Swiftpack.co - Package -

Lingo Provider

Language GitHub license

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


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.


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.


Help us keep the lights on

Used By

Total: 0