Sha256: 1094bfe0977fe6f7c07f9c20637f68d974bfab0943af18fdf775719316de7c3b

Contents?: true

Size: 1.37 KB

Versions: 24

Compression:

Stored size: 1.37 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.locale)
        end

        def all_for(code)
          get_resource(code)[:languages]
        rescue
          {}
        end

        def from_code(code)
          from_code_for_locale(code, TwitterCldr.locale)
        end

        def from_code_for_locale(code, locale = TwitterCldr.locale)
          get_resource(locale)[:languages][TwitterCldr.convert_locale(code)]
        rescue
          nil
        end

        def translate_language(language, source_locale = :en, dest_locale = TwitterCldr.locale)
          lang_code = get_resource(source_locale)[:languages].detect { |_, val| val.downcase == language.downcase }.first
          get_resource(dest_locale)[:languages][lang_code] if lang_code
        rescue
          nil
        end

        def is_rtl?(locale)
          locale = TwitterCldr.convert_locale(locale)
          TwitterCldr.get_locale_resource(locale, :layout)[locale][:layout][:orientation][:character_order] == "right-to-left"
        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

24 entries across 24 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/shared/languages.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/shared/languages.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.2.1 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.2.0 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.1.2 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.1.1 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.1.0 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.10 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.9 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.8 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.7 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.6 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.5 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.4 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.3 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.2 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.1 lib/twitter_cldr/shared/languages.rb
twitter_cldr-2.4.3 lib/twitter_cldr/shared/languages.rb
twitter_cldr-3.0.0 lib/twitter_cldr/shared/languages.rb