Module: TwitterCldr

Extended by:
SingleForwardable
Defined in:
lib/twitter_cldr/utils.rb,
lib/twitter_cldr.rb,
lib/twitter_cldr/shared.rb,
lib/twitter_cldr/version.rb,
lib/twitter_cldr/formatters.rb,
lib/twitter_cldr/tokenizers.rb,
lib/twitter_cldr/normalizers.rb,
lib/twitter_cldr/core_ext/array.rb,
lib/twitter_cldr/shared/numbers.rb,
lib/twitter_cldr/core_ext/string.rb,
lib/twitter_cldr/core_ext/symbol.rb,
lib/twitter_cldr/formatters/base.rb,
lib/twitter_cldr/normalizers/nfd.rb,
lib/twitter_cldr/shared/calendar.rb,
lib/twitter_cldr/tokenizers/base.rb,
lib/twitter_cldr/normalizers/nfkd.rb,
lib/twitter_cldr/shared/languages.rb,
lib/twitter_cldr/shared/resources.rb,
lib/twitter_cldr/tokenizers/token.rb,
lib/twitter_cldr/shared/currencies.rb,
lib/twitter_cldr/utils/code_points.rb,
lib/twitter_cldr/formatters/numbers.rb,
lib/twitter_cldr/formatters/plurals.rb,
lib/twitter_cldr/shared/unicode_data.rb,
lib/twitter_cldr/utils/interpolation.rb,
lib/twitter_cldr/core_ext/calendars/date.rb,
lib/twitter_cldr/core_ext/calendars/time.rb,
lib/twitter_cldr/formatters/plurals/rules.rb,
lib/twitter_cldr/core_ext/localized_object.rb,
lib/twitter_cldr/tokenizers/composite_token.rb,
lib/twitter_cldr/core_ext/calendars/datetime.rb,
lib/twitter_cldr/core_ext/calendars/timespan.rb,
lib/twitter_cldr/formatters/numbers/helpers/base.rb,
lib/twitter_cldr/core_ext/numbers/localized_number.rb,
lib/twitter_cldr/formatters/numbers/helpers/integer.rb,
lib/twitter_cldr/formatters/calendars/date_formatter.rb,
lib/twitter_cldr/formatters/calendars/time_formatter.rb,
lib/twitter_cldr/formatters/numbers/helpers/fraction.rb,
lib/twitter_cldr/formatters/numbers/number_formatter.rb,
lib/twitter_cldr/formatters/plurals/plural_formatter.rb,
lib/twitter_cldr/tokenizers/calendars/date_tokenizer.rb,
lib/twitter_cldr/tokenizers/calendars/time_tokenizer.rb,
lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb,
lib/twitter_cldr/formatters/numbers/decimal_formatter.rb,
lib/twitter_cldr/formatters/numbers/percent_formatter.rb,
lib/twitter_cldr/formatters/numbers/currency_formatter.rb,
lib/twitter_cldr/formatters/calendars/datetime_formatter.rb,
lib/twitter_cldr/formatters/calendars/timespan_formatter.rb,
lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb,
lib/twitter_cldr/tokenizers/calendars/timespan_tokenizer.rb

Overview

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Defined Under Namespace

Modules: Formatters, LocalizedNumberMixin, Normalizers, Shared, Tokenizers, Utils Classes: LocalizedArray, LocalizedDate, LocalizedDateTime, LocalizedNumber, LocalizedObject, LocalizedString, LocalizedSymbol, LocalizedTime

Constant Summary collapse

CLDR_VERSION =

version of CLDR that was used for generating YAML files in the resources/ directory

'21.0'
DEFAULT_LOCALE =

release date: 2012-02-10

:en
DEFAULT_CALENDAR_TYPE =
:gregorian
RESOURCES_DIR =
File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'resources')
TWITTER_LOCALE_MAP =

maps twitter locales to cldr locales

{
    :msa     => :ms,
    :'zh-cn' => :zh,
    :'zh-tw' => :'zh-Hant'
}
CLDR_LOCALE_MAP =

maps cldr locales to twitter locales

TWITTER_LOCALE_MAP.invert
VERSION =
"1.3.6"

Class Method Summary collapse

Class Method Details

.convert_locale(locale) ⇒ Object


69
70
71
72
# File 'lib/twitter_cldr.rb', line 69

def convert_locale(locale)
  locale = locale.to_sym
  TWITTER_LOCALE_MAP.fetch(locale, locale)
end

.get_localeObject


58
59
60
61
62
63
64
65
66
67
# File 'lib/twitter_cldr.rb', line 58

def get_locale
  if defined?(FastGettext)
    locale = FastGettext.locale
    locale = DEFAULT_LOCALE if locale.to_s.empty?
  else
    locale = DEFAULT_LOCALE
  end

  (supported_locale?(locale) ? locale : DEFAULT_LOCALE).to_sym
end

.require_jsObject


88
89
90
# File 'lib/twitter_cldr.rb', line 88

def require_js
  require "js/lib/twitter_cldr_js"
end

.resourcesObject


54
55
56
# File 'lib/twitter_cldr.rb', line 54

def resources
  @resources ||= TwitterCldr::Shared::Resources.new
end

.supported_locale?(locale) ⇒ Boolean


83
84
85
86
# File 'lib/twitter_cldr.rb', line 83

def supported_locale?(locale)
  locale = locale.to_sym
  supported_locales.include?(locale) || supported_locales.include?(convert_locale(locale))
end

.supported_localesObject


79
80
81
# File 'lib/twitter_cldr.rb', line 79

def supported_locales
  @supported_locales ||= Dir.glob(File.join(RESOURCES_DIR, 'locales', '*')).map { |f| File.basename(f).to_sym }
end

.twitter_locale(locale) ⇒ Object


74
75
76
77
# File 'lib/twitter_cldr.rb', line 74

def twitter_locale(locale)
  locale = locale.to_sym
  CLDR_LOCALE_MAP.fetch(locale, locale)
end