li18ngo

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 4 Imported by: 10

README ΒΆ

🌐 li18ngo: i18n helper

A B A B A B Go Reference Go report Coverage Status Li18ngo Continuous Integration pre-commit A B

go dev

πŸ”° Introduction

This project contains helpers to aid in the development of libraries and programs that require i18n support. It doesn't perform i18n itself, that is delegated to go-i18n. Rather it aims to provide functionality that makes using go-i18n easier. For example, implementing localised error messages can be a bit tedious and error prone so included within this module is a cli app, lingo, that can generate all error related code (PS, this has not been implemented yet, so is still in the works).

πŸ“š Usage

πŸŽ€ Features

ginkgo gomega

🌐 l10n Translations

This template has been setup to support localisation. The default language is en-GB with support for en-US. There is a translation file for en-US defined as src/i18n/deploy/arcadia.active.en-US.json. This is the initial translation for en-US that should be deployed with the app.

Make sure that the go-i18n package has been installed so that it can be invoked as cli, see go-i18n for installation instructions.

To maintain localisation of the application, the user must take care to implement all steps to ensure translate-ability of all user facing messages. Whenever there is a need to add/change user facing messages including error messages, to maintain this state, the user must:

  • define template struct (xxxTemplData) in src/i18n/messages.go and corresponding Message() method. All messages are defined here in the same location, simplifying the message extraction process as all extractable strings occur at the same place. Please see go-i18n for all translation/pluralisation options and other regional sensitive content.

For more detailed workflow instructions relating to i18n, please see i18n README. For details on how defining translate-able content can be achieved consistently, see Defining Content

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var (

	// DefaultLanguage represents the default language of this module
	DefaultLanguage = translate.DefaultLanguage

	// ErrSafePanicWarning is the error raised as a panic if the client
	// has accidentally not called Use before working with li18ngo.
	ErrSafePanicWarning = translate.ErrSafePanicWarning

	// Li18ngoSourceID the id that represents this module. If a client want
	// to provides translations for languages that li18ngo does not, then
	// the localizer the 'create' created for this purpose should use this
	// SourceID. So whenever the Text function is used on templates defined
	// inside this module, the translation process is directed to use the
	// correct i18n.Localizer (identified by the SourceID). The Source is
	// statically defined for all templates defined in li18ngo.
	Li18ngoSourceID = translate.Li18ngoSourceID

	// Text is the function to use to obtain a string created from
	// registered Localizers. The data parameter must be a go template
	// defining the input parameters and the translatable message content.
	// Not threadsafe.
	Text = translate.Text

	// Use, must be called before any string data can be translated.
	// If requesting the default language, then only the language Tag
	// needs to be provided. If the requested language is not the default
	// and therefore requires translation from the translation file(s), then
	// the App and Path properties must be provided indicating
	// how the i18n bundle is created.
	// If only the Default language, then Use can even be called without
	// specifying the Tag and in this case the default language will be
	// used. The client MUST call Use before using any functionality in
	// this package.
	Use = translate.Use
)

Functions ΒΆ

This section is empty.

Types ΒΆ

type ExistsInFS ΒΆ

type ExistsInFS = nef.ExistsInFS

ExistsInFS provides the facility to check the existence of a path in the underlying file system.

type LanguageInfo ΒΆ

type LanguageInfo = translate.LanguageInfo

LanguageInfo information pertaining to setting language. Auto detection is not supported. Any executable that supports i18n, should perform auto detection and then invoke Use, with the detected language tag

type LoadFrom ΒΆ

type LoadFrom = translate.LoadFrom

LoadFrom denotes where to load the translation file from

type LocalisableError ΒΆ

type LocalisableError = translate.LocalisableError

LocalisableError is an error that is translate-able (Localisable)

type LocalizerCreatorFn ΒΆ

type LocalizerCreatorFn = translate.LocalizerCreatorFn

LocalizerCreatorFn represents the signature of the function that can optionally be provided to override how an i18n Localizer is created.

type MakeDirFS ΒΆ added in v0.1.5

