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



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

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



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

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

.get_fallback_localeObject



52
53
54
# File 'lib/sgtn-client/util/locale-util.rb', line 52

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

.get_source_localeObject



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

def self.get_source_locale
  'en'
end

.is_source_locale(locale = nil) ⇒ Object



29
30
31
# File 'lib/sgtn-client/util/locale-util.rb', line 29

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