skelpo / Lingo-Provider

Vapor provider for Lingo - the Swift localization library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lingo Provider

Language 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-provider.git", majorVersion: 1)]
]

Add the Provider

After you have initialized the Config object, simply add the provider:

import LingoProvider
...
try config.addProvider(LingoProvider.Provider.self)

Config

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.

Use

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."
	}
}

Learn more

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

About

Vapor provider for Lingo - the Swift localization library

License:MIT License


Languages

Language:Swift 100.0%