type MakeDirFS = nef.MakeDirFS

MakeDirFS is a file system with a MkDirAll method.

type NotADirectoryError ΒΆ

type NotADirectoryError struct {
	translate.LocalisableError
}

func NewNotADirectoryError ΒΆ

func NewNotADirectoryError(path string) NotADirectoryError

NewNotADirectoryError creates a NotADirectoryError

func (NotADirectoryError) NotADirectory ΒΆ

func (e NotADirectoryError) NotADirectory() bool

NotADirectory enables the client to check if error is NotADirectoryError via QueryNotADirectoryError

type NotADirectoryErrorBehaviourQuery ΒΆ

type NotADirectoryErrorBehaviourQuery interface {
	NotADirectory() bool
}

NotADirectoryErrorBehaviourQuery used to query if an error is: "File system path is not a directory"

type NotADirectoryTemplData ΒΆ

type NotADirectoryTemplData struct {
	locale.Li18ngoTemplData
	Path string
}

NotADirectoryTemplData path is not a directory

func (NotADirectoryTemplData) Message ΒΆ

func (td NotADirectoryTemplData) Message() *i18n.Message

type PathNotFoundError ΒΆ

type PathNotFoundError struct {
	translate.LocalisableError
}

func NewPathNotFoundError ΒΆ

func NewPathNotFoundError(name, path string) PathNotFoundError

NewPathNotFoundError creates a PathNotFoundError

func (PathNotFoundError) IsPathNotFound ΒΆ

func (e PathNotFoundError) IsPathNotFound() bool

PathNotFound enables the client to check if error is PathNotFoundError via QueryPathNotFoundError

type PathNotFoundErrorBehaviourQuery ΒΆ

type PathNotFoundErrorBehaviourQuery interface {
	IsPathNotFound() bool
}

PathNotFoundErrorBehaviourQuery used to query if an error is: "File system foo is ..."

type PathNotFoundTemplData ΒΆ

type PathNotFoundTemplData struct {
	locale.Li18ngoTemplData
	Name string
	Path string
}

PathNotFoundTemplData is

func (PathNotFoundTemplData) Message ΒΆ

func (td PathNotFoundTemplData) Message() *i18n.Message

type SupportedLanguages ΒΆ

type SupportedLanguages = translate.SupportedLanguages

SupportedLanguages is a collection of the language Tags that a module can define to express what languages it contains translations for.

type TemplData ΒΆ

type TemplData struct{}

func (TemplData) SourceID ΒΆ

func (td TemplData) SourceID() string

type ThirdPartyError ΒΆ

type ThirdPartyError struct {
	translate.LocalisableError
}

ThirdPartyError represents an error received by a dependency that does not support i18n.

func NewThirdPartyErr ΒΆ

func NewThirdPartyErr(err error) ThirdPartyError

NewThirdPartyErr creates a ThirdPartyErr

type ThirdPartyErrorTemplData ΒΆ

type ThirdPartyErrorTemplData struct {
	locale.Li18ngoTemplData

	Error error
}

ThirdPartyErrorTemplData third party un-translated error

func (ThirdPartyErrorTemplData) Message ΒΆ

func (td ThirdPartyErrorTemplData) Message() *i18n.Message

type TranslationFiles ΒΆ

type TranslationFiles = translate.TranslationFiles

TranslationFiles maps a source id to a TranslationSource

type TranslationSource ΒΆ

type TranslationSource = translate.TranslationSource

TranslationSource Name: core name of dependency's translation file. The actual file is derived from this name in the form: <name>.active.<lang>.json; eg li18ngo.active.en-GB.json. Path: file system path to the translation file. If missing, then it will default to the location of the executable file.

type UseOptionFn ΒΆ

type UseOptionFn = translate.UseOptionFn

UseOptionFn functional options function required by Use.

type UseOptions ΒΆ

type UseOptions = translate.UseOptions

UseOptions the options provided to the Use function

Directories ΒΆ

Path Synopsis
cmd
lingo command
internal
lab
tools
mio