Sha256: 6f8e4b6eee50f9228315f48565301b29b50a2e798d6378bc7539258a31ddd937
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 module TwitterCldr module Shared class 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 => e {} 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 => e 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 => e nil end protected def get_resource(locale) locale = TwitterCldr.convert_locale(locale) TwitterCldr.get_resource(locale, "languages")[locale] end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
twitter_cldr-1.1.0 | lib/shared/languages.rb |