twitter_cldr 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +177 -0
- data/NOTICE +26 -0
- data/README.md +83 -0
- data/Rakefile +36 -0
- data/lib/ext/calendars/date.rb +20 -0
- data/lib/ext/calendars/datetime.rb +36 -0
- data/lib/ext/calendars/time.rb +20 -0
- data/lib/ext/localized_object.rb +15 -0
- data/lib/ext/numbers/bignum.rb +3 -0
- data/lib/ext/numbers/fixnum.rb +3 -0
- data/lib/ext/numbers/float.rb +3 -0
- data/lib/ext/numbers/localized_number.rb +53 -0
- data/lib/ext/strings/symbol.rb +17 -0
- data/lib/formatters/base.rb +36 -0
- data/lib/formatters/calendars/date_formatter.rb +9 -0
- data/lib/formatters/calendars/datetime_formatter.rb +217 -0
- data/lib/formatters/calendars/time_formatter.rb +9 -0
- data/lib/formatters/numbers/currency_formatter.rb +25 -0
- data/lib/formatters/numbers/decimal_formatter.rb +22 -0
- data/lib/formatters/numbers/helpers/base.rb +18 -0
- data/lib/formatters/numbers/helpers/fraction.rb +29 -0
- data/lib/formatters/numbers/helpers/integer.rb +46 -0
- data/lib/formatters/numbers/number_formatter.rb +48 -0
- data/lib/formatters/numbers/percent_formatter.rb +18 -0
- data/lib/formatters/plurals/rules.rb +34 -0
- data/lib/shared/currencies.rb +33 -0
- data/lib/shared/languages.rb +48 -0
- data/lib/shared/resources.rb +45 -0
- data/lib/shared/timezones.rb +1 -0
- data/lib/tokenizers/base.rb +112 -0
- data/lib/tokenizers/calendars/date_tokenizer.rb +24 -0
- data/lib/tokenizers/calendars/datetime_tokenizer.rb +46 -0
- data/lib/tokenizers/calendars/time_tokenizer.rb +24 -0
- data/lib/tokenizers/key_path.rb +30 -0
- data/lib/tokenizers/numbers/number_tokenizer.rb +50 -0
- data/lib/tokenizers/token.rb +17 -0
- data/lib/twitter_cldr.rb +104 -0
- data/lib/version.rb +3 -0
- data/resources/ar/calendars.yml +145 -0
- data/resources/ar/languages.yml +498 -0
- data/resources/ar/numbers.yml +35 -0
- data/resources/ar/plurals.yml +1 -0
- data/resources/da/calendars.yml +157 -0
- data/resources/da/languages.yml +508 -0
- data/resources/da/numbers.yml +31 -0
- data/resources/da/plurals.yml +1 -0
- data/resources/de/calendars.yml +152 -0
- data/resources/de/languages.yml +508 -0
- data/resources/de/numbers.yml +31 -0
- data/resources/de/plurals.yml +1 -0
- data/resources/en/calendars.yml +145 -0
- data/resources/en/languages.yml +510 -0
- data/resources/en/numbers.yml +31 -0
- data/resources/en/plurals.yml +1 -0
- data/resources/es/calendars.yml +145 -0
- data/resources/es/languages.yml +508 -0
- data/resources/es/numbers.yml +30 -0
- data/resources/es/plurals.yml +1 -0
- data/resources/fa/calendars.yml +150 -0
- data/resources/fa/languages.yml +484 -0
- data/resources/fa/numbers.yml +30 -0
- data/resources/fa/plurals.yml +1 -0
- data/resources/fi/calendars.yml +176 -0
- data/resources/fi/languages.yml +508 -0
- data/resources/fi/numbers.yml +31 -0
- data/resources/fi/plurals.yml +1 -0
- data/resources/fil/calendars.yml +159 -0
- data/resources/fil/languages.yml +115 -0
- data/resources/fil/numbers.yml +31 -0
- data/resources/fil/plurals.yml +1 -0
- data/resources/fr/calendars.yml +149 -0
- data/resources/fr/languages.yml +508 -0
- data/resources/fr/numbers.yml +31 -0
- data/resources/fr/plurals.yml +1 -0
- data/resources/he/calendars.yml +145 -0
- data/resources/he/languages.yml +266 -0
- data/resources/he/numbers.yml +31 -0
- data/resources/he/plurals.yml +1 -0
- data/resources/hi/calendars.yml +144 -0
- data/resources/hi/languages.yml +505 -0
- data/resources/hi/numbers.yml +31 -0
- data/resources/hi/plurals.yml +1 -0
- data/resources/hu/calendars.yml +145 -0
- data/resources/hu/languages.yml +508 -0
- data/resources/hu/numbers.yml +30 -0
- data/resources/hu/plurals.yml +1 -0
- data/resources/id/calendars.yml +145 -0
- data/resources/id/languages.yml +506 -0
- data/resources/id/numbers.yml +30 -0
- data/resources/id/plurals.yml +1 -0
- data/resources/it/calendars.yml +164 -0
- data/resources/it/languages.yml +503 -0
- data/resources/it/numbers.yml +30 -0
- data/resources/it/plurals.yml +1 -0
- data/resources/ja/calendars.yml +157 -0
- data/resources/ja/languages.yml +502 -0
- data/resources/ja/numbers.yml +30 -0
- data/resources/ja/plurals.yml +1 -0
- data/resources/ko/calendars.yml +133 -0
- data/resources/ko/languages.yml +505 -0
- data/resources/ko/numbers.yml +30 -0
- data/resources/ko/plurals.yml +1 -0
- data/resources/ms/calendars.yml +145 -0
- data/resources/ms/languages.yml +54 -0
- data/resources/ms/numbers.yml +30 -0
- data/resources/ms/plurals.yml +1 -0
- data/resources/nl/calendars.yml +145 -0
- data/resources/nl/languages.yml +508 -0
- data/resources/nl/numbers.yml +31 -0
- data/resources/nl/plurals.yml +1 -0
- data/resources/no/calendars.yml +122 -0
- data/resources/no/languages.yml +508 -0
- data/resources/no/numbers.yml +30 -0
- data/resources/no/plurals.yml +1 -0
- data/resources/pl/calendars.yml +161 -0
- data/resources/pl/languages.yml +504 -0
- data/resources/pl/numbers.yml +31 -0
- data/resources/pl/plurals.yml +1 -0
- data/resources/pt/calendars.yml +145 -0
- data/resources/pt/languages.yml +508 -0
- data/resources/pt/numbers.yml +31 -0
- data/resources/pt/plurals.yml +1 -0
- data/resources/ru/calendars.yml +176 -0
- data/resources/ru/languages.yml +508 -0
- data/resources/ru/numbers.yml +30 -0
- data/resources/ru/plurals.yml +1 -0
- data/resources/shared/currencies.yml +451 -0
- data/resources/sv/calendars.yml +145 -0
- data/resources/sv/languages.yml +508 -0
- data/resources/sv/numbers.yml +31 -0
- data/resources/sv/plurals.yml +1 -0
- data/resources/th/calendars.yml +145 -0
- data/resources/th/languages.yml +507 -0
- data/resources/th/numbers.yml +30 -0
- data/resources/th/plurals.yml +1 -0
- data/resources/tr/calendars.yml +145 -0
- data/resources/tr/languages.yml +508 -0
- data/resources/tr/numbers.yml +30 -0
- data/resources/tr/plurals.yml +1 -0
- data/resources/ur/calendars.yml +133 -0
- data/resources/ur/languages.yml +81 -0
- data/resources/ur/numbers.yml +31 -0
- data/resources/ur/plurals.yml +1 -0
- data/resources/zh/calendars.yml +169 -0
- data/resources/zh/languages.yml +506 -0
- data/resources/zh/numbers.yml +30 -0
- data/resources/zh/plurals.yml +1 -0
- data/resources/zh-Hant/calendars.yml +141 -0
- data/resources/zh-Hant/languages.yml +409 -0
- data/resources/zh-Hant/numbers.yml +30 -0
- data/spec/ext/calendars/date_spec.rb +45 -0
- data/spec/ext/calendars/datetime_spec.rb +43 -0
- data/spec/ext/calendars/time_spec.rb +45 -0
- data/spec/ext/numbers/bignum_spec.rb +19 -0
- data/spec/ext/numbers/fixnum_spec.rb +19 -0
- data/spec/ext/numbers/float_spec.rb +19 -0
- data/spec/ext/numbers/localized_number_spec.rb +53 -0
- data/spec/ext/strings/symbol_spec.rb +23 -0
- data/spec/formatters/base_spec.rb +12 -0
- data/spec/formatters/calendars/datetime_formatter_spec.rb +324 -0
- data/spec/formatters/numbers/currency_formatter_spec.rb +27 -0
- data/spec/formatters/numbers/decimal_formatter_spec.rb +30 -0
- data/spec/formatters/numbers/helpers/fraction_spec.rb +22 -0
- data/spec/formatters/numbers/helpers/integer_spec.rb +99 -0
- data/spec/formatters/numbers/number_formatter_spec.rb +79 -0
- data/spec/formatters/numbers/percent_formatter_spec.rb +12 -0
- data/spec/formatters/plurals/rules_spec.rb +73 -0
- data/spec/shared/currencies_spec.rb +55 -0
- data/spec/shared/languages_spec.rb +82 -0
- data/spec/shared/resources_spec.rb +44 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/tokenizers/base_spec.rb +134 -0
- data/spec/tokenizers/calendars/date_tokenizer_spec.rb +36 -0
- data/spec/tokenizers/calendars/datetime_tokenizer_spec.rb +52 -0
- data/spec/tokenizers/calendars/time_tokenizer_spec.rb +34 -0
- data/spec/tokenizers/key_path_spec.rb +44 -0
- data/spec/tokenizers/numbers/number_tokenizer_spec.rb +60 -0
- data/spec/tokenizers/token_spec.rb +18 -0
- data/spec/twitter_cldr_spec.rb +53 -0
- metadata +293 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Tokenizers
|
3
|
+
class Base
|
4
|
+
attr_reader :resource, :locale
|
5
|
+
attr_reader :token_splitter_regex, :token_type_regexes, :paths
|
6
|
+
attr_accessor :type, :placeholders
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@locale = (options[:locale] || TwitterCldr::DEFAULT_LOCALE).to_sym
|
10
|
+
self.init_resources
|
11
|
+
self.init_placeholders
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# Not to be confused with tokenize_pattern, which pulls out placeholders. Tokenize_format actually splits a completely
|
17
|
+
# expanded format string into whatever parts are defined by the subclass's token type and token splitter regexes.
|
18
|
+
def tokenize_format(text)
|
19
|
+
final = []
|
20
|
+
text.split(self.token_splitter_regex).each_with_index do |token, index|
|
21
|
+
unless index == 0 && token == ""
|
22
|
+
self.token_type_regexes.each do |token_type|
|
23
|
+
if token =~ token_type[:regex]
|
24
|
+
final << Token.new(:value => token, :type => token_type[:type])
|
25
|
+
break
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
final
|
31
|
+
end
|
32
|
+
|
33
|
+
def tokens_for(key, type)
|
34
|
+
final = []
|
35
|
+
tokens = self.expand_pattern(self.pattern_for(self.traverse(key)), type)
|
36
|
+
|
37
|
+
tokens.each do |token|
|
38
|
+
if token.is_a?(Token)
|
39
|
+
final << token
|
40
|
+
else
|
41
|
+
final += tokenize_format(token[:value])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
final
|
46
|
+
end
|
47
|
+
|
48
|
+
def init_placeholders
|
49
|
+
@placeholders = {}
|
50
|
+
end
|
51
|
+
|
52
|
+
def traverse(needle, haystack = @resource)
|
53
|
+
segments = needle.to_s.split(".")
|
54
|
+
final = haystack
|
55
|
+
segments.each { |segment| final = final[segment.to_sym] }
|
56
|
+
final
|
57
|
+
rescue NameError
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def expand_pattern(format_str, type)
|
62
|
+
if format_str.is_a?(Symbol)
|
63
|
+
# symbols mean another path was given
|
64
|
+
self.expand_pattern(self.pattern_for(self.traverse(format_str)), type)
|
65
|
+
else
|
66
|
+
parts = tokenize_pattern(format_str)
|
67
|
+
final = []
|
68
|
+
|
69
|
+
parts.each do |part|
|
70
|
+
case part[:type]
|
71
|
+
when :placeholder then
|
72
|
+
placeholder = self.choose_placeholder(part[:value], @placeholders)
|
73
|
+
final += placeholder ? placeholder.tokens(:type => type) : []
|
74
|
+
else
|
75
|
+
final << part
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
final
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Tokenize_pattern is supposed to take a pattern found in the YAML resource files and break it into placeholders and plaintext.
|
84
|
+
# Placeholders are delimited by single and double curly braces, plaintext is everything else.
|
85
|
+
def tokenize_pattern(pattern_str)
|
86
|
+
results = []
|
87
|
+
pattern_str.split(/(\{\{?\w*\}?\}|\'\w+\')/).each do |piece|
|
88
|
+
unless piece.empty?
|
89
|
+
case piece[0].chr
|
90
|
+
when "{"
|
91
|
+
results << { :value => piece, :type => :placeholder }
|
92
|
+
else
|
93
|
+
results << { :value => piece, :type => :plaintext }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
results
|
98
|
+
end
|
99
|
+
|
100
|
+
def choose_placeholder(token, placeholders)
|
101
|
+
if token[0..1] == "{{"
|
102
|
+
token_value = token[2..-3]
|
103
|
+
found = placeholders.find { |placeholder| placeholder[:name].to_s == token_value }
|
104
|
+
else
|
105
|
+
found = placeholders[token[1..-2].to_i]
|
106
|
+
end
|
107
|
+
|
108
|
+
found ? found[:object] : nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Tokenizers
|
3
|
+
class DateTokenizer < TwitterCldr::Tokenizers::DateTimeTokenizer
|
4
|
+
def initialize(options = {})
|
5
|
+
super(options)
|
6
|
+
@token_splitter_regex = /(\s*\'[\w\s-]+\'\s*|G{1,5}|y+|Y+|Q{1,4}|q{1,5}|M{1,5}|L{1,5}|d{1,2}|F{1}|E{1,5}|e{1,5}|c{1,5})/
|
7
|
+
@token_type_regexes = [{ :type => :pattern, :regex => /^(?:G{1,5}|y+|Y+|Q{1,4}|q{1,5}|M{1,5}|L{1,5}|d{1,2}|F{1}|E{1,5}|e{1,5}|c{1,5})/ },
|
8
|
+
{ :type => :plaintext, :regex => // }]
|
9
|
+
@paths = { :default => "calendars.gregorian.formats.date.default",
|
10
|
+
:full => "calendars.gregorian.formats.date.full",
|
11
|
+
:long => "calendars.gregorian.formats.date.long",
|
12
|
+
:medium => "calendars.gregorian.formats.date.medium",
|
13
|
+
:short => "calendars.gregorian.formats.date.short" }
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
# must override this because DateTimeTokenizer will set them otherwise
|
19
|
+
def init_placeholders
|
20
|
+
@placeholders = {}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Tokenizers
|
3
|
+
class DateTimeTokenizer < Base
|
4
|
+
attr_reader :placeholders, :calendar_type
|
5
|
+
|
6
|
+
DEFAULT_CALENDAR_TYPE = :gregorian
|
7
|
+
VALID_TYPES = [:default, :full, :long, :medium, :short]
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
super(options)
|
11
|
+
@calendar_type = options[:calendar_type] || DEFAULT_CALENDAR_TYPE
|
12
|
+
@token_splitter_regex = //
|
13
|
+
@token_type_regexes = [{ :type => :plaintext, :regex => // }]
|
14
|
+
@paths = { :default => "calendars.gregorian.formats.datetime.default",
|
15
|
+
:full => "calendars.gregorian.formats.datetime.full",
|
16
|
+
:long => "calendars.gregorian.formats.datetime.long",
|
17
|
+
:medium => "calendars.gregorian.formats.datetime.medium",
|
18
|
+
:short => "calendars.gregorian.formats.datetime.short" }
|
19
|
+
end
|
20
|
+
|
21
|
+
def tokens(options = {})
|
22
|
+
type = options[:type] || :default
|
23
|
+
self.tokens_for(self.paths[type], type)
|
24
|
+
end
|
25
|
+
|
26
|
+
def calendar
|
27
|
+
@resource[:calendars][@calendar_type]
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def init_resources
|
33
|
+
@resource = TwitterCldr.resources.resource_for(@locale, "calendars")[TwitterCldr.convert_locale(@locale)]
|
34
|
+
end
|
35
|
+
|
36
|
+
def init_placeholders
|
37
|
+
@placeholders = [{ :name => :date, :object => TwitterCldr::Tokenizers::DateTokenizer.new(:locale => @locale) },
|
38
|
+
{ :name => :time, :object => TwitterCldr::Tokenizers::TimeTokenizer.new(:locale => @locale) }]
|
39
|
+
end
|
40
|
+
|
41
|
+
def pattern_for(resource)
|
42
|
+
resource.is_a?(Hash) ? resource[:pattern] : resource
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Tokenizers
|
3
|
+
class TimeTokenizer < TwitterCldr::Tokenizers::DateTimeTokenizer
|
4
|
+
def initialize(options = {})
|
5
|
+
super(options)
|
6
|
+
@token_splitter_regex = /(\'[\w\s-]+\'|a{1}|h{1,2}|H{1,2}|K{1,2}|k{1,2}|m{1,2}|s{1,2}|S+|z{1,4}|Z{1,4})/
|
7
|
+
@token_type_regexes = [{ :type => :pattern, :regex => /^a{1}|h{1,2}|H{1,2}|K{1,2}|k{1,2}|m{1,2}|s{1,2}|S+|z{1,4}|Z{1,4}/ },
|
8
|
+
{ :type => :plaintext, :regex => // }]
|
9
|
+
@paths = { :default => "calendars.gregorian.formats.time.default",
|
10
|
+
:full => "calendars.gregorian.formats.time.full",
|
11
|
+
:long => "calendars.gregorian.formats.time.long",
|
12
|
+
:medium => "calendars.gregorian.formats.time.medium",
|
13
|
+
:short => "calendars.gregorian.formats.time.short" }
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
# must override this because DateTimeTokenizer will set them otherwise
|
19
|
+
def init_placeholders
|
20
|
+
@placeholders = {}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Tokenizers
|
3
|
+
class KeyPath
|
4
|
+
class << self
|
5
|
+
def dirname(path)
|
6
|
+
self.join_path(self.split_path(path)[0..-2])
|
7
|
+
end
|
8
|
+
|
9
|
+
def join(*args)
|
10
|
+
final = ""
|
11
|
+
args.each do |arg|
|
12
|
+
fixed_arg = arg.chomp(".")
|
13
|
+
fixed_arg = arg[1..-1] if fixed_arg[0].chr == "."
|
14
|
+
final << "." if final.size > 0
|
15
|
+
final << fixed_arg
|
16
|
+
end
|
17
|
+
final
|
18
|
+
end
|
19
|
+
|
20
|
+
def split_path(path)
|
21
|
+
path.split(/\./)
|
22
|
+
end
|
23
|
+
|
24
|
+
def join_path(path_arr)
|
25
|
+
path_arr.join(".")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Tokenizers
|
3
|
+
class NumberTokenizer < Base
|
4
|
+
def initialize(options = {})
|
5
|
+
super(options)
|
6
|
+
@type = options[:type] || :decimal
|
7
|
+
@token_splitter_regex = /([^0*#,\.]*)([0#,\.]+)([^0*#,\.]*)$/
|
8
|
+
@token_type_regexes = [{ :type => :pattern, :regex => /[0?#,\.]*/ },
|
9
|
+
{ :type => :plaintext, :regex => // }]
|
10
|
+
@base_path = "numbers.formats"
|
11
|
+
@symbol_path = "numbers.symbols"
|
12
|
+
@paths = { :default => "patterns.default",
|
13
|
+
:positive => "patterns.positive",
|
14
|
+
:negative => "patterns.negative" }
|
15
|
+
end
|
16
|
+
|
17
|
+
def tokens(options = {})
|
18
|
+
unless self.traverse(self.full_path_for(:positive))
|
19
|
+
key_path = self.full_path_for(:default)
|
20
|
+
positive, negative = self.traverse(key_path).split(/;/)
|
21
|
+
insert_point = self.traverse(KeyPath.dirname(key_path))
|
22
|
+
insert_point[:positive] = positive
|
23
|
+
insert_point[:negative] = negative ? negative : "#{self.symbols[:minus] || '-'}#{positive}"
|
24
|
+
end
|
25
|
+
|
26
|
+
sign = options[:sign] || :positive
|
27
|
+
self.tokens_for(self.full_path_for(sign), nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
def symbols
|
31
|
+
self.traverse(@symbol_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def full_path_for(path)
|
37
|
+
KeyPath.join(@base_path, @type.to_s, self.paths[path])
|
38
|
+
end
|
39
|
+
|
40
|
+
def init_resources
|
41
|
+
@resource = TwitterCldr.resources.resource_for(@locale, "numbers")[TwitterCldr.convert_locale(@locale)]
|
42
|
+
end
|
43
|
+
|
44
|
+
def pattern_for(resource)
|
45
|
+
# can't go any deeper, so return original pattern (which should NOT be a hash, by the way)
|
46
|
+
resource
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Tokenizers
|
3
|
+
class Token
|
4
|
+
attr_accessor :value, :type
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
options.each_pair do |key, val|
|
8
|
+
self.send("#{key.to_s}=", val)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
@value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/twitter_cldr.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
$:.push(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'date'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
require 'version'
|
8
|
+
|
9
|
+
# patches for extending Ruby functionality
|
10
|
+
require 'ext/localized_object'
|
11
|
+
require 'ext/calendars/datetime'
|
12
|
+
require 'ext/calendars/date'
|
13
|
+
require 'ext/calendars/time'
|
14
|
+
require 'ext/numbers/localized_number'
|
15
|
+
require 'ext/numbers/bignum'
|
16
|
+
require 'ext/numbers/fixnum'
|
17
|
+
require 'ext/numbers/float'
|
18
|
+
require 'ext/strings/symbol'
|
19
|
+
|
20
|
+
# manages access to CLDR resources (yaml files in resources dir)
|
21
|
+
require 'shared/resources'
|
22
|
+
|
23
|
+
|
24
|
+
module TwitterCldr
|
25
|
+
DEFAULT_LOCALE = :en
|
26
|
+
RESOURCE_DIR = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), "resources")
|
27
|
+
|
28
|
+
# maps twitter locales to cldr locales
|
29
|
+
TWITTER_LOCALE_MAP = { :msa => :ms,
|
30
|
+
:'zh-cn' => :zh,
|
31
|
+
:'zh-tw' => :'zh-Hant' }
|
32
|
+
|
33
|
+
@@resources = TwitterCldr::Shared::Resources.new
|
34
|
+
|
35
|
+
def self.get_resource_file(locale, resource)
|
36
|
+
File.join(RESOURCE_DIR, self.convert_locale(locale).to_s, "#{resource}.yml")
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.resources
|
40
|
+
@@resources
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.get_locale
|
44
|
+
if defined?(FastGettext)
|
45
|
+
locale = FastGettext.locale
|
46
|
+
locale = DEFAULT_LOCALE if locale.to_s.empty?
|
47
|
+
else
|
48
|
+
locale = DEFAULT_LOCALE
|
49
|
+
end
|
50
|
+
|
51
|
+
(self.supported_locale?(locale) ? locale : DEFAULT_LOCALE).to_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.convert_locale(locale)
|
55
|
+
locale = locale.to_sym
|
56
|
+
TWITTER_LOCALE_MAP.include?(locale) ? TWITTER_LOCALE_MAP[locale] : locale
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.supported_locales
|
60
|
+
unless defined?(@@supported_locales)
|
61
|
+
rejectable = [:shared]
|
62
|
+
@@supported_locales = Dir.glob(File.join(File.dirname(File.dirname(__FILE__)), "resources/*")).map do |file|
|
63
|
+
File.basename(file).to_sym
|
64
|
+
end.reject { |file| rejectable.include?(file) }
|
65
|
+
end
|
66
|
+
|
67
|
+
@@supported_locales
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.supported_locale?(locale)
|
71
|
+
locale = locale.to_sym
|
72
|
+
self.supported_locales.include?(locale) || self.supported_locales.include?(self.convert_locale(locale))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# other shared libraries (most access shared resource data in resources/shared)
|
78
|
+
require 'shared/currencies'
|
79
|
+
require 'shared/languages'
|
80
|
+
|
81
|
+
# all tokenizers
|
82
|
+
require 'tokenizers/base'
|
83
|
+
require 'tokenizers/key_path'
|
84
|
+
require 'tokenizers/token'
|
85
|
+
require 'tokenizers/calendars/datetime_tokenizer'
|
86
|
+
require 'tokenizers/calendars/date_tokenizer'
|
87
|
+
require 'tokenizers/calendars/time_tokenizer'
|
88
|
+
require 'tokenizers/numbers/number_tokenizer'
|
89
|
+
|
90
|
+
# all formatters
|
91
|
+
require 'formatters/base'
|
92
|
+
require 'formatters/calendars/datetime_formatter'
|
93
|
+
require 'formatters/calendars/date_formatter'
|
94
|
+
require 'formatters/calendars/time_formatter'
|
95
|
+
require 'formatters/numbers/number_formatter'
|
96
|
+
require 'formatters/numbers/decimal_formatter'
|
97
|
+
require 'formatters/numbers/currency_formatter'
|
98
|
+
require 'formatters/numbers/percent_formatter'
|
99
|
+
require 'formatters/plurals/rules'
|
100
|
+
|
101
|
+
# formatter helpers
|
102
|
+
require 'formatters/numbers/helpers/base'
|
103
|
+
require 'formatters/numbers/helpers/fraction'
|
104
|
+
require 'formatters/numbers/helpers/integer'
|
data/lib/version.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
ar:
|
2
|
+
calendars:
|
3
|
+
gregorian:
|
4
|
+
days:
|
5
|
+
format:
|
6
|
+
abbreviated:
|
7
|
+
fri: جمعة
|
8
|
+
mon: اثنين
|
9
|
+
sat: سبت
|
10
|
+
sun: أحد
|
11
|
+
thu: خميس
|
12
|
+
tue: ثلاثاء
|
13
|
+
wed: أربعاء
|
14
|
+
narrow: :"calendars.gregorian.days.stand-alone.narrow"
|
15
|
+
wide:
|
16
|
+
fri: الجمعة
|
17
|
+
mon: الاثنين
|
18
|
+
sat: السبت
|
19
|
+
sun: الأحد
|
20
|
+
thu: الخميس
|
21
|
+
tue: الثلاثاء
|
22
|
+
wed: الأربعاء
|
23
|
+
stand-alone:
|
24
|
+
abbreviated: :"calendars.gregorian.days.format.abbreviated"
|
25
|
+
narrow:
|
26
|
+
fri: ج
|
27
|
+
mon: ن
|
28
|
+
sat: س
|
29
|
+
sun: ح
|
30
|
+
thu: خ
|
31
|
+
tue: ث
|
32
|
+
wed: ر
|
33
|
+
wide: :"calendars.gregorian.days.format.wide"
|
34
|
+
fields:
|
35
|
+
day: يوم
|
36
|
+
dayperiod: ص/م
|
37
|
+
era: العصر
|
38
|
+
hour: الساعات
|
39
|
+
minute: الدقائق
|
40
|
+
month: الشهر
|
41
|
+
second: الثواني
|
42
|
+
week: الأسبوع
|
43
|
+
weekday: اليوم
|
44
|
+
year: السنة
|
45
|
+
zone: التوقيت
|
46
|
+
formats:
|
47
|
+
date:
|
48
|
+
default: :"calendars.gregorian.formats.date.medium"
|
49
|
+
full:
|
50
|
+
pattern: "EEEE، d MMMM، y"
|
51
|
+
long:
|
52
|
+
pattern: "d MMMM، y"
|
53
|
+
medium:
|
54
|
+
pattern: dd/MM/yyyy
|
55
|
+
short:
|
56
|
+
pattern: d/M/yyyy
|
57
|
+
datetime:
|
58
|
+
default: :"calendars.gregorian.formats.datetime.medium"
|
59
|
+
full:
|
60
|
+
pattern: "{1} {0}"
|
61
|
+
long:
|
62
|
+
pattern: "{1} {0}"
|
63
|
+
medium:
|
64
|
+
pattern: "{1} {0}"
|
65
|
+
short:
|
66
|
+
pattern: "{1} {0}"
|
67
|
+
time:
|
68
|
+
default: :"calendars.gregorian.formats.time.medium"
|
69
|
+
full:
|
70
|
+
pattern: "zzzz h:mm:ss a"
|
71
|
+
long:
|
72
|
+
pattern: "z h:mm:ss a"
|
73
|
+
medium:
|
74
|
+
pattern: "h:mm:ss a"
|
75
|
+
short:
|
76
|
+
pattern: "h:mm a"
|
77
|
+
months:
|
78
|
+
format:
|
79
|
+
abbreviated:
|
80
|
+
1: يناير
|
81
|
+
10: أكتوبر
|
82
|
+
11: نوفمبر
|
83
|
+
12: ديسمبر
|
84
|
+
2: فبراير
|
85
|
+
3: مارس
|
86
|
+
4: أبريل
|
87
|
+
5: مايو
|
88
|
+
6: يونيو
|
89
|
+
7: يوليو
|
90
|
+
8: أغسطس
|
91
|
+
9: سبتمبر
|
92
|
+
narrow: :"calendars.gregorian.months.stand-alone.narrow"
|
93
|
+
wide:
|
94
|
+
1: يناير
|
95
|
+
10: أكتوبر
|
96
|
+
11: نوفمبر
|
97
|
+
12: ديسمبر
|
98
|
+
2: فبراير
|
99
|
+
3: مارس
|
100
|
+
4: أبريل
|
101
|
+
5: مايو
|
102
|
+
6: يونيو
|
103
|
+
7: يوليو
|
104
|
+
8: أغسطس
|
105
|
+
9: سبتمبر
|
106
|
+
stand-alone:
|
107
|
+
abbreviated: :"calendars.gregorian.months.format.abbreviated"
|
108
|
+
narrow:
|
109
|
+
1: ي
|
110
|
+
10: ك
|
111
|
+
11: ب
|
112
|
+
12: د
|
113
|
+
2: ف
|
114
|
+
3: م
|
115
|
+
4: أ
|
116
|
+
5: و
|
117
|
+
6: ن
|
118
|
+
7: ل
|
119
|
+
8: غ
|
120
|
+
9: س
|
121
|
+
wide: :"calendars.gregorian.months.format.wide"
|
122
|
+
periods:
|
123
|
+
am: ص
|
124
|
+
pm: م
|
125
|
+
quarters:
|
126
|
+
format:
|
127
|
+
abbreviated:
|
128
|
+
1: "الربع الأول"
|
129
|
+
2: "الربع الثاني"
|
130
|
+
3: "الربع الثالث"
|
131
|
+
4: "الربع الرابع"
|
132
|
+
narrow: :"calendars.gregorian.quarters.stand-alone.narrow"
|
133
|
+
wide:
|
134
|
+
1: "الربع الأول"
|
135
|
+
2: "الربع الثاني"
|
136
|
+
3: "الربع الثالث"
|
137
|
+
4: "الربع الرابع"
|
138
|
+
stand-alone:
|
139
|
+
abbreviated: :"calendars.gregorian.quarters.format.abbreviated"
|
140
|
+
narrow:
|
141
|
+
1: ١
|
142
|
+
2: ٢
|
143
|
+
3: ٣
|
144
|
+
4: ٤
|
145
|
+
wide: :"calendars.gregorian.quarters.format.wide"
|