Class: SgtnClient::LocaleUtil
- Inherits:
-
Object
- Object
- SgtnClient::LocaleUtil
- Defined in:
- lib/sgtn-client/util/locale-util.rb
Class Method Summary collapse
- .fallback(locale) ⇒ Object
- .get_best_locale(locale) ⇒ Object
- .get_source_locale ⇒ Object
- .process_locale(locale = nil) ⇒ Object
Class Method Details
.fallback(locale) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sgtn-client/util/locale-util.rb', line 23 def self.fallback(locale) found = SgtnClient::DEFAULT_LOCALES.select {|e| e == locale} if !found.empty? return found[0] end if SgtnClient::MAP_LOCALES.key?(locale) return SgtnClient::MAP_LOCALES[locale] end parts = locale.split("-") if parts.size > 1 f = SgtnClient::DEFAULT_LOCALES.select {|e| e == parts[0]} if !f.empty? return f[0] end end return locale end |
.get_best_locale(locale) ⇒ Object
16 17 18 |
# File 'lib/sgtn-client/util/locale-util.rb', line 16 def self.get_best_locale(locale) fallback(process_locale(locale)) end |
.get_source_locale ⇒ Object
40 41 42 43 44 |
# File 'lib/sgtn-client/util/locale-util.rb', line 40 def self.get_source_locale env = SgtnClient::Config.default_environment source_locale = SgtnClient::Config.configurations[env]["default_language"] source_locale || 'en' end |
.process_locale(locale = nil) ⇒ Object
19 20 21 22 |
# File 'lib/sgtn-client/util/locale-util.rb', line 19 def self.process_locale(locale=nil) locale ||= SgtnClient::Config.configurations.default locale.to_s end |