All Projects → m1 → go-localize

m1 / go-localize

Licence: MIT license
i18n (Internationalization and localization) engine written in Go, used for translating locale strings.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to go-localize

android-studio-plugin
Integrate your Android project with Crowdin
Stars: ✭ 52 (+15.56%)
Mutual labels:  i18n, internationalization, localization
msgtools
Tools for Developing Diagnostic Messages
Stars: ✭ 18 (-60%)
Mutual labels:  i18n, internationalization, localization
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+5942.22%)
Mutual labels:  i18n, internationalization, localization
awesome-i18n
🌍 A curated list of i18n resources for all kind of languages and frameworks
Stars: ✭ 205 (+355.56%)
Mutual labels:  i18n, internationalization, localization
Flutter translate
Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
Stars: ✭ 245 (+444.44%)
Mutual labels:  i18n, internationalization, localization
React Translated
A dead simple way to add complex translations (i18n) in a React (DOM/Native) project 🌎🌍🌏
Stars: ✭ 176 (+291.11%)
Mutual labels:  i18n, internationalization, localization
ad localize
ADLocalize is a simple way to manage your localization files. Supported wording sources : CSVs and Google Sheets. Localization file generation available for iOS, Android, JSON (i18next), YAML and Java properties
Stars: ✭ 22 (-51.11%)
Mutual labels:  i18n, internationalization, localization
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (+177.78%)
Mutual labels:  i18n, internationalization, localization
rails
Rails translation made _('simple').
Stars: ✭ 65 (+44.44%)
Mutual labels:  i18n, internationalization, localization
L10ns
Internationalization workflow and formatting
Stars: ✭ 234 (+420%)
Mutual labels:  i18n, internationalization, localization
Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+288.89%)
Mutual labels:  i18n, internationalization, localization
I18N
I18N Library for .NET, and Delphi
Stars: ✭ 48 (+6.67%)
Mutual labels:  i18n, internationalization, localization
Formatjs
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Stars: ✭ 12,869 (+28497.78%)
Mutual labels:  i18n, internationalization, localization
typesafe-i18n
A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.
Stars: ✭ 1,227 (+2626.67%)
Mutual labels:  i18n, internationalization, localization
Jquery.ime
jQuery based input methods library
Stars: ✭ 145 (+222.22%)
Mutual labels:  i18n, internationalization, localization
Serge
Continuous localization platform
Stars: ✭ 212 (+371.11%)
Mutual labels:  i18n, internationalization, localization
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (+142.22%)
Mutual labels:  i18n, internationalization, localization
Phabricator zh hans
Phabricator zh-Hans Translation & Tools.
Stars: ✭ 113 (+151.11%)
Mutual labels:  i18n, internationalization, localization
Lang.js
🎭 Laravel Translator class in JavaScript!
Stars: ✭ 232 (+415.56%)
Mutual labels:  i18n, internationalization, localization
React Native Globalize
Internationalization (i18n) for React Native
Stars: ✭ 246 (+446.67%)
Mutual labels:  i18n, internationalization, localization

go-localize

GoDoc Build Status Go Report Card Release codecov

Simple and easy to use i18n (Internationalization and localization) engine written in Go, used for translating locale strings. Use with go generate or on the CLI. Currently supports JSON, YAML, TOML and CSV translation files

Why another i18n library?

This package aims to be as simple and easy to use as possible. It also takes inspiration from popular localization libraries/packages in other languages - so makes it easier to reason about coming from other languages and frameworks.

Usage

Go generate

The suggested way to use go-localize is to use go generate. For example, take the following directory structure:

goapp
└── localizations_src
    ├── en
    │   └── messages.yaml
    └── es
        ├── customer
        │   └── messages.json
        └── messages.json

Example of JSON translation file:

{
  "hello": "Hola",
  "how_are_you": "¿Cómo estás?",
  "whats_your_name": "¿Cuál es tu nombre?",
  "hello_my_name_is": "Hola, mi nombre es {{.name}}"
}

Example of YAML translation file:

hello: hello
how_are_you: How are you?
whats_your_name: "What's your name?"
hello_my_name_is: Hello my name is {{.name}}
hello_firstname_lastname: Hello {{.firstname}} {{.lastname}}

Example of CSV translation file:

hello, hello
how_are_you, How are you?

Example of TOML translation file:

hello = "hello"
how_are_you = "How are you?"

To then generate the localization package, add the following to your main.go or another one of your .go files:

//go:generate go-localize -input localizations_src -output localizations

Now you'll be able to use the localization like so:

l := localizations.New("en", "es")

println(l.Get("messages.how_are_you")) // How are you?

println(l.GetWithLocale("es", "messages.hello_my_name_is", &localizations.Replacements{"name":"steve"})) // "Hola, mi nombre es steve"

With en being the locale and es being the fallback. The localization keys are worked out using folder structure, eg:

en/customer/messages.json with the contents being:

{
  "hello": "hello customer!"
}

You'll be able to access this using the key: customer.messages.hello.

Suggestions

It is suggested to instead of using hardcoded locale keys i.e. en to use the language keys included in key, i.e: language.BritishEnglish.String() which is en-GB

Replacements

Take this replacement string for example:

hello_firstname_lastname: Hello {{.firstname}} {{.lastname}}

To then replace firstname and the lastname variable, you can use something like this:

l := localizations.New("en", "es")
println(l.Get("hello_firstname_lastname", &localizations.Replacements{"firstname": "steve", "lastname": "steve"}))

You can also append numerous replacements if you have them like so:

println(l.Get("hello_firstname_lastname", &localizations.Replacements{"firstname": "steve"}, &localizations.Replacements{"lastname": "steve"}))

Locale defining and localization fallbacks

You can define the locale and fallbacks using:

l := localizations.New("en", "es")

Where en is the locale and es is the fallback. If no translation key-value is found then the key will be returned. For example

println(l.Get("key_doesnt_exist")) //"key_doesnt_exist" will be printed

Translation file support

We currently support JSON and YAML translation files. Please suggest missing file type using issues or pull requests.

CLI

Instead of using go generate you can just generate the localizations manually using go-localize:

Usage of go-localize:
  -input string
        input localizations folder
  -output string
        where to output the generated package
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].