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
LOCALE_SEPARATOR =
'-'

Class Method Summary collapse

Class Method Details

.get_best_locale(locale) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/sgtn-client/util/locale-util.rb', line 16

def self.get_best_locale(locale)
  return locale if Config.available_locales.include?(locale)

  return get_fallback_locale if locale.nil?

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

  get_best_match(locale.gsub('_', LOCALE_SEPARATOR).downcase)
end

.get_default_localeObject



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

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

.get_fallback_localeObject



50
51
52
# File 'lib/sgtn-client/util/locale-util.rb', line 50

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

.get_source_localeObject



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

def self.get_source_locale
  'en'
end

.is_source_locale(locale = nil) ⇒ Object



27
28
29
# File 'lib/sgtn-client/util/locale-util.rb', line 27

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