Localized
Localized provides a macro for localizing cross-platform Swift code.
Use YML syntax for defining available phrases:
hello(name):
en: Hello, (name)!
de: Hallo, (name)!
fr: Salut, (name)!
house:
en: House
de: Haus
fr: Maison
Then, access the localized strings safely in your code:
// Use the system language
print(Loc.hello(name: "Peter"))
print(Loc.house)
// Access the translation for a specific language
print(Localized.hello(name: "Peter").en)
print(Localized.house.fr)
Table of Contents
Installation
- Open your Swift package in GNOME Builder, Xcode, or any other IDE.
- Open the
Package.swiftfile. - Into the
Packageinitializer, underdependencies, paste:
.package(url: "https://github.com/AparokshaUI/Localized", from: "0.1.0")
Usage
Definition
Define the available phrases using YML.
#localized(default: "en", yml: """
export:
en: Export Document
de: Exportiere das Dokument
send(message, name):
en: Send (message) to (name).
de: Sende (message) to (name).
""")
As you can see, you can add parameters using brackets after the key.
Usage
In most cases, you want to get the translated string in the system language. This can be accomplished using the following syntax.
let export = Loc.export
let send = Loc.send(message: "Hello", name: "Peter")
You can access a specific language as well.
let export = Localized.export.en
let send = Localized.send(message: "Hallo", name: "Peter").de
If you want to get the translation for a specific language code, use the following syntax. This function will return the translation for the default language if there's no translation for the prefix of that code available.
let export = Localized.export.string(for: "de-CH")
Thanks
Dependencies
- Swift Syntax licensed under the Apache 2.0 license
- Yams licensed under the MIT license
- Swift Macro Toolkit licensed under the Apache 2.0 license
Other Thanks
- The contributors
- SwiftLint for checking whether code style conventions are violated
- The programming language Swift
- SourceDocs used for generating the docs
Description
Easy-to-use, safe and cross-platform library for localizing Swift code
https://localized.aparoksha.dev/documentation/localized/
Initial release
Latest
Languages
Cython
89.2%
Swift
10.8%