Documentation
¶
Overview ¶
Package i18n provides internationalization and localization services.
It is designed to be a simple, straightforward i18n solution that should be well-suited to most applications.
Getting Started ¶
To use the i18n service, you first need to create a new instance:
i18nService, err := i18n.New()
if err != nil {
log.Fatal(err)
}
Once you have a service instance, you can set the language and translate messages.
Locales ¶
The i18n service loads locales from the `locales` directory. Locales are JSON files with the language code as the filename (e.g., `en.json`, `es.json`). The service uses the `embed` package to bundle the locales into the binary, so you don't need to worry about distributing the locale files with your application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct{}
Options holds configuration for the i18n service. This is a placeholder for future configuration options.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides internationalization and localization. It is the primary entrypoint for the i18n package.
func New ¶
New creates a new i18n service. The service is initialized with the English language as the default.
func (*Service) AvailableLanguages ¶
AvailableLanguages returns a list of available language codes.
func (*Service) GetAllMessages ¶
GetAllMessages returns all translation messages for the specified language. The keys are message IDs and values are the translated strings. If lang is empty, it uses the current language.
func (*Service) SetLanguage ¶
SetLanguage sets the language for the i18n service. The language tag should be a valid BCP 47 language tag (e.g., "en", "en-US"). If the language is not supported, an error is returned.