Class: SgtnClient::LocaleUtil

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

Class Method Summary collapse

Class Method Details

.fallback(locale) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sgtn-client/util/locale-util.rb', line 13

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