Swiftpack.co - Package - vapor-community/Lingo-Vapor

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.

Github

link
Stars: 22
Help us keep the lights on

Releases

3.0.0 - May 11, 2018

1.0.1 - Oct 16, 2017

This release includes support for Swift 4 while preserving backwards compatibility with Swift 3.

1.0.0 - Aug 28, 2017