Merge pull request #77 from taozhou-glean/tao-add-get-language

feat: Add language getter for Locale
This commit is contained in:
Leonel Quinteros 2023-05-09 15:50:24 -03:00 committed by GitHub
commit db315c3450
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View file

@ -192,6 +192,14 @@ func (l *Locale) SetDomain(dom string) {
l.Unlock()
}
// GetLanguage is the lang getter for Locale configuration
func (l *Locale) GetLanguage() string {
l.RLock()
lang := l.lang
l.RUnlock()
return lang
}
// Get uses a domain "default" to return the corresponding Translation of a given string.
// Supports optional parameters (vars... interface{}) to be inserted on the formatted string using the fmt.Printf syntax.
func (l *Locale) Get(str string, vars ...interface{}) string {

View file

@ -226,6 +226,12 @@ msgstr "More Translation"
// Create Locale with full language code
l := NewLocale("/tmp", "en_US")
// Test language
language := l.GetLanguage()
if language != "en_US" {
t.Errorf("Expected 'en_US' but got '%s'", language)
}
// Force nil domain storage
l.Domains = nil
@ -293,6 +299,12 @@ msgstr "More Translation"
// Create Locale with full language code
l = NewLocale("/tmp", "golem")
// Test language
language = l.GetLanguage()
if language != "golem" {
t.Errorf("Expected 'golem' but got '%s'", language)
}
// Force nil domain storage
l.Domains = nil
@ -323,6 +335,12 @@ msgstr "More Translation"
// Create Locale with full language code
l = NewLocale("fixtures/", "fr_FR")
// Test language
language = l.GetLanguage()
if language != "fr_FR" {
t.Errorf("Expected 'fr_FR' but got '%s'", language)
}
// Force nil domain storage
l.Domains = nil
@ -353,6 +371,12 @@ msgstr "More Translation"
// Create Locale with full language code
l = NewLocale("fixtures/", "de_DE")
// Test language
language = l.GetLanguage()
if language != "de_DE" {
t.Errorf("Expected 'de_DE' but got '%s'", language)
}
// Force nil domain storage
l.Domains = nil
@ -383,6 +407,12 @@ msgstr "More Translation"
// Create Locale with full language code
l = NewLocale("fixtures/", "de_AT")
// Test language
language = l.GetLanguage()
if language != "de_AT" {
t.Errorf("Expected 'de_AT' but got '%s'", language)
}
// Force nil domain storage
l.Domains = nil