This repository has been archived on 2019-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mumbledj/vendor/github.com/nicksnyder/go-i18n
2016-06-21 09:05:20 -07:00
..
goi18n Update vendored dependencies, added goi18n 2016-06-21 09:05:20 -07:00
i18n Update vendored dependencies, added goi18n 2016-06-21 09:05:20 -07:00
.gitignore Update vendored dependencies, added goi18n 2016-06-21 09:05:20 -07:00
.travis.yml Update vendored dependencies, added goi18n 2016-06-21 09:05:20 -07:00
CHANGELOG Update vendored dependencies, added goi18n 2016-06-21 09:05:20 -07:00
LICENSE Update vendored dependencies, added goi18n 2016-06-21 09:05:20 -07:00
README.md Update vendored dependencies, added goi18n 2016-06-21 09:05:20 -07:00

go-i18n Build Status

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 runtime APIs for fetching translated strings.

Command goi18n GoDoc

The goi18n command provides functionality for managing the translation process.

Installation

Make sure you have setup GOPATH.

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

Workflow

A typical workflow looks like this:

  1. Add a new string to your source code.

    T("settings_title")
    
  2. Add the string to en-US.all.json

    [
      {
        "id": "settings_title",
        "translation": "Settings"
      }
    ]
    
  3. Run goi18n

    goi18n path/to/*.all.json
    
  4. Send path/to/*.untranslated.json to get translated.

  5. Run goi18n again to merge the translations

    goi18n path/to/*.all.json path/to/*.untranslated.json
    

Translation files

A translation file stores translated and untranslated strings.

Example:

[
  {
    "id": "d_days",
    "translation": {
      "one": "{{.Count}} day",
      "other": "{{.Count}} days"
    }
  },
  {
    "id": "my_height_in_meters",
    "translation": {
      "one": "I am {{.Count}} meter tall.",
      "other": "I am {{.Count}} meters tall."
    }
  },
  {
    "id": "person_greeting",
    "translation": "Hello {{.Person}}"
  },
  {
    "id": "person_unread_email_count",
    "translation": {
      "one": "{{.Person}} has {{.Count}} unread email.",
      "other": "{{.Person}} has {{.Count}} unread emails."
    }
  },
  {
    "id": "person_unread_email_count_timeframe",
    "translation": {
      "one": "{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}.",
      "other": "{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}."
    }
  },
  {
    "id": "program_greeting",
    "translation": "Hello world"
  },
  {
    "id": "your_unread_email_count",
    "translation": {
      "one": "You have {{.Count}} unread email.",
      "other": "You have {{.Count}} unread emails."
    }
  }
]

Contributions

If you would like to submit a pull request, please

  1. Write tests
  2. Format code with goimports.
  3. Read the common code review comments.

License

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