-
Notifications
You must be signed in to change notification settings - Fork 1
Locales
Go-gui's locale system controls number formatting, date formatting, currency display, and UI string translation. Locales are values — register them, switch at runtime, and use the formatting helpers wherever you display locale-sensitive data.
type Locale struct {
ID string // e.g. "en-US", "de-DE"
Label string // human-readable label
NumberFormat NumberFormat // digit grouping, decimal/group separators
DateFormat DateFormat // short/long date patterns, first day of week
CurrencyFormat CurrencyFormat // symbol, code, position, decimal places
Translations map[string]string
}The zero-value Locale{} uses en-US defaults (period decimal, comma grouping,
M/D/YYYY dates, USD currency).
NumberFormat controls how numbers are displayed:
type NumberFormat struct {
GroupSizes []int // default [3]
DecimalSep rune // default '.'
GroupSep rune // default ','
MinusSign rune // default '-'
PlusSign rune // default '+'
}Use gui.LocaleFormatFloat64(v, decimals, lc) or gui.LocaleFormatInt64(n, lc) to
format numbers for display:
lc, _ := gui.LocaleGet("de-DE")
s := gui.LocaleFormatFloat64(1234567.89, 2, lc)
// "1.234.567,89"DateFormat controls date patterns and calendar conventions:
type DateFormat struct {
ShortDate string // "M/D/YYYY" or "DD.MM.YYYY"
LongDate string // "MMMM D, YYYY" or "D. MMMM YYYY"
MonthYear string // "MMMM YYYY"
FirstDayOfWeek uint8 // 0=Sunday, 1=Monday
Use24H bool
}Format a date with gui.LocaleFormatDate(t, format):
lc, _ := gui.LocaleGet("de-DE")
s := gui.LocaleFormatDate(time.Now(), lc.DateFormat.ShortDate)
// "14.06.2026"Pattern tokens: YYYY (4-digit year), MM / M (month, zero-padded or not),
DD / D (day), HH, mm, ss. Month names come from the locale's translations
map ("January", "Jan", etc.).
type CurrencyFormat struct {
Symbol string // "$", "€", "¥"
Code string // "USD", "EUR", "JPY"
Position NumericAffixPosition // AffixPrefix or AffixSuffix
Spacing bool // true adds a space between symbol and amount
Decimals int // 2
}Use gui.LocaleFormatCurrency(amount float64, lc Locale) to format a monetary value.
Go-gui ships preset locale data for:
| Locale ID | Language / Region |
|---|---|
en-US |
English (United States) — the default |
de-DE |
German (Germany) |
es-ES |
Spanish (Spain) |
fr-FR |
French (France) |
he-IL |
Hebrew (Israel) |
ja-JP |
Japanese |
ko-KR |
Korean |
pt-BR |
Portuguese (Brazil) |
zh-CN |
Chinese (Simplified) |
ar-SA |
Arabic (Saudi Arabia) |
Presets auto-register at init. Add your own:
gui.LocaleRegister(gui.Locale{
ID: "en-GB",
Label: "English (UK)",
DateFormat: gui.DateFormat{
ShortDate: "DD/MM/YYYY",
LongDate: "D MMMM YYYY",
MonthYear: "MMMM YYYY",
FirstDayOfWeek: 1, // Monday
Use24H: false,
},
CurrencyFormat: gui.CurrencyFormat{
Symbol: "£",
Code: "GBP",
Position: gui.AffixPrefix,
Decimals: 2,
},
Translations: map[string]string{
"January": "January",
"Feb": "Feb",
// ... fill in all month/weekday keys
},
})
lc, ok := gui.LocaleGet("en-GB")gui.LocaleRegisteredNames() []string returns sorted IDs of all registered locales. Use it
to populate a locale picker.
gui.LocaleLoadDir(dir string) error reads all *.json files from a directory and
registers each as a locale. File names should match locale IDs (e.g. de-DE.json).
Getting Started
Widgets
Layout & Interaction
Visuals
Reference