A Vapor provider for Lingo - a pure Swift localization library ready to be used in Server Side Swift projects.
Add LingoProvider as a dependancy in your Package.swift
file:
dependencies: [
...,
.Package(url: "https://github.com/vapor-community/lingo-provider.git", majorVersion: 1)]
]
After you have initialized the Config
object, simply add the provider:
import LingoProvider
...
try config.addProvider(LingoProvider.Provider.self)
Lingo can be configured in a lingo.json
file located inside your Vapor Config
dir:
{
"defaultLocale": "en",
"localizationsDir": "Localizations"
}
The
localizationsDir
can be omitted in this case, as the Localizations is also the default path. Note that this folder should exist under the drop.workDir.
LingoProvider adds an extension on Droplet for easier access to Lingo, so it can be used simply as:
let localizedTitle = droplet.lingo.localize("welcome.title", locale: "en")
Use the following syntax for defining localizations in a JSON file:
{
"title": "Hello Swift!",
"greeting.message": "Hi %{full-name}!",
"unread.messages": {
"one": "You have one unread message.",
"other": "You have %{count} unread messages."
}
}
- Lingo - learn more about the localization file format, pluralization support, and see how you can get the most out of the Lingo.