Documentation
¶
Index ¶
- Variables
- func Button(lang, key string, args ...interface{}) string
- func ConvertDigits(number string, lang string) string
- func Error(lang, key string, args ...interface{}) string
- func FormatCurrency(amount float64, lang string) string
- func FormatNumber(value float64, lang string, decimals int) string
- func GetCSSClass(lang string) string
- func GetHTMLAttributes(lang string) map[string]string
- func Initialize(config *Config) error
- func IsRTL(code string) bool
- func Label(lang, key string, args ...interface{}) string
- func Message(lang, key string, args ...interface{}) string
- func Success(lang, key string, args ...interface{}) string
- func TemplateFuncs(lang string) template.FuncMap
- func Validation(lang, key string, args ...interface{}) string
- type Config
- type CurrencyFormat
- type I18n
- func (i *I18n) AddTranslation(lang, key, value string)
- func (i *I18n) GetAllKeys(lang string) []string
- func (i *I18n) GetDefaultLanguage() string
- func (i *I18n) GetSupportedLanguages() []string
- func (i *I18n) GetTranslations(lang string) map[string]interface{}
- func (i *I18n) LoadCustomTranslations(lang string, jsonData string) error
- func (i *I18n) SetDefaultLanguage(lang string) error
- func (i *I18n) T(lang, key string, args ...interface{}) string
- func (i *I18n) Translate(lang, key string, args ...interface{}) string
- type LanguageConfig
- type LanguageDirection
- type NumberFormat
Constants ¶
This section is empty.
Variables ¶
var SupportedLanguages = map[string]LanguageConfig{ "en": { Code: "en", Name: "English", NativeName: "English", Direction: LTR, DateFormat: "Jan 2, 2006", TimeFormat: "3:04 PM", NumberFormat: NumberFormat{ DecimalSeparator: ".", ThousandSeparator: ",", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "$", Code: "USD", Position: "before", DecimalPlaces: 2, SpaceAfterSymbol: false, }, }, "es": { Code: "es", Name: "Spanish", NativeName: "Español", Direction: LTR, DateFormat: "2 de Jan de 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ",", ThousandSeparator: ".", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "€", Code: "EUR", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "fr": { Code: "fr", Name: "French", NativeName: "Français", Direction: LTR, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ",", ThousandSeparator: " ", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "€", Code: "EUR", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "de": { Code: "de", Name: "German", NativeName: "Deutsch", Direction: LTR, DateFormat: "2. Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ",", ThousandSeparator: ".", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "€", Code: "EUR", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "ar": { Code: "ar", Name: "Arabic", NativeName: "العربية", Direction: RTL, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: "٫", ThousandSeparator: "٬", Digits: "٠١٢٣٤٥٦٧٨٩", }, Currency: CurrencyFormat{ Symbol: "ر.س", Code: "SAR", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "he": { Code: "he", Name: "Hebrew", NativeName: "עברית", Direction: RTL, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ".", ThousandSeparator: ",", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "₪", Code: "ILS", Position: "before", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "fa": { Code: "fa", Name: "Persian", NativeName: "فارسی", Direction: RTL, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: "٫", ThousandSeparator: "٬", Digits: "۰۱۲۳۴۵۶۷۸۹", }, Currency: CurrencyFormat{ Symbol: "﷼", Code: "IRR", Position: "after", DecimalPlaces: 0, SpaceAfterSymbol: true, }, }, "ur": { Code: "ur", Name: "Urdu", NativeName: "اردو", Direction: RTL, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ".", ThousandSeparator: ",", Digits: "۰۱۲۳۴۵۶۷۸۹", }, Currency: CurrencyFormat{ Symbol: "Rs", Code: "PKR", Position: "before", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "ja": { Code: "ja", Name: "Japanese", NativeName: "日本語", Direction: LTR, DateFormat: "2006年1月2日", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ".", ThousandSeparator: ",", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "¥", Code: "JPY", Position: "before", DecimalPlaces: 0, SpaceAfterSymbol: false, }, }, "zh": { Code: "zh", Name: "Chinese", NativeName: "中文", Direction: LTR, DateFormat: "2006年1月2日", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ".", ThousandSeparator: ",", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "¥", Code: "CNY", Position: "before", DecimalPlaces: 2, SpaceAfterSymbol: false, }, }, "pl": { Code: "pl", Name: "Polish", NativeName: "Polski", Direction: LTR, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ",", ThousandSeparator: " ", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "zł", Code: "PLN", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "pt": { Code: "pt", Name: "Portuguese", NativeName: "Português", Direction: LTR, DateFormat: "2 de Jan de 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ",", ThousandSeparator: ".", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "R$", Code: "BRL", Position: "before", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "tlh": { Code: "tlh", Name: "Klingon", NativeName: "tlhIngan Hol", Direction: LTR, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ".", ThousandSeparator: ",", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "DarSeq", Code: "DRK", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "ru": { Code: "ru", Name: "Russian", NativeName: "Русский", Direction: LTR, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ",", ThousandSeparator: " ", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "₽", Code: "RUB", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, "uk": { Code: "uk", Name: "Ukrainian", NativeName: "Українська", Direction: LTR, DateFormat: "2 Jan 2006", TimeFormat: "15:04", NumberFormat: NumberFormat{ DecimalSeparator: ",", ThousandSeparator: " ", Digits: "0123456789", }, Currency: CurrencyFormat{ Symbol: "₴", Code: "UAH", Position: "after", DecimalPlaces: 2, SpaceAfterSymbol: true, }, }, }
SupportedLanguages contains configuration for all supported languages.
Functions ¶
func ConvertDigits ¶
ConvertDigits converts Western digits to locale-specific digits.
func FormatCurrency ¶
FormatCurrency formats currency according to language configuration.
func FormatNumber ¶
FormatNumber formats a number according to language configuration.
func GetCSSClass ¶
GetCSSClass returns CSS classes for language-specific styling.
func GetHTMLAttributes ¶
GetHTMLAttributes returns HTML attributes for language support.
func TemplateFuncs ¶
TemplateFuncs returns template functions for i18n.
func Validation ¶
Validation returns a translated validation message.
Types ¶
type CurrencyFormat ¶
type CurrencyFormat struct {
Symbol string `json:"symbol"`
Code string `json:"code"`
Position string `json:"position"` // before or after
DecimalPlaces int `json:"decimal_places"`
SpaceAfterSymbol bool `json:"space_after_symbol"`
}
CurrencyFormat represents currency formatting configuration.
type I18n ¶
type I18n struct {
// contains filtered or unexported fields
}
I18n handles internationalization.
var Instance *I18n
Instance is the global i18n instance.
func (*I18n) AddTranslation ¶
AddTranslation adds or updates a translation.
func (*I18n) GetAllKeys ¶
GetAllKeys returns all translation keys for a language in dot notation.
func (*I18n) GetDefaultLanguage ¶
GetDefaultLanguage returns the default language.
func (*I18n) GetSupportedLanguages ¶
GetSupportedLanguages returns the list of supported languages.
func (*I18n) GetTranslations ¶
GetTranslations returns all translations for a language.
func (*I18n) LoadCustomTranslations ¶
LoadCustomTranslations loads custom translations from a JSON string.
func (*I18n) SetDefaultLanguage ¶
SetDefaultLanguage sets the default language.
type LanguageConfig ¶
type LanguageConfig struct {
Code string `json:"code"`
Name string `json:"name"`
NativeName string `json:"native_name"`
Direction LanguageDirection `json:"direction"`
DateFormat string `json:"date_format"`
TimeFormat string `json:"time_format"`
NumberFormat NumberFormat `json:"number_format"`
Currency CurrencyFormat `json:"currency"`
Enabled bool `json:"enabled"`
}
LanguageConfig contains configuration for each language.
func GetEnabledLanguages ¶
func GetEnabledLanguages() []LanguageConfig
GetEnabledLanguages returns languages that have translation files. A language is considered enabled if its JSON file exists in the embedded translations.
func GetLanguageConfig ¶
func GetLanguageConfig(code string) (LanguageConfig, bool)
GetLanguageConfig returns configuration for a language.
type LanguageDirection ¶
type LanguageDirection string
LanguageDirection represents text direction.
const ( // LTR represents left-to-right text direction. LTR LanguageDirection = "ltr" // RTL represents right-to-left text direction. RTL LanguageDirection = "rtl" )
func GetDirection ¶
func GetDirection(code string) LanguageDirection
GetDirection returns the text direction for a language.
type NumberFormat ¶
type NumberFormat struct {
DecimalSeparator string `json:"decimal_separator"`
ThousandSeparator string `json:"thousand_separator"`
Digits string `json:"digits"` // For languages with different digit systems
}
NumberFormat represents number formatting configuration.