All Projects → nicksnyder → Go I18n

nicksnyder / Go I18n

Licence: mit
Translate your Go program into multiple languages.

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Go I18n

Traduora
Ever® Traduora - Open-Source Translation Management Platform
Stars: ✭ 1,580 (-13.85%)
Mutual labels:  translation, i18n
Transloco
🚀 😍 The internationalization (i18n) library for Angular
Stars: ✭ 1,185 (-35.39%)
Mutual labels:  translation, i18n
React Intl Hooks
React hooks for internationalization without the hassle ⚛️🌍
Stars: ✭ 64 (-96.51%)
Mutual labels:  translation, i18n
Phabricator zh hans
Phabricator zh-Hans Translation & Tools.
Stars: ✭ 113 (-93.84%)
Mutual labels:  translation, i18n
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (-93.18%)
Mutual labels:  translation, i18n
Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (-47.27%)
Mutual labels:  translation, i18n
Elm I18n
Localization for Elm apps as a pre-build phase with import and export between elm code and CSV/PO
Stars: ✭ 68 (-96.29%)
Mutual labels:  translation, i18n
Django Rosetta
Rosetta is a Django application that eases the translation process of your Django projects
Stars: ✭ 806 (-56.05%)
Mutual labels:  translation, i18n
Eslint Plugin I18n Json
Fully extendable eslint plugin for JSON i18n translation files.
Stars: ✭ 101 (-94.49%)
Mutual labels:  translation, i18n
Gitlab I18n Patch
Unofficial Japanese translation for GitLab Community Edition.
Stars: ✭ 98 (-94.66%)
Mutual labels:  translation, i18n
Webfactoryicutranslationbundle
Enables ICU message formatting for translations in Symfony applications.
Stars: ✭ 27 (-98.53%)
Mutual labels:  translation, i18n
I18n Ally
🌍 All in one i18n extension for VS Code
Stars: ✭ 1,931 (+5.29%)
Mutual labels:  translation, i18n
Satakieli
Satakieli is a i18n library that provides identical API for ClojureScript and Clojure programmers. Localized messages can be written using ICU MessageFormat syntax.
Stars: ✭ 24 (-98.69%)
Mutual labels:  translation, i18n
Atom I18n
:atom: One Atom i18n Package for Any Locale 🌏 🌎 🌍
Stars: ✭ 56 (-96.95%)
Mutual labels:  translation, i18n
Translatedjs
Internationalization and localization for JavaScript and Node.js
Stars: ✭ 17 (-99.07%)
Mutual labels:  translation, i18n
Gettext Go
🆎 GNU gettext for Go (Imported By Kubernetes)
Stars: ✭ 66 (-96.4%)
Mutual labels:  translation, i18n
React I18next
Internationalization for react done right. Using the i18next i18n ecosystem.
Stars: ✭ 6,942 (+278.52%)
Mutual labels:  translation, i18n
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (-57.69%)
Mutual labels:  translation, i18n
Pootle
Online translation tool
Stars: ✭ 1,346 (-26.61%)
Mutual labels:  translation, i18n
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (-94.06%)
Mutual labels:  translation, i18n

go-i18n Build status Report card codecov Sourcegraph

go-i18n is a Go package and a command that helps you translate Go programs into multiple languages.

Package i18n

GoDoc

The i18n package provides support for looking up messages according to a set of locale preferences.

import "github.com/nicksnyder/go-i18n/v2/i18n"

Create a Bundle to use for the lifetime of your application.

bundle := i18n.NewBundle(language.English)

Load translations into your bundle during initialization.

bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
bundle.LoadMessageFile("es.toml")

Create a Localizer to use for a set of language preferences.

func(w http.ResponseWriter, r *http.Request) {
    lang := r.FormValue("lang")
    accept := r.Header.Get("Accept-Language")
    localizer := i18n.NewLocalizer(bundle, lang, accept)
}

Use the Localizer to lookup messages.

localizer.Localize(&i18n.LocalizeConfig{
    DefaultMessage: &i18n.Message{
        ID: "PersonCats",
        One: "{{.Name}} has {{.Count}} cat.",
        Other: "{{.Name}} has {{.Count}} cats.",
    },
    TemplateData: map[string]interface{}{
        "Name": "Nick",
        "Count": 2,
    },
    PluralCount: 2,
}) // Nick has 2 cats.

Command goi18n

GoDoc

The goi18n command manages message files used by the i18n package.

go get -u github.com/nicksnyder/go-i18n/v2/goi18n
goi18n -help

Extracting messages

Use goi18n extract to extract all i18n.Message struct literals in Go source files to a message file for translation.

# active.en.toml
[PersonCats]
description = "The number of cats a person has"
one = "{{.Name}} has {{.Count}} cat."
other = "{{.Name}} has {{.Count}} cats."

Translating a new language

  1. Create an empty message file for the language that you want to add (e.g. translate.es.toml).

  2. Run goi18n merge active.en.toml translate.es.toml to populate translate.es.toml with the messages to be translated.

    # translate.es.toml
    [HelloPerson]
    hash = "sha1-5b49bfdad81fedaeefb224b0ffc2acc58b09cff5"
    other = "Hello {{.Name}}"
  3. After translate.es.toml has been translated, rename it to active.es.toml.

    # active.es.toml
    [HelloPerson]
    hash = "sha1-5b49bfdad81fedaeefb224b0ffc2acc58b09cff5"
    other = "Hola {{.Name}}"
  4. Load active.es.toml into your bundle.

    bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
    bundle.LoadMessageFile("active.es.toml")

Translating new messages

If you have added new messages to your program:

  1. Run goi18n extract to update active.en.toml with the new messages.
  2. Run goi18n merge active.*.toml to generate updated translate.*.toml files.
  3. Translate all the messages in the translate.*.toml files.
  4. Run goi18n merge active.*.toml translate.*.toml to merge the translated messages into the active message files.

For more information and examples:

License

go-i18n is available under the MIT license. See the LICENSE file for more info.

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].