Documentation ¶
Overview ¶
Package l10n provides locale helpers (LocaleRegistry) and predefined standard keys for Alexa skills
Index ¶
- Constants
- Variables
- func GetLocales() map[string]LocaleInstance
- func Register(locale LocaleInstance, opts ...RegisterFunc) error
- func SetDefault(locale string) error
- type Config
- type Locale
- func (l *Locale) Get(key string, args ...interface{}) string
- func (l *Locale) GetAll(key string, args ...interface{}) []string
- func (l *Locale) GetAny(key string, args ...interface{}) string
- func (l *Locale) GetErrors() []error
- func (l *Locale) GetName() string
- func (l *Locale) ResetErrors()
- func (l *Locale) Set(key string, values []string)
- type LocaleError
- type LocaleInstance
- type LocaleRegistry
- type MissingPlaceholderError
- type NoTranslationError
- type RegisterFunc
- type Registry
- type Snippets
Constants ¶
const ( KeySkillName string = "SKILL_Name" KeySkillDescription string = "SKILL_Description" KeySkillSummary string = "SKILL_Summary" KeySkillExamplePhrases string = "SKILL_ExamplePhrases" KeySkillKeywords string = "SKILL_Keywords" KeySkillSmallIconURI string = "SKILL_SmallIconURI" KeySkillLargeIconURI string = "SKILL_LargeIconURI" KeySkillTestingInstructions string = "SKILL_TestingInstructions" KeySkillInvocation string = "SKILL_Invocation" KeySkillPrivacyPolicyURL string = "SKILL_PrivacyPolicyURL" KeySkillTermsOfUseURL string = "SKILL_TermsOfUse" KeyPostfixSamples string = "_Samples" KeyPostfixValues string = "_Values" KeyPostfixTitle string = "_Title" KeyPostfixText string = "_Text" KeyPostfixSSML string = "_SSML" // fallback, standard error. KeyErrorTitle string = "Error_Title" KeyErrorText string = "Error_Text" KeyErrorSSML string = "Error_SSML" // unknown error. KeyErrorUnknownTitle string = "Error_Unknown_Title" KeyErrorUnknownText string = "Error_Unknown_Text" KeyErrorUnknownSSML string = "Error_Unknown_SSML" // not found error (slot, intent, ...), see request.go. KeyErrorNotFoundTitle string = "Error_NotFound_Title" KeyErrorNotFoundText string = "Error_NotFound_Text" KeyErrorNotFoundSSML string = "Error_NotFound_SSML" // missing locale error. KeyErrorLocaleNotFoundTitle string = "Error_LocaleNotFound_Title" KeyErrorLocaleNotFoundText string = "Error_LocaleNotFound_Text" KeyErrorLocaleNotFoundSSML string = "Error_LocaleNotFound_SSML" // generic translation error. KeyErrorTranslationTitle string = "Error_Translation_Title" KeyErrorTranslationText string = "Error_Translation_Text" KeyErrorTranslationSSML string = "Error_Translation_SSML" // missing translation error. KeyErrorNoTranslationTitle string = "Error_NoTranslation_Title" KeyErrorNoTranslationText string = "Error_NoTranslation_Text" KeyErrorNoTranslationSSML string = "Error_NoTranslation_SSML" // missing placeholder in translation error. KeyErrorMissingPlaceholderTitle string = "Error_MissingPlaceholder_Title" KeyErrorMissingPlaceholderText string = "Error_MissingPlaceholder_Text" KeyErrorMissingPlaceholderSSML string = "Error_MissingPlaceholder_SSML" // default intents. KeyLaunchTitle string = "Launch_Title" KeyLaunchText string = "Launch_Text" KeyLaunchSSML string = "Launch_SSML" KeyHelpTitle string = "Help_Title" KeyHelpText string = "Help_Text" KeyHelpSSML string = "Help_SSML" KeyStopTitle string = "Stop_Title" KeyStopText string = "Stop_Text" KeyStopSSML string = "Stop_SSML" KeyCancelTitle string = "Cancel_Title" KeyCancelText string = "Cancel_Text" KeyCancelSSML string = "Cancel_SSML" )
Default keys.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the standard registry used.
Functions ¶
func GetLocales ¶
func GetLocales() map[string]LocaleInstance
GetLocales returns the locales registered in the DefaultRegistry.
func Register ¶
func Register(locale LocaleInstance, opts ...RegisterFunc) error
Register registers a new Locale in the DefaultRegistry.
func SetDefault ¶
SetDefault sets the default locale in the DefaultRegistry.
Types ¶
type Locale ¶
type Locale struct { Name string // de-DE, en-US, ... TextSnippets Snippets // contains filtered or unexported fields }
Locale is a representation of keys in a specific language.
type LocaleError ¶
LocaleError defines the interface for locale errors.
type LocaleInstance ¶
type LocaleInstance interface { GetName() string Set(key string, values []string) Get(key string, args ...interface{}) string GetAny(key string, args ...interface{}) string GetAll(key string, args ...interface{}) []string GetErrors() []error ResetErrors() }
LocaleInstance is the interface for a specific locale.
func GetDefault ¶
func GetDefault() LocaleInstance
GetDefault returns the default locale in the DefaultRegistry.
func Resolve ¶
func Resolve(name string) (LocaleInstance, error)
Resolve returns the matching locale from the DefaultRegistry.
type LocaleRegistry ¶
type LocaleRegistry interface { Register(locale LocaleInstance, opts ...RegisterFunc) error Resolve(locale string) (LocaleInstance, error) GetDefault() LocaleInstance SetDefault(locale string) error GetLocales() map[string]LocaleInstance }
LocaleRegistry is the interface for an l10n registry.
type MissingPlaceholderError ¶
MissingPlaceholderError defines a generic not found error.
func (MissingPlaceholderError) Error ¶
func (e MissingPlaceholderError) Error() string
Error returns a string representing the error including the key (and placeholder) missing.
func (MissingPlaceholderError) GetKey ¶
func (e MissingPlaceholderError) GetKey() string
GetKey returns the key of the error.
func (MissingPlaceholderError) GetLocale ¶
func (e MissingPlaceholderError) GetLocale() string
GetLocale returns locale of the error.
func (MissingPlaceholderError) GetPlaceholder ¶
func (e MissingPlaceholderError) GetPlaceholder() string
GetPlaceholder returns the placeholder concerned.
type NoTranslationError ¶
NoTranslationError defines a missing translation error.
func (NoTranslationError) Error ¶
func (n NoTranslationError) Error() string
Error returns a string of the error.
func (NoTranslationError) GetKey ¶
func (n NoTranslationError) GetKey() string
GetKey returns the associated key.
func (NoTranslationError) GetLocale ¶
func (n NoTranslationError) GetLocale() string
GetLocale returns the locale of the error.
func (NoTranslationError) GetPlaceholder ¶
func (n NoTranslationError) GetPlaceholder() string
GetPlaceholder returns the placeholder concerned.
type RegisterFunc ¶
type RegisterFunc func(cfg *Config)
RegisterFunc defines the functions to be passed to Register.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the Locale registry.
func (*Registry) GetDefault ¶
func (r *Registry) GetDefault() LocaleInstance
GetDefault returns the default locale.
func (*Registry) GetLocales ¶
func (r *Registry) GetLocales() map[string]LocaleInstance
GetLocales returns all registered locales.
func (*Registry) Register ¶
func (r *Registry) Register(l LocaleInstance, opts ...RegisterFunc) error
Register registers a new locale and fails if it already exists.
func (*Registry) Resolve ¶
func (r *Registry) Resolve(locale string) (LocaleInstance, error)
Resolve returns the Locale matching the given name or an error.
func (*Registry) SetDefault ¶
SetDefault sets the default locale which must be registered.