Skip to content

Commit

Permalink
Rename 'storage' to 'locale'
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
m-horky committed Oct 9, 2023
1 parent 9fe64fd commit 2fc6115
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions gotext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -112,7 +112,7 @@ func SetDomain(dom string) {
}
globalConfig.Unlock()

loadStorage(true)
loadLocales(true)
}

// GetLanguage returns the language gotext will translate into.
Expand Down Expand Up @@ -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
Expand All @@ -162,7 +162,7 @@ func SetLibrary(lib string) {
globalConfig.library = lib
globalConfig.Unlock()

loadStorage(true)
loadLocales(true)
}

func GetLocales() []*Locale {
Expand Down Expand Up @@ -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.
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2fc6115

Please sign in to comment.