From 2fc6115a3245598630d4f0a83955fd22dd6aa771 Mon Sep 17 00:00:00 2001 From: Matyas Horky Date: Wed, 30 Aug 2023 10:31:23 +0200 Subject: [PATCH] Rename 'storage' to 'locale' As the package matured, it makes sense to use unified names everywhere. Since the config holds Locale objects, the variable is called 'locales'. This patch finishes the work and updates the 'loadStorage' function to be called 'localLocales' with argument 'rebuildCache' instead of 'force'. --- gotext.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/gotext.go b/gotext.go index 1c0223e..93c0089 100644 --- a/gotext.go +++ b/gotext.go @@ -60,13 +60,13 @@ func init() { gob.Register(TranslatorEncoding{}) } -// loadStorage creates a new Locale object at package level based on the Global variables settings -// for every language specified using Configure. -// It's called automatically when trying to use Get or GetD methods. -func loadStorage(force bool) { +// loadLocales creates a new Locale object for every language (specified using Configure) +// at package level based on the configuration of global configuration . +// It is called when trying to use Get or GetD methods. +func loadLocales(rebuildCache bool) { globalConfig.Lock() - if globalConfig.locales == nil || force { + if globalConfig.locales == nil || rebuildCache { var locales []*Locale for _, language := range globalConfig.languages { locales = append(locales, NewLocale(globalConfig.library, language)) @@ -75,7 +75,7 @@ func loadStorage(force bool) { } for _, locale := range globalConfig.locales { - if _, ok := locale.Domains[globalConfig.domain]; !ok || force { + if _, ok := locale.Domains[globalConfig.domain]; !ok || rebuildCache { locale.AddDomain(globalConfig.domain) } locale.SetDomain(globalConfig.domain) @@ -112,7 +112,7 @@ func SetDomain(dom string) { } globalConfig.Unlock() - loadStorage(true) + loadLocales(true) } // GetLanguage returns the language gotext will translate into. @@ -143,7 +143,7 @@ func SetLanguage(lang string) { globalConfig.languages = languages globalConfig.Unlock() - loadStorage(true) + loadLocales(true) } // GetLibrary is the library getter for the package configuration @@ -162,7 +162,7 @@ func SetLibrary(lib string) { globalConfig.library = lib globalConfig.Unlock() - loadStorage(true) + loadLocales(true) } func GetLocales() []*Locale { @@ -233,7 +233,7 @@ func Configure(lib, lang, dom string) { globalConfig.domain = dom globalConfig.Unlock() - loadStorage(true) + loadLocales(true) } // Get uses the default domain globally set to return the corresponding Translation of a given string. @@ -251,8 +251,8 @@ func GetN(str, plural string, n int, vars ...interface{}) string { // GetD returns the corresponding Translation in the given domain for a given string. // Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. func GetD(dom, str string, vars ...interface{}) string { - // Try to load default package Locale storage - loadStorage(false) + // Try to load default package Locales + loadLocales(false) globalConfig.RLock() defer globalConfig.RUnlock() @@ -274,8 +274,8 @@ func GetD(dom, str string, vars ...interface{}) string { // GetND retrieves the (N)th plural form of Translation in the given domain for a given string. // Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. func GetND(dom, str, plural string, n int, vars ...interface{}) string { - // Try to load default package Locale storage - loadStorage(false) + // Try to load default package Locales + loadLocales(false) globalConfig.RLock() defer globalConfig.RUnlock() @@ -309,8 +309,8 @@ func GetNC(str, plural string, n int, ctx string, vars ...interface{}) string { // GetDC returns the corresponding Translation in the given domain for the given string in the given context. // Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. func GetDC(dom, str, ctx string, vars ...interface{}) string { - // Try to load default package Locale storage - loadStorage(false) + // Try to load default package Locales + loadLocales(false) globalConfig.RLock() defer globalConfig.RUnlock() @@ -329,8 +329,8 @@ func GetDC(dom, str, ctx string, vars ...interface{}) string { // GetNDC retrieves the (N)th plural form of Translation in the given domain for a given string. // Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax. func GetNDC(dom, str, plural string, n int, ctx string, vars ...interface{}) string { - // Try to load default package Locale storage - loadStorage(false) + // Try to load default package Locales + loadLocales(false) // Return Translation globalConfig.RLock() @@ -372,7 +372,7 @@ func IsTranslatedND(dom, str string, n int, langs ...string) bool { langs = GetLanguages() } - loadStorage(false) + loadLocales(false) globalConfig.RLock() defer globalConfig.RUnlock() @@ -415,7 +415,7 @@ func IsTranslatedNDC(dom, str string, n int, ctx string, langs ...string) bool { langs = GetLanguages() } - loadStorage(false) + loadLocales(false) globalConfig.RLock() defer globalConfig.RUnlock()