Sha256: d8d6d1c0988aa58896725ed398bd1ee81b6370512db9162e2b48fed523ca3a43
Contents?: true
Size: 1.46 KB
Versions: 9
Compression:
Stored size: 1.46 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 module TwitterCldr module Shared module Languages class << self def all all_for(TwitterCldr.get_locale) end def all_for(code) get_resource(TwitterCldr.convert_locale(code.to_sym))[:languages] rescue {} end def from_code(code) from_code_for_locale(code, TwitterCldr.get_locale) end def from_code_for_locale(code, locale = TwitterCldr.get_locale) get_resource(TwitterCldr.convert_locale(locale.to_sym))[:languages][TwitterCldr.convert_locale(code.to_sym)] rescue nil end def translate_language(language, source_locale = :en, dest_locale = TwitterCldr.get_locale) source_locale = TwitterCldr.convert_locale(source_locale.to_sym) lang_code = get_resource(source_locale)[:languages].select { |key, val| val.downcase == language.downcase }.flatten.first if lang_code dest_locale = TwitterCldr.convert_locale(dest_locale.to_sym) get_resource(dest_locale)[:languages][lang_code.to_sym] else nil end rescue nil end protected def get_resource(locale) locale = TwitterCldr.convert_locale(locale) TwitterCldr.get_locale_resource(locale, :languages)[locale] end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems