Class: SgtnClient::LocaleUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/sgtn-client/util/locale-util.rb

Constant Summary collapse

MAP_LOCALES =
{
  'zh-CN' => 'zh-Hans',
  'zh-TW' => 'zh-Hant',
  'zh-Hans-CN' => 'zh-Hans',
  'zh-Hant-TW' => 'zh-Hant'
}.freeze

Class Method Summary collapse

Class Method Details

.get_best_locale(locale) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/sgtn-client/util/locale-util.rb', line 14

def self.get_best_locale(locale)
  return get_fallback_locale if locale.nil?

  locale = locale.to_s
  return get_fallback_locale if locale.empty?

  get_best_match(locale.gsub('_', '-'))
end

.get_default_localeObject



41
42
43
44
# File 'lib/sgtn-client/util/locale-util.rb', line 41

def self.get_default_locale
  env = SgtnClient::Config.default_environment
  SgtnClient::Config.configurations[env]['default_language']
end

.get_fallback_localeObject



46
47
48
# File 'lib/sgtn-client/util/locale-util.rb', line 46

def self.get_fallback_locale
  @fallback_locale ||= get_default_locale || get_source_locale || 'en'
end

.get_source_localeObject



37
38
39
# File 'lib/sgtn-client/util/locale-util.rb', line 37

def self.get_source_locale
  'en'
end

.is_source_locale(locale = nil) ⇒ Object



23
24
25
# File 'lib/sgtn-client/util/locale-util.rb', line 23

def self.is_source_locale(locale = nil)
  locale == get_source_locale
end