Vapor provider for Lingo - the Swift localization library
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Sources Updated README.md for Vapor 3 May 11, 2018
Tests Updated README.md for Vapor 3 May 11, 2018
.gitignore
LICENSE Initial commit Aug 25, 2017
Package.swift Updated Vapor version to official release May 7, 2018
README.md Update README.md Jun 10, 2018

README.md

Lingo Provider

Language GitHub license

A Vapor provider for Lingo - a pure Swift localization library ready to be used in Server Side Swift projects.

Setup

Add a dependancy

Add LingoProvider as a dependancy in your Package.swift file:

dependencies: [
	...,
	.package(url: "https://github.com/vapor-community/lingo-vapor.git", from: "3.0.0")]
]

Add the Provider

In the configure.swift simply initialize the LingoVapor with a default locale:

import LingoVapor
...
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
	...
	let lingoProvider = LingoProvider(defaultLocale: "en", localizationsDir: "Localizations")
	try services.register(lingoProvider)
}

The localizationsDir can be omitted, as the Localizations is also the default path. Note that this folder should exist under the workDir.

Use

After you have registered the provider, you can use any Container to create Lingo:

let lingo = try someContainer.make(Lingo.self)
...
let localizedTitle = 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."
	}
}

Learn more

  • Lingo - learn more about the localization file format, pluralization support, and see how you can get the most out of the Lingo.