Localization of the application with ability to change language "on the fly" and support for plural form in any language.

Overview

L10n-swift

Build Status CocoaPods Version Language Swift4 CocoaPods Platform CocoaPods License Pod method Compatible Mentioned in Awesome-swift

L10n-swift is a simple framework that improves localization in swift app, providing cleaner syntax and in-app language switching.

Overview

Change language Simple translator Plurals

🌟 Features

  • Change the language of your apps "on the fly".
  • IBInspectable for Xcode Interface Builder (Cocoa - coming soon).
  • Support for user-defined Localizable file names.
  • Support for formats: *.plist, *.json, *.stringsdict, *.strings.
  • Support for grouping localization keys.
  • Support for plural forms in any language with multiple arguments.
  • Support for pseudo-languages: NonLocalized, DoubleLength, Accented, Bounded, ForcedRightToLeft.
  • Use .l10n() to localize any string, date and numbers.
  • Use more than one language at the same time.
  • About 25 times faster than a native solution.

πŸ’» Demo

pod try L10n-swift

⚠️ Requirements

  • iOS 9.0+ | macOS 10.10+ | tvOS 9.0+ | watchOS 2.0+
  • Swift 3.0+

πŸ‘₯ Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

πŸ“— Installation

Core Extension IBInspectable
L10n-swift βœ”οΈ βœ”οΈ βœ”οΈ
L10n-swift/Core βœ”οΈ
L10n-swift/Extension βœ”οΈ βœ”οΈ
L10n-swift/IBInspectable βœ”οΈ βœ”οΈ

CocoaPods

pod 'L10n-swift', '~> 5.9'

Carthage

github "Decybel07/L10n-swift", ~> 5.9

Swift Package Manager

.Package(url: "https://github.com/Decybel07/L10n-swift.git", majorVersion: 5)

πŸ“˜ Usage

Import L10n_swift at the top of each Swift file that will use framework.

import L10n_swift

Get localized text

Add .l10() following any String object you want localized:

"hello.world".l10n()

Get localized number

Add .l10() following number you want localized. Using the number format for the current language:

12.l10n()
24.l10n(minIntegerDigits: 4)
1.61803.l10n()
2.71828.l10n(fractionDigits: 2)

3.14.l10n { formatter in
    formatter.numberStyle = .currency
}

Get localized date

Add .l10() following any Date object you want localized using the date format for the current language:

Date().l10n()

Date().l10n { formatter in
    formatter.dateStyle = .medium
}

Get plural

Add .l10nPlural(CVarArg...) following any String object you want translated with plurals:

"numberOfApples".l10nPlural(2)

More about plurals, you can read on wiki

Observe language changed

Add observer for notification L10nLanguageChanged. This notification is called when language has been changed.

NotificationCenter.default.addObserver(
    self, selector: #selector(self.yourFunction), name: .L10nLanguageChanged, object: nil
)

Set language

L10n.shared.language = "en"
L10n.shared.language = "en-GB"

At runtime, you can switch the language at any time by setting the language property.

Get current language

L10n.shared.language

Get locale for current language

L10n.shared.locale

Get list of supported languages

L10n.supportedLanguages

A list of all the languages contained in the main bundle.

Get preferred language

L10n.preferredLanguage

A preferred language contained in the main bundle.

Supported formats

.plist, .stringsdict

Sample .plist and .stringsdict file

More about .plist format you can read on wiki.

More about .stringsdict format you can read on wiki.

.json

Sample .json file

More about .json format you can read on wiki.

.strings

Sample .strings file

More about .strings format you can read on wiki.

πŸ“™ FAQ

πŸ€“ Author

Adrian Bobrowski (Decybel07), [email protected]

πŸ”‘ License

L10n-swift is available under the MIT license. See the LICENSE file for more info.

