L10n-swift is a simple framework that improves localization in swift app, providing cleaner syntax and in-app language switching.
- 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.
- Use
.l10n()
to localized any string, date, int and double. - Use more than one languages at the same time.
- About 25 times faster than a native solution.
pod try L10n-swift
- iOS 9.0+ | macOS 10.10+ | tvOS 9.0+ | watchOS 2.0+
- Swift 3.0+
- 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.
Core | Extension | IBInspectable | |
---|---|---|---|
L10n-swift | ✔️ | ✔️ | ✔️ |
L10n-swift/Core | ✔️ | ||
L10n-swift/Extension | ✔️ | ✔️ | |
L10n-swift/IBInspectable | ✔️ | ✔️ |
pod 'L10n-swift', '~> 5.4'
github "Decybel07/L10n-swift", ~> 5.4
.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
Add .l10()
following any String
object you want localized:
"HelloWorld".l10n()
Add .l10()
following any Int
, Double
or NSNumber
object 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
}
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
}
Add .l10(arg: CVarArg)
following any String
object you want translated with plurals:
"numberOfApples".l10n(arg: 2)
More about plurals, you can read on wiki
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
)
L10n.shared.language = "en"
L10n.shared.language = "en-GB"
At runtime, you can switch the language at any time by setting the language property
L10n.shared.language
L10n.shared.locale
L10n.supportedLanguages
A list of all the languages contained in the main bundle.
L10n.preferredLanguage
A preferred language contained in the main bundle
More about .plist format you can read on wiki
More about .stringsdict format you can read on wiki
More about .json format you can read on wiki
More about .strings format you can read on wiki.
📙 FAQ
Adrian Bobrowski (Decybel07), [email protected]
L10n-swift is available under the MIT license. See the LICENSE file for more info.