Decybel07/L10n-swift
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
Overview
<p align="center"> <table><tr> <td><img src="https://raw.githubusercontent.com/Decybel07/L10n-swift/master/Images/language720.gif" alt="Change language"/></td> <td><img src="https://raw.githubusercontent.com/Decybel07/L10n-swift/master/Images/translator720.gif" alt="Simple translator"/></td> <td><img src="https://raw.githubusercontent.com/Decybel07/L10n-swift/master/Images/plurals720.gif" alt="Plurals"/></td> </tr></table> </p>
π Features
- [x] Change the language of your apps "on the fly".
- [x] IBInspectable for Xcode Interface Builder (Cocoa - coming soon).
- [x] Support for user-defined
Localizablefile names. - [x] Support for formats:
.plist,.json,.stringsdict,.strings. - [x] Support for grouping localization keys.
- [x] Support for plural forms in any language with multiple arguments.
- [x] Support for pseudo-languages:
NonLocalized,DoubleLength,Accented,Bounded,ForcedRightToLeft. - [x] Use
.l10n()to localize any string, date and numbers. - [x] Use more than one language at the same time.
- [x] 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 4.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
``ruby pod 'L10n-swift', '~> 5.10' ``
Carthage
github "Decybel07/L10n-swift", ~> 5.10Swift Package Manager
.Package(url: "https://github.com/Decybel07/L10n-swift.git", majorVersion: 5)π [Usage](http://cocoadocs.org/docsets/L10n-swift/)
Import L10n_swift at the top of each Swift file that will use framework. ``swift import L10n_swift ``
Get localized text
Add .l10() following any String object you want localized: ``swift "hello.world".l10n() ``
Get localized number
Add .l10() following number you want localized. Using the number format for the current language: ```swift 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: ```swift Date().l10n()
Date().l10n { formatter in formatter.dateStyle = .medium } ```
Get plural
Add .l10nPlural(CVarArg...) following any String object you want translated with plurals: ``swift "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. ``swift NotificationCenter.default.addObserver( self, selector: #selector(self.yourFunction), name: .L10nLanguageChanged, object: nil ) ``
Set language
``swift 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
``swift L10n.shared.language ``
Get locale for current language
``swift L10n.shared.locale ``
Get list of supported languages
``swift L10n.supportedLanguages `` A list of all the languages contained in the main bundle.
Get preferred language
``swift L10n.preferredLanguage `` A preferred language contained in the main bundle.
Supported formats
.plist, .stringsdict
<img src="https://raw.githubusercontent.com/Decybel07/L10n-swift/master/Images/sample_plist_file.png" alt="Sample .plist and .stringsdict file" width="597" style="max-width:100%;"/>
More about .plist format you can read on wiki.
More about .stringsdict format you can read on wiki.
#### .json <img src="https://raw.githubusercontent.com/Decybel07/L10n-swift/master/Images/sample_json_file.png" alt="Sample .json file" width="554" style="max-width:100%;"/>
More about .json format you can read on wiki.
#### .strings <img src="https://raw.githubusercontent.com/Decybel07/L10n-swift/master/Images/sample_strings_file.png" alt="Sample .strings file" width="544" style="max-width:100%;"/>
More about .strings format you can read on wiki.
π License
L10n-swift is available under the MIT license. See the LICENSE file for more info.
Package Metadata
Repository: Decybel07/L10n-swift
Stars: 324
Forks: 31
Open issues: 1
Default branch: master
Primary language: swift
License: MIT
Topics: carthage, change-language, cocoapods, ios, l10n, language, language-detection, localization, localized, macos, plist, plural-form, pluralization, plurals, strings, stringsdict, swift-framework, swift-package-manager, tvos, watchos
README: README.md