i18n

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 8 Imported by: 0

README

i18n License MIT

i18n is a Go package that helps you translate Go programs into multiple languages.

Features

  • plural

Installation

go get -u github.com/yarigo/i18n

Rules

For set a current localization, use a language mather function of all supported languages and match from it by language string:

matcher := language.NewMatcher([]language.Tag{
	language.English, // The first language is used as fallback.
	language.MustParse("en-AU"),
	language.Danish,
	language.Chinese,
	language.Russian,
})

lang, _ := language.MatchStrings(matcher, "ru")

Package support multiple definition by its number identification. As identification use a position into array rules. See tests for understanding this.

plural

If you want to use plural function, you can set it as "plural:one" or "one" (without plural prefix).

A selector matches an argument if:

  • it is "other" or Other
  • it matches the plural form of the argument: "zero", "one", "two", "few", or "many", or the equivalent Form
  • it is of the form "=x" where x is an integer that matches the value of the argument.
  • it is of the form "<x" where x is an integer that is larger than the argument.

For use a format, set it as suffix. For example:

"one:%d": "..."

or

"plural:one:%d": "..."

Examples of format strings are:

  • %.2f decimal with scale 2
  • %.2e scientific notation with precision 3 (scale + 1)
  • %d integer

Locale structure

{
	"messages": [
		{
			"id": "id of message",
			"text": "message",
			"rules": ["rules"]
		}
	]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I18n

type I18n struct {
	// contains filtered or unexported fields
}

I18n structure data.

func New

func New() *I18n

New instance.

func (*I18n) L10n

func (i *I18n) L10n(lang language.Tag) *message.Printer

L10n return current localization printer.

func (*I18n) Load

func (i *I18n) Load(lang language.Tag, data *[]byte) error

Load translation data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL