i18n

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

Internationalization

New language

To localize into a new language:

  1. Create a folder in locales/ with the ISO 639-1 (preferred) or ISO 639-2 code.

  2. Copy the canonical example from locales/en/default.po:

    cp locales/en/default.po locales/<lang>/default.po
    
  3. Translate the msgstr values. Do not change other values in the file.

  4. Save the file and submit a pull request.

Update an existing language

To update an existing language:

  1. Find the language in the locales/ folder.

  2. Update the language on line 3.

  3. Update the msgstr fields to the new values.

  4. Save the file.

  5. Submit a pull request.

Terms

  • realm - public health authority, state, or hospital system. The system is multi-tenant, and a user can be a member of multiple realms. For example, the same doctor might operate clinics across state lines. In the US, each state is a "realm". In other areas, a realm could be a country or region.

  • case worker - someone at a health clinic, testing facility, doctor's office, etc that is managing cases related to COVID-19.

  • patient - the person who is being given a test result for COVID-19.

  • short code - 6-8 digit (numeric-only) code that is dictated to a patient by a case worker over the phone.

  • long code - 16+ alpha-numeric code that is sent to the patient via an SMS text message. This requires the patient to provide a phone number. If no phone number is provided, no long code is generated.

  • backup code - 6-8 digit (numeric-only) code that is dictated to a patient by a case worker over the phone if and only if the long code fails to dispatch (e.g. due to network issues). This requires the patient to provide a phone number. If no phone number is provided, no backup code is generated.

  • signing key - this refers to an asymmetric signing key (cryptography).

Documentation

Overview

Package i18n defines internationalization and localization.

Index

Constants

View Source
const (
	DefaultSource = iota
	RedirectSource
)

Variables

This section is empty.

Functions

func LocalesFS added in v0.26.0

func LocalesFS() fs.FS

LocalesFS returns the file system for the server assets.

func TranslatorLanguage added in v0.26.0

func TranslatorLanguage(l gotext.Translator) string

Types

type LocaleMap

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

LocaleMap is a map of locale names to their data structure.

func Load

func Load(opts ...Option) (*LocaleMap, error)

Load parses and loads the localization files from disk. It builds the locale matcher based on the currently available data (organized by folder).

Due to the heavy I/O, callers should cache the resulting value and only call Load when data needs to be refreshed.

func (*LocaleMap) Canonicalize

func (l *LocaleMap) Canonicalize(id string, matcher language.Matcher) (result string, retErr error)

Canonicalize converts the given ID to the expected name.

func (*LocaleMap) Lookup

func (l *LocaleMap) Lookup(ids ...string) gotext.Translator

Lookup finds the best locale for the given ids. If none exists, the default locale is used.

If reloading is enabled, the locales are reloaded before lookup. If reloading fails, it panics. For this reason, you should not enable reloading in production.

func (*LocaleMap) LookupDynamic added in v0.30.0

func (l *LocaleMap) LookupDynamic(realmID uint, realmDefaultLocale string, ids ...string) gotext.Translator

LookupDynamic finds the best locale for the given ids.

func (*LocaleMap) SetDynamicTranslations added in v0.30.0

func (l *LocaleMap) SetDynamicTranslations(incoming []*database.DynamicTranslation)

SetDynamicTranslations creates realm specific locals with translations based on what's in the database.

type Option

type Option func(*LocaleMap) *LocaleMap

Option is an option to creating a locale map.

func WithDefaultSource added in v1.1.0

func WithDefaultSource() Option

WithDefaultSource loads the default translations for the main Web UI (server).

func WithRedirectSource added in v1.1.0

func WithRedirectSource() Option

WithRedirectSource loads the translations for the redirect server.

func WithReloading

func WithReloading(v bool) Option

WithReloading enables hot reloading for the map.

type Source added in v1.1.0

type Source int

Jump to

Keyboard shortcuts

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