Comments
  • Not support Localization in custom Framework

    Not support Localization in custom Framework

    It works on Japanese and Italian perfectly (without needs to restart the app). But it did not works on Arabic and French even after restarting the app it not works. Kindly help me.

    question 
    opened by ghost 15
  • Plural localization not working

    Plural localization not working

    Just installed this pod and tried plural localization via "eventCount".l10n(arg: count) Added this lines to Localizable.strings

    "eventCount.one" = "%d event";
    "eventCount.many" = "%d events";
    "eventCount.other" = "%d events";
    

    Traced code, self.bundle in this function is nil, so no resource is loaded

        private func resource(named resourceName: String?) -> ResourceContainer {
            let resourceName = (resourceName ?? "").isEmpty ? "Localizable" : resourceName!
    
            return self.resources[resourceName] ?? {
                let resource = ResourceContainer(bundle: self.bundle, name: resourceName)
                self.resources[resourceName] = resource
                return resource
            }()
        }
    

    Version 5.1.0

    fixed 
    opened by entropious 14
  • fails to install with swift pm

    fails to install with swift pm

    Short description of the issue.

    Swift PM fails to resolve the dependency to L10n-swift

    What did you expect to happen?

    It should install just like it does with other libraries. (example: Alamofire, PinLayout)

    What happened instead?

    The dependency does not get resolved and swift package aborts with an error.

    How to reproduces this problem?

    Package.swift

    // swift-tools-version:5.0
    import PackageDescription
    
    let package = Package(
        name: "Test",
        products: [],
        dependencies: [
            .package(url: "https://github.com/Decybel07/L10n-swift.git", .upToNextMajor(from: "5.5.1")),
        ],
        targets: [
            .target(
                name: "Test",
                dependencies: [
                    "L10n-swift",
                ],
                path: "Test"
            ),
        ]
    )
    
    
    $ swift package resolve
    Updating https://github.com/Decybel07/L10n-swift.git
    error: dependency graph is unresolvable; found these conflicting requirements:
    
    Dependencies: 
        https://github.com/Decybel07/L10n-swift.git @ 5.5.1..<6.0.0
    

    Environment.

    L10n-swift version: 5.5.1

    Xcode version: Xcode 10.3, Build version 10G8

    Swift version: Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)

    Platform(s):

    • [ ] iOS
    • [ ] watchOS
    • [ ] tvOS
    • [x] macOS

    Installation method:

    • [ ] CocoaPods
    • [ ] Carthage
    • [x] Swift Package Manager
    • [ ] Other (which ones)
    bug help wanted 
    opened by tcurdt 9
  • Plurals does not work

    Plurals does not work

    Short description of the issue.

    Hi, I am using iOS 15. Tried both SPM and Pods. Firstly created "minutes_time.one" and "minutes_time.other" in Localizable.string in en.lproj. When I am trying to call "minutes_time".l10nPlural(1) there is an error No exact matches in call to instance method 'l10nPlural'. Then I've tried to do "minutes_time".l10nPlural(args: [1]), but then I've got "minutes_time.other" version instead of "minutes_time.one"

    Environment.

    DebugDescription

    L10n {
    	Language: en
    	Preferred language: en
    	Supported languages: ["en"]
    	Bundles: [
    		"/var/containers/Bundle/Application/6353C86E-3F14-4D72-95DE-250F4628A4D1/.../en.lproj"
    	]
    }
    

    L10n-swift version: 5.10

    Xcode version: 13.2.1 xcodebuild -version

    Swift version: 5.5.2 swift -version

    Platform(s):

    • [x] iOS
    • [ ] watchOS
    • [ ] tvOS
    • [ ] macOS

    File format(s):

    • [x] strings
    • [ ] stringsdict
    • [ ] plist
    • [ ] json

    Installation method:

    • [x] CocoaPods
    • [ ] Carthage
    • [x] Swift Package Manager
    • [ ] Other (which ones)
    bug help wanted fixed 
    opened by Arideno 8
  • Conformance with CVarArg

    Conformance with CVarArg

    Hi,

    First of all, thanks for this library. Of all the projects I checked this one seems to handle plurals and localizations the best. I guess it takes handling plurals in Polish to understand this pain :P

    I have some problems with String extension function. I try to call it as it is in examples:

    "view_edit_profile_photos_content_text".l10n(args: 10)

    For some reason XCode gives me following compile time exception:

    Cannot invoke 'l10n' with an argument list of '(args: Int)'

    question fixed 
    opened by Sroka 3
  • String.L10n() is not working

    String.L10n() is not working

    I added a Localizable.strings with 3 languages into project and included it in build phase. This is english version of it:

    /*
     strings.strings
     NavigationDrawerController
     
     Created by A.V.Ebrahimi on 4/21/17.
     Copyright Β© 2017 CosmicMind. All rights reserved.
     */
    "AppName" = "Mallowin";
    
    

    But now this is not working : toolbar.title="AppName".l10n()

    question 
    opened by a-v-ebrahimi 3
  • Language doesn't change in static variables.

    Language doesn't change in static variables.

    I have some static variables in a struct which are used to display error messages to users

    struct AlertBody {
    
        static let SOMETHING_WRONG = "There was an error service in your request. Please try again from while".l10n()
        static let NO_NETWORK_ERROR = "No internet Connection found. Check your connection or try again.".l10n()
    }
    

    When I change the language, these static variables still give the message in previous language. In order to get the messages in correct language I have to close and reopen the app. But is there any other way to reload these static variables at the run time?

    question 
    opened by uditha2233 2
  • Language change on macOS doesn't update system menubar items

    Language change on macOS doesn't update system menubar items

    Short description of the issue.

    System (default) menubar items don't update after a language change

    What did you expect to happen?

    Menubar adapts to new language selected

    What happened instead?

    Menubar didn't adapt to new language

    How to reproduces this problem?

    1. Start app
    2. Take note of the menubar
    3. Change language
    4. See no changes

    Environment

    UI framework: SwiftUI System: macOS Ventura 13.0

    DebugDescription

    L10n {
    	Language: uk
    	Preferred language: en
    	Supported languages: ["en", "uk", "ru"]
    	Bundles: [
    		"/Users/egoryakovenko/Library/Developer/Xcode/DerivedData/Moc-cmqpfvhdudhbgibqasempmgnurue/Build/Products/Debug/Moc.app/Contents/Resources/uk.lproj",
    		"/Users/egoryakovenko/Library/Developer/Xcode/DerivedData/Moc-cmqpfvhdudhbgibqasempmgnurue/Build/Products/Debug/Moc.app/Contents/Resources/en.lproj"
    	]
    }
    

    (bundles change time to time, sometimes i have uk, sometimes i don't)

    L10n-swift version: 5.10.2

    Xcode version: Xcode 14.1 Build version 14B47 xcodebuild -version

    Swift version: swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.2 clang-1400.0.29.51) Target: x86_64-apple-macosx13.0 swift -version

    Platform(s):

    • [ ] iOS
    • [ ] watchOS
    • [ ] tvOS
    • [x] macOS

    File format(s):

    • [x] strings
    • [ ] stringsdict
    • [ ] plist
    • [ ] json

    Installation method:

    • [ ] CocoaPods
    • [ ] Carthage
    • [x] Swift Package Manager
    • [ ] Other (which ones)
    opened by ggoraa 1
  • 'L10n' is not a member type of class 'FrameworkMainClass.FrameworkMainClass'

    'L10n' is not a member type of class 'FrameworkMainClass.FrameworkMainClass'

    I'm working on custom framework. I have created an xcframework file , when I import this file into demo project then I got this error. 'L10n' is not a member type of class 'FrameworkMainClass.FrameworkMainClass'

    opened by zaidahmedpf 1
  • IBInspectable with custom bundle

    IBInspectable with custom bundle

    I use L10n-swift library for the project localization.
    My project receives localisation files from the backend as json and stores it to the separate bundle in project's Documents folder.
    And I have to load localizations from Documents to L10n.

    I know that L10n can be created as a new instance and pass my bundle as parameter into init method, but IBInspectable extension won't work with the custom bundle, bcouz IBInspectable use shared singleton with default L10n initialization.
    How can I load my Bundle to L10n.shared and use IBInspectable extension as Main bundle?

    enhancement help wanted question 
    opened by vkhadyka 1
  • Line break are escaped in translated strings

    Line break are escaped in translated strings

    With the string Phone\nNumber in the .stringsdict, I'm getting the following string "Phone\\nNumber" instead of "Phone\nNumber".

    Environment.

    DebugDescription

    "L10n {\n\tLanguage: en\n\tPreferred language: en\n\tSupported languages: [\"en\"]\n\tBundles: [\n\t\t\"/var/containers/Bundle/Application/1E0B4F9F-2F20-4503-8108-2C06E1FEDBE7/Cruise.app/en.lproj\",\n\t\t\"/var/containers/Bundle/Application/1E0B4F9F-2F20-4503-8108-2C06E1FEDBE7/Cruise.app/Base.lproj\"\n\t]\n}"
    

    L10n-swift version: 5.7.3

    Xcode version: Xcode 12.4 Build version 12D4e

    Swift version: Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28) Target: x86_64-apple-darwin19.6.0

    Platform(s):

    • [x] iOS
    • [ ] watchOS
    • [ ] tvOS
    • [ ] macOS

    File format(s):

    • [ ] strings
    • [x] stringsdict
    • [ ] plist
    • [ ] json

    Installation method:

    • [x] CocoaPods
    • [ ] Carthage
    • [ ] Swift Package Manager
    • [ ] Other (which ones)
    wontfix 
    opened by Morniak 1
Releases(5.10.2)
Owner
Adrian Bobrowski
Adrian Bobrowski
Swift friendly localization and i18n with in-app language switching

Localize-Swift Localize-Swift is a simple framework that improves i18n and localization in Swift iOS apps - providing cleaner syntax and in-app langua

Roy Marmelstein 2.9k Dec 29, 2022
transai is a localization tool on Android and iOS.

transai transai is a command line tool to help you do Android and iOS translation management. You can extract string files to csv format, or generate

Jintin 56 Nov 12, 2022
Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.

Installation β€’ Configuration β€’ Usage β€’ Build Script β€’ Donation β€’ Migration Guides β€’ Issues β€’ Contributing β€’ License BartyCrouch BartyCrouch incrementa

Flinesoft 1.3k Jan 1, 2023
iOS localization swift code generation project

code-gen-library - localization-swift module code-gen-library - localization-swift module with Python bash script execute to localization swift files(

umut boz 0 Oct 26, 2021
A CLI tool for localization resource management on Xcode. Built with Google Translator.

Supported by Jetbrains Open Source License Program Automatically translate and synchronize '.strings' files from the defined base language The basic c

gitmerge 164 May 4, 2022
Localizations is an OS X app that manages your Xcode project localization files (.strings)

Localizations 0.2 Localizations is an OS X app that manages your Xcode project localization files (.strings). It focuses on keeping .strings files in

Arnaud Thiercelin 129 Jul 19, 2022
a custom language construction kit

Swifties a custom language construction kit intro Swifties aims to provide a flexible toolkit for creating custom languages in Swift. demo A custom Li

Andreas Nilsson 11 Aug 25, 2021
iOS implementation of the Catrobat language

Catty Catty, also known as Pocket Code for iOS, is an on-device visual programming system for iPhones. Catrobat is a visual programming language and s

null 74 Dec 25, 2022
Demo project of Swift language crash using Release build on iOS 14

Demo project of Swift language crash using Release build on iOS 14 Repro steps O

Daohan Chong 0 Mar 24, 2022
Crowdin iOS SDK delivers all new translations from Crowdin project to the application immediately

Crowdin iOS SDK Crowdin iOS SDK delivers all new translations from Crowdin project to the application immediately. So there is no need to update this

Crowdin 98 Dec 14, 2022
Setting up application specific localized string within xib file.

LocalizedView ##What is this? LocalizedView is a helper class for setting up application specific localized string within Xib file. Here is a video de

darkcl 8 Oct 2, 2017
An application to convert strings to diffirent formats

Localized An application to convert strings to diffirent formats This app will help developers to convert strings from application in one platform to

null 16 Feb 12, 2021
Localize is a framework writed in swift to localize your projects easier improves i18n, including storyboards and strings.

Localize Localize is a framework written in swift to help you localize and pluralize your projects. It supports both storyboards and strings. Features

Andres Silva 279 Dec 24, 2022
NoOptionalInterpolation gets rid of "Optional(...)" and "nil" in Swift's string interpolation

NoOptionalInterpolation gets rid of "Optional(...)" and "nil" in Swift's string interpolation

Thanh Pham 48 Jun 5, 2022
A tool for finding missing and unused NSLocalizedStrings

nslocalizer This is a command line tool that is used for discovering missing and unused localization strings in Xcode projects. Contributing and Code

Samantha Demi 155 Sep 17, 2022
Semi-automated Text Translator for Websites and Apps

macOS/Ubuntu/Windows: attranslate is a semi-automated tool for "synchronizing" translation-files. attranslate is optimized for fast and smooth rollout

Felix Kirchengast 272 Dec 21, 2022
Will Powell 1.2k Dec 29, 2022
πŸ”₯ πŸ”₯ πŸ”₯Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

?? ?? ??Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

null 60 Dec 12, 2022
Appfiguratesdk - Appfigurate provides the ability to change configuration properties in iOS and watchOS, apps and app extensions, securely, at runtime.

Appfigurateβ„’ Appfigurate provides the ability to change configuration properties in iOS and watchOS, apps and app extensions, securely, at runtime. Do

Electric Bolt 21 Dec 14, 2022
SwiftUI library to display a clock. You can move the arms to change the time, change the style of the clock and customise some configurations.

SwiftClockUI Clock UI for SwiftUI This library has been tested βœ… ?? macOS Catalina 10.15.3 βœ… ?? macOS Big Sur 11.6 βœ… ?? iOS 13 βœ… ?? iOS 14 βœ… ?? iOS 15

Renaud Jenny 239 Dec 29, 2022