Module: TwitterCldr
- Extended by:
- SingleForwardable
- Defined in:
- lib/twitter_cldr/utils.rb,
lib/twitter_cldr.rb,
lib/twitter_cldr/shared.rb,
lib/twitter_cldr/parsers.rb,
lib/twitter_cldr/version.rb,
lib/twitter_cldr/versions.rb,
lib/twitter_cldr/collation.rb,
lib/twitter_cldr/localized.rb,
lib/twitter_cldr/resources.rb,
lib/twitter_cldr/timezones.rb,
lib/twitter_cldr/formatters.rb,
lib/twitter_cldr/tokenizers.rb,
lib/twitter_cldr/transforms.rb,
lib/twitter_cldr/utils/trie.rb,
lib/twitter_cldr/utils/yaml.rb,
lib/twitter_cldr/shared/bidi.rb,
lib/twitter_cldr/shared/unit.rb,
lib/twitter_cldr/data_readers.rb,
lib/twitter_cldr/segmentation.rb,
lib/twitter_cldr/shared/caser.rb,
lib/twitter_cldr/normalization.rb,
lib/twitter_cldr/shared/locale.rb,
lib/twitter_cldr/parsers/parser.rb,
lib/twitter_cldr/shared/numbers.rb,
lib/twitter_cldr/shared/calendar.rb,
lib/twitter_cldr/transforms/rule.rb,
lib/twitter_cldr/utils/range_set.rb,
lib/twitter_cldr/resources/loader.rb,
lib/twitter_cldr/shared/languages.rb,
lib/twitter_cldr/shared/territory.rb,
lib/twitter_cldr/tokenizers/token.rb,
lib/twitter_cldr/utils/regexp_ast.rb,
lib/twitter_cldr/shared/casefolder.rb,
lib/twitter_cldr/shared/code_point.rb,
lib/twitter_cldr/shared/currencies.rb,
lib/twitter_cldr/shared/hyphenator.rb,
lib/twitter_cldr/shared/properties.rb,
lib/twitter_cldr/supported_locales.rb,
lib/twitter_cldr/transforms/cursor.rb,
lib/twitter_cldr/utils/code_points.rb,
lib/twitter_cldr/collation/collator.rb,
lib/twitter_cldr/formatters/numbers.rb,
lib/twitter_cldr/formatters/plurals.rb,
lib/twitter_cldr/resources/cldr_dtd.rb,
lib/twitter_cldr/resources/importer.rb,
lib/twitter_cldr/shared/day_periods.rb,
lib/twitter_cldr/shared/territories.rb,
lib/twitter_cldr/shared/unicode_set.rb,
lib/twitter_cldr/timezones/location.rb,
lib/twitter_cldr/timezones/timezone.rb,
lib/twitter_cldr/transforms/filters.rb,
lib/twitter_cldr/segmentation/cursor.rb,
lib/twitter_cldr/shared/postal_codes.rb,
lib/twitter_cldr/shared/property_set.rb,
lib/twitter_cldr/timezones/zone_meta.rb,
lib/twitter_cldr/transforms/rule_set.rb,
lib/twitter_cldr/formatters/formatter.rb,
lib/twitter_cldr/parsers/symbol_table.rb,
lib/twitter_cldr/resources/properties.rb,
lib/twitter_cldr/shared/unicode_regex.rb,
lib/twitter_cldr/tokenizers/tokenizer.rb,
lib/twitter_cldr/transforms/tokenizer.rb,
lib/twitter_cldr/utils/regexp_sampler.rb,
lib/twitter_cldr/collation/trie_loader.rb,
lib/twitter_cldr/parsers/number_parser.rb,
lib/twitter_cldr/resources/cldr_locale.rb,
lib/twitter_cldr/segmentation/metadata.rb,
lib/twitter_cldr/segmentation/rule_set.rb,
lib/twitter_cldr/shared/language_codes.rb,
lib/twitter_cldr/shared/likely_subtags.rb,
lib/twitter_cldr/transforms/rule_match.rb,
lib/twitter_cldr/transforms/transforms.rb,
lib/twitter_cldr/utils/script_detector.rb,
lib/twitter_cldr/collation/trie_builder.rb,
lib/twitter_cldr/resources/requirements.rb,
lib/twitter_cldr/timezones/gmt_location.rb,
lib/twitter_cldr/transforms/conversions.rb,
lib/twitter_cldr/transforms/transformer.rb,
lib/twitter_cldr/utils/file_system_trie.rb,
lib/twitter_cldr/formatters/numbers/rbnf.rb,
lib/twitter_cldr/segmentation/dictionary.rb,
lib/twitter_cldr/shared/numbering_system.rb,
lib/twitter_cldr/transforms/comment_rule.rb,
lib/twitter_cldr/transforms/transform_id.rb,
lib/twitter_cldr/data_readers/data_reader.rb,
lib/twitter_cldr/formatters/plurals/rules.rb,
lib/twitter_cldr/localized/localized_date.rb,
lib/twitter_cldr/localized/localized_hash.rb,
lib/twitter_cldr/localized/localized_time.rb,
lib/twitter_cldr/resources/units_importer.rb,
lib/twitter_cldr/segmentation/state_table.rb,
lib/twitter_cldr/transforms/variable_rule.rb,
lib/twitter_cldr/formatters/list_formatter.rb,
lib/twitter_cldr/localized/localized_array.rb,
lib/twitter_cldr/resources/import_resolver.rb,
lib/twitter_cldr/resources/readme_renderer.rb,
lib/twitter_cldr/segmentation/status_table.rb,
lib/twitter_cldr/segmentation/suppressions.rb,
lib/twitter_cldr/transforms/transliterator.rb,
lib/twitter_cldr/collation/sort_key_builder.rb,
lib/twitter_cldr/localized/localized_number.rb,
lib/twitter_cldr/localized/localized_object.rb,
lib/twitter_cldr/localized/localized_string.rb,
lib/twitter_cldr/localized/localized_symbol.rb,
lib/twitter_cldr/resources/aliases_importer.rb,
lib/twitter_cldr/segmentation/possible_word.rb,
lib/twitter_cldr/segmentation/state_machine.rb,
lib/twitter_cldr/segmentation/word_iterator.rb,
lib/twitter_cldr/shared/properties_database.rb,
lib/twitter_cldr/shared/property_normalizer.rb,
lib/twitter_cldr/timezones/generic_location.rb,
lib/twitter_cldr/timezones/iso8601_location.rb,
lib/twitter_cldr/resources/cldr_data_builder.rb,
lib/twitter_cldr/resources/cldr_document_set.rb,
lib/twitter_cldr/segmentation/break_iterator.rb,
lib/twitter_cldr/segmentation/category_table.rb,
lib/twitter_cldr/transforms/conversions/side.rb,
lib/twitter_cldr/collation/trie_with_fallback.rb,
lib/twitter_cldr/formatters/numbers/rbnf/rule.rb,
lib/twitter_cldr/localized/localized_datetime.rb,
lib/twitter_cldr/localized/localized_timespan.rb,
lib/twitter_cldr/parsers/unicode_regex_parser.rb,
lib/twitter_cldr/resources/bidi_test_importer.rb,
lib/twitter_cldr/resources/calendars_importer.rb,
lib/twitter_cldr/resources/rbnf_test_importer.rb,
lib/twitter_cldr/resources/tailoring_importer.rb,
lib/twitter_cldr/resources/timezones_importer.rb,
lib/twitter_cldr/segmentation/cj_break_engine.rb,
lib/twitter_cldr/shared/postal_code_generator.rb,
lib/twitter_cldr/shared/property_name_aliases.rb,
lib/twitter_cldr/tokenizers/pattern_tokenizer.rb,
lib/twitter_cldr/transforms/filtered_rule_set.rb,
lib/twitter_cldr/transforms/transforms/parser.rb,
lib/twitter_cldr/data_readers/date_data_reader.rb,
lib/twitter_cldr/data_readers/time_data_reader.rb,
lib/twitter_cldr/parsers/unicode_regex/literal.rb,
lib/twitter_cldr/resources/transforms_importer.rb,
lib/twitter_cldr/resources/unicode_file_parser.rb,
lib/twitter_cldr/segmentation/lao_break_engine.rb,
lib/twitter_cldr/segmentation/segment_iterator.rb,
lib/twitter_cldr/shared/property_value_aliases.rb,
lib/twitter_cldr/transforms/conversions/parser.rb,
lib/twitter_cldr/formatters/numbers/rbnf/plural.rb,
lib/twitter_cldr/resources/hyphenation_importer.rb,
lib/twitter_cldr/resources/regexp_ast_generator.rb,
lib/twitter_cldr/resources/territories_importer.rb,
lib/twitter_cldr/segmentation/null_suppressions.rb,
lib/twitter_cldr/segmentation/thai_break_engine.rb,
lib/twitter_cldr/shared/territories_containment.rb,
lib/twitter_cldr/transforms/conversion_rule_set.rb,
lib/twitter_cldr/transforms/filters/filter_rule.rb,
lib/twitter_cldr/transforms/filters/null_filter.rb,
lib/twitter_cldr/data_readers/number_data_reader.rb,
lib/twitter_cldr/formatters/numbers/helpers/base.rb,
lib/twitter_cldr/parsers/unicode_regex/component.rb,
lib/twitter_cldr/resources/list_formats_importer.rb,
lib/twitter_cldr/resources/postal_codes_importer.rb,
lib/twitter_cldr/resources/unicode_data_importer.rb,
lib/twitter_cldr/segmentation/khmer_break_engine.rb,
lib/twitter_cldr/segmentation/possible_word_list.rb,
lib/twitter_cldr/shared/properties/bidi_brackets.rb,
lib/twitter_cldr/formatters/numbers/rbnf/rule_set.rb,
lib/twitter_cldr/resources/segment_rules_importer.rb,
lib/twitter_cldr/resources/segment_tests_importer.rb,
lib/twitter_cldr/resources/validity_data_importer.rb,
lib/twitter_cldr/segmentation/korean_break_engine.rb,
lib/twitter_cldr/shared/properties/arabic_shaping.rb,
lib/twitter_cldr/data_readers/calendar_data_reader.rb,
lib/twitter_cldr/data_readers/timespan_data_reader.rb,
lib/twitter_cldr/resources/language_codes_importer.rb,
lib/twitter_cldr/resources/number_formats_importer.rb,
lib/twitter_cldr/resources/parent_locales_importer.rb,
lib/twitter_cldr/resources/timezone_tests_importer.rb,
lib/twitter_cldr/segmentation/brahmic_break_engine.rb,
lib/twitter_cldr/segmentation/burmese_break_engine.rb,
lib/twitter_cldr/tokenizers/numbers/rbnf_tokenizer.rb,
lib/twitter_cldr/transforms/filters/unicode_filter.rb,
lib/twitter_cldr/data_readers/date_time_data_reader.rb,
lib/twitter_cldr/formatters/numbers/helpers/integer.rb,
lib/twitter_cldr/formatters/numbers/rbnf/formatters.rb,
lib/twitter_cldr/formatters/numbers/rbnf/rule_group.rb,
lib/twitter_cldr/resources/collation_tests_importer.rb,
lib/twitter_cldr/resources/collation_tries_importer.rb,
lib/twitter_cldr/resources/requirements/pom_manager.rb,
lib/twitter_cldr/resources/transform_tests_importer.rb,
lib/twitter_cldr/formatters/numbers/helpers/fraction.rb,
lib/twitter_cldr/formatters/numbers/number_formatter.rb,
lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb,
lib/twitter_cldr/formatters/plurals/plural_formatter.rb,
lib/twitter_cldr/parsers/unicode_regex/character_set.rb,
lib/twitter_cldr/resources/currency_symbols_importer.rb,
lib/twitter_cldr/resources/day_period_rules_importer.rb,
lib/twitter_cldr/resources/properties/emoji_importer.rb,
lib/twitter_cldr/resources/timezone_regions_importer.rb,
lib/twitter_cldr/segmentation/unhandled_break_engine.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/rbnf/substitution.rb,
lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb,
lib/twitter_cldr/resources/casefolder_class_generator.rb,
lib/twitter_cldr/resources/locales_resources_importer.rb,
lib/twitter_cldr/segmentation/dictionary_break_engine.rb,
lib/twitter_cldr/transforms/transforms/null_transform.rb,
lib/twitter_cldr/transforms/transforms/transform_pair.rb,
lib/twitter_cldr/transforms/transforms/transform_rule.rb,
lib/twitter_cldr/collation/implicit_collation_elements.rb,
lib/twitter_cldr/formatters/numbers/currency_formatter.rb,
lib/twitter_cldr/parsers/unicode_regex/character_class.rb,
lib/twitter_cldr/parsers/unicode_regex/character_range.rb,
lib/twitter_cldr/transforms/transforms/blank_transform.rb,
lib/twitter_cldr/transforms/transforms/named_transform.rb,
lib/twitter_cldr/resources/properties/property_importer.rb,
lib/twitter_cldr/resources/requirements/git_requirement.rb,
lib/twitter_cldr/resources/requirements/icu_requirement.rb,
lib/twitter_cldr/resources/requirements/uca_requirement.rb,
lib/twitter_cldr/transforms/conversions/conversion_rule.rb,
lib/twitter_cldr/transforms/transforms/casing_transform.rb,
lib/twitter_cldr/formatters/calendars/timespan_formatter.rb,
lib/twitter_cldr/resources/properties/prop_list_importer.rb,
lib/twitter_cldr/resources/requirements/cldr_requirement.rb,
lib/twitter_cldr/resources/segment_dictionaries_importer.rb,
lib/twitter_cldr/tokenizers/calendars/timespan_tokenizer.rb,
lib/twitter_cldr/formatters/calendars/date_time_formatter.rb,
lib/twitter_cldr/resources/requirements/emoji_requirement.rb,
lib/twitter_cldr/tokenizers/calendars/date_time_tokenizer.rb,
lib/twitter_cldr/resources/bcp47_timezone_metadata_importer.rb,
lib/twitter_cldr/resources/properties/age_property_importer.rb,
lib/twitter_cldr/resources/requirements/unicode_requirement.rb,
lib/twitter_cldr/resources/properties/jamo_property_importer.rb,
lib/twitter_cldr/resources/unicode_property_aliases_importer.rb,
lib/twitter_cldr/data_readers/additional_date_format_selector.rb,
lib/twitter_cldr/resources/properties/blocks_property_importer.rb,
lib/twitter_cldr/resources/properties/script_property_importer.rb,
lib/twitter_cldr/resources/requirements/dependency_requirement.rb,
lib/twitter_cldr/transforms/transforms/normalization_transform.rb,
lib/twitter_cldr/transforms/transforms/break_internal_transform.rb,
lib/twitter_cldr/tokenizers/unicode_regex/unicode_regex_tokenizer.rb,
lib/twitter_cldr/resources/properties/line_break_property_importer.rb,
lib/twitter_cldr/resources/properties/word_break_property_importer.rb,
lib/twitter_cldr/resources/properties/bidi_brackets_property_importer.rb,
lib/twitter_cldr/resources/properties/arabic_shaping_property_importer.rb,
lib/twitter_cldr/resources/properties/derived_core_properties_importer.rb,
lib/twitter_cldr/resources/properties/grapheme_break_property_importer.rb,
lib/twitter_cldr/resources/properties/sentence_break_property_importer.rb,
lib/twitter_cldr/resources/properties/unicode_data_properties_importer.rb,
lib/twitter_cldr/resources/properties/east_asian_width_property_importer.rb,
lib/twitter_cldr/resources/properties/script_extensions_property_importer.rb,
lib/twitter_cldr/resources/properties/hangul_syllable_type_property_importer.rb,
lib/twitter_cldr/resources/properties/indic_syllabic_category_property_importer.rb,
lib/twitter_cldr/resources/properties/indic_positional_category_property_importer.rb
Overview
Defined Under Namespace
Modules: Collation, DataReaders, Formatters, Localized, Normalization, Parsers, Resources, Segmentation, Shared, Timezones, Tokenizers, Transforms, Utils, Versions
Constant Summary
collapse
- DEFAULT_LOCALE =
:en
- DEFAULT_CALENDAR_TYPE =
:gregorian
- RESOURCES_DIR =
File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'resources')
- VENDOR_DIR =
File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'vendor')
- LIB_DIR =
File.dirname(File.expand_path(__FILE__))
- SPEC_DIR =
File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'spec')
{
msa: :ms,
'zh-cn': :zh,
'zh-tw': :'zh-Hant',
no: :nb
}
- CLDR_LOCALE_MAP =
maps cldr locales to twitter locales
TWITTER_LOCALE_MAP.invert
- VERSION =
'6.12.1'
- SUPPORTED_LOCALES_FILE =
File.expand_path('../../resources/supported_locales.yml', __dir__)
- SUPPORTED_LOCALES =
YAML.load_file(SUPPORTED_LOCALES_FILE).freeze
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.disable_custom_locale_resources ⇒ Object
Returns the value of attribute disable_custom_locale_resources.
66
67
68
|
# File 'lib/twitter_cldr.rb', line 66
def disable_custom_locale_resources
@disable_custom_locale_resources
end
|
.locale ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/twitter_cldr.rb', line 72
def locale
locale = supported_locale?(@locale) ? @locale : find_fallback
locale = DEFAULT_LOCALE if locale.to_s.empty?
(supported_locale?(locale) ? locale : DEFAULT_LOCALE).to_sym
end
|
Class Method Details
.convert_locale(locale) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/twitter_cldr.rb', line 113
def convert_locale(locale)
locale = normalize_locale(locale)
unless supported_locale?(locale)
loc = TwitterCldr::Shared::Locale.parse(locale)
max_supported = loc.max_supported
if loc.dasherized == 'und' || !max_supported
return locale
end
locale = normalize_locale(max_supported.dasherized)
end
locale
end
|
.locale_fallbacks ⇒ Object
109
110
111
|
# File 'lib/twitter_cldr.rb', line 109
def locale_fallbacks
@locale_fallbacks ||= []
end
|
.normalize_locale(locale) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/twitter_cldr.rb', line 130
def normalize_locale(locale)
return locale unless (locale.is_a?(String) || locale.is_a?(Symbol))
locale = locale.to_sym
locale = lowercase_locales_map.fetch(locale, locale)
TWITTER_LOCALE_MAP.fetch(locale.downcase, locale)
end
|
.register_locale_fallback(proc_or_locale) ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'lib/twitter_cldr.rb', line 93
def register_locale_fallback(proc_or_locale)
case proc_or_locale
when Symbol, String, Proc
locale_fallbacks << proc_or_locale
else
raise "A locale fallback must be of type String, Symbol, or Proc."
end
nil
end
|
.reset_locale_fallbacks ⇒ Object
.supported_locale?(locale) ⇒ Boolean
147
148
149
|
# File 'lib/twitter_cldr.rb', line 147
def supported_locale?(locale)
!!locale && supported_locales.include?(normalize_locale(locale))
end
|
.supported_locales ⇒ Object
138
139
140
141
|
# File 'lib/twitter_cldr.rb', line 138
def (locale)
locale = locale.to_sym
CLDR_LOCALE_MAP.fetch(locale, locale)
end
|
.with_locale(locale) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/twitter_cldr.rb', line 80
def with_locale(locale)
raise "Unsupported locale" unless supported_locale?(locale)
begin
old_locale = @locale
@locale = locale
result = yield
ensure
@locale = old_locale
result
end
end
|