68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package locale
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// Language code type
|
|
type Lang string
|
|
|
|
const (
|
|
EN_CA Lang = "en-CA"
|
|
FR_CA Lang = "fr-CA"
|
|
IU_CA Lang = "iu-CA" // Inuktitut (syllabics + roman in parentheses)
|
|
)
|
|
|
|
// Bundle mirrors the JSON structure
|
|
type Bundle struct {
|
|
UI struct {
|
|
Loading string `json:"loading"`
|
|
FetchingWeather string `json:"fetching_weather"`
|
|
CurrentCond string `json:"current_conditions"`
|
|
FeelsLike string `json:"feels_like"`
|
|
Humidity string `json:"humidity"`
|
|
Wind string `json:"wind"`
|
|
Pressure string `json:"pressure"`
|
|
Visibility string `json:"visibility"`
|
|
Sunrise string `json:"sunrise"`
|
|
Sunset string `json:"sunset"`
|
|
Alerts string `json:"alerts"`
|
|
NoAlerts string `json:"no_alerts"`
|
|
Updated string `json:"updated"`
|
|
Location string `json:"location"`
|
|
Language string `json:"language"`
|
|
SelectLang string `json:"select_language"`
|
|
SelectLocation string `json:"select_location"`
|
|
ManualEntry string `json:"manual_entry"`
|
|
} `json:"ui"`
|
|
|
|
Conditions map[string]string `json:"conditions"`
|
|
Alerts map[string]string `json:"alerts"`
|
|
|
|
Locale string `json:"locale"`
|
|
Language string `json:"language_name"`
|
|
Script string `json:"script"`
|
|
}
|
|
|
|
// Runtime loaded language bundles (populated by loader.go)
|
|
var bundles = map[Lang]Bundle{}
|
|
|
|
// Register language bundle
|
|
func register(lang Lang, b Bundle) {
|
|
bundles[lang] = b
|
|
}
|
|
|
|
// Get returns a language bundle, defaulting to EN_CA
|
|
func Get(lang Lang) Bundle {
|
|
if b, ok := bundles[lang]; ok {
|
|
return b
|
|
}
|
|
return bundles[EN_CA]
|
|
}
|
|
|
|
// Normalize condition keys internally
|
|
func Normalize(cond string) string {
|
|
c := strings.ToLower(cond)
|
|
return strings.ReplaceAll(c, " ", "_")
|
|
}
|