twitter_cldr 1.3.0 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.md +58 -10
  2. data/Rakefile +25 -0
  3. data/lib/twitter_cldr.rb +16 -1
  4. data/lib/twitter_cldr/core_ext.rb +1 -0
  5. data/lib/twitter_cldr/core_ext/calendars/datetime.rb +14 -0
  6. data/lib/twitter_cldr/core_ext/calendars/timespan.rb +26 -0
  7. data/lib/twitter_cldr/formatters.rb +1 -0
  8. data/lib/twitter_cldr/formatters/calendars/datetime_formatter.rb +1 -6
  9. data/lib/twitter_cldr/formatters/calendars/timespan_formatter.rb +67 -0
  10. data/lib/twitter_cldr/formatters/numbers/number_formatter.rb +1 -1
  11. data/lib/twitter_cldr/tokenizers.rb +1 -0
  12. data/lib/twitter_cldr/tokenizers/base.rb +23 -9
  13. data/lib/twitter_cldr/tokenizers/calendars/date_tokenizer.rb +14 -8
  14. data/lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb +13 -9
  15. data/lib/twitter_cldr/tokenizers/calendars/time_tokenizer.rb +13 -7
  16. data/lib/twitter_cldr/tokenizers/calendars/timespan_tokenizer.rb +82 -0
  17. data/lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb +21 -14
  18. data/lib/twitter_cldr/tokenizers/token.rb +4 -0
  19. data/lib/twitter_cldr/version.rb +1 -1
  20. data/resources/locales/ar/units.yml +149 -0
  21. data/resources/locales/da/units.yml +79 -0
  22. data/resources/locales/de/units.yml +93 -0
  23. data/resources/locales/en/units.yml +65 -0
  24. data/resources/locales/es/units.yml +93 -0
  25. data/resources/locales/fa/units.yml +86 -0
  26. data/resources/locales/fi/units.yml +93 -0
  27. data/resources/locales/fil/units.yml +79 -0
  28. data/resources/locales/fr/units.yml +93 -0
  29. data/resources/locales/he/units.yml +79 -0
  30. data/resources/locales/hi/units.yml +79 -0
  31. data/resources/locales/hu/units.yml +72 -0
  32. data/resources/locales/id/units.yml +72 -0
  33. data/resources/locales/it/units.yml +79 -0
  34. data/resources/locales/ja/units.yml +72 -0
  35. data/resources/locales/ko/units.yml +72 -0
  36. data/resources/locales/ms/units.yml +86 -0
  37. data/resources/locales/nl/units.yml +79 -0
  38. data/resources/locales/pl/units.yml +135 -0
  39. data/resources/locales/pt/units.yml +93 -0
  40. data/resources/locales/ru/units.yml +135 -0
  41. data/resources/locales/sv/units.yml +93 -0
  42. data/resources/locales/th/units.yml +72 -0
  43. data/resources/locales/tr/units.yml +72 -0
  44. data/resources/locales/ur/units.yml +86 -0
  45. data/resources/locales/zh-Hant/units.yml +72 -0
  46. data/resources/locales/zh/units.yml +72 -0
  47. data/spec/core_ext/calendars/date_spec.rb +83 -9
  48. data/spec/core_ext/calendars/datetime_spec.rb +1 -3
  49. data/spec/core_ext/calendars/time_spec.rb +12 -3
  50. data/spec/formatters/calendars/timespan_formatter_spec.rb +39 -0
  51. data/spec/tokenizers/base_spec.rb +10 -10
  52. data/spec/tokenizers/calendars/timespan_tokenizer_spec.rb +24 -0
  53. data/spec/tokenizers/numbers/number_tokenizer_spec.rb +1 -1
  54. data/spec/twitter_cldr_spec.rb +16 -0
  55. metadata +126 -14
  56. data/lib/twitter_cldr/tokenizers/key_path.rb +0 -35
  57. data/spec/tokenizers/key_path_spec.rb +0 -49
@@ -9,13 +9,19 @@ module TwitterCldr
9
9
  def initialize(options = {})
10
10
  super(options)
11
11
  @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})/
12
- @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}/ },
13
- { :type => :plaintext, :regex => // }]
14
- @paths = { :default => "formats.time.default",
15
- :full => "formats.time.full",
16
- :long => "formats.time.long",
17
- :medium => "formats.time.medium",
18
- :short => "formats.time.short" }
12
+
13
+ @token_type_regexes = [
14
+ { :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})/ },
15
+ { :type => :plaintext, :regex => // }
16
+ ]
17
+
18
+ @paths = {
19
+ :default => [:formats, :time, :default],
20
+ :full => [:formats, :time, :full],
21
+ :long => [:formats, :time, :long],
22
+ :medium => [:formats, :time, :medium],
23
+ :short => [:formats, :time, :short]
24
+ }
19
25
  end
20
26
 
21
27
  protected
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ module TwitterCldr
7
+ module Tokenizers
8
+ class TimespanTokenizer < Base
9
+ def initialize(options = {})
10
+ super(options)
11
+
12
+ @type = options[:type] || :decimal
13
+
14
+ @token_splitter_regex = /([^0*#,\.]*)([0#,\.]+)([^0*#,\.]*)$/ # creates spaces
15
+ @token_type_regexes = [
16
+ { :type => :pattern, :regex => /[0?#,\.]*/ }, # splits token at right places
17
+ { :type => :plaintext, :regex => // }
18
+ ]
19
+ @base_path = [:units]
20
+ @paths = {
21
+ :ago => {
22
+ :default => :'hour-past',
23
+ :second => :'second-past',
24
+ :minute => :'minute-past',
25
+ :hour => :'hour-past',
26
+ :day => :'day-past',
27
+ :week => :'week-past',
28
+ :month => :'month-past',
29
+ :year => :'year-past'
30
+ },
31
+ :until => {
32
+ :default => :'hour-future',
33
+ :second => :'second-future',
34
+ :minute => :'minute-future',
35
+ :hour => :'hour-future',
36
+ :day => :'day-future',
37
+ :week => :'week-future',
38
+ :month => :'month-future',
39
+ :year => :'year-future'
40
+ }
41
+ }
42
+ end
43
+
44
+ def tokens(options = {})
45
+ path = full_path(options[:direction], options[:unit] || :default)
46
+ pluralization = TwitterCldr::Formatters::Plurals::Rules.rule_for(options[:number], @locale)
47
+
48
+ case pluralization # sometimes the plural rule will return ":one" when the resource only contains a path with "1"
49
+ when :zero
50
+ pluralization = 0 if token_exists(path + [0])
51
+ when :one
52
+ pluralization = 1 if token_exists(path + [1])
53
+ when :two
54
+ pluralization = 2 if token_exists(path + [2])
55
+ end
56
+ path += [pluralization]
57
+ tokens_with_placeholders_for(path) if token_exists(path)
58
+ end
59
+
60
+ def token_exists(path)
61
+ @@token_cache ||= {}
62
+ cache_key = compute_cache_key(@locale, path.join('.'))
63
+ true if @@token_cache.include?(cache_key) || traverse(path)
64
+ end
65
+
66
+ protected
67
+
68
+ def full_path(direction, unit)
69
+ @base_path + [@paths[direction][unit]]
70
+ end
71
+
72
+ def init_resources
73
+ @resource = TwitterCldr.get_locale_resource(@locale, :units)[TwitterCldr.convert_locale(@locale)]
74
+ end
75
+
76
+ def pattern_for(resource)
77
+ # can't go any deeper, so return original pattern (which should NOT be a hash, by the way)
78
+ resource
79
+ end
80
+ end
81
+ end
82
+ end
@@ -8,28 +8,35 @@ module TwitterCldr
8
8
  class NumberTokenizer < Base
9
9
  def initialize(options = {})
10
10
  super(options)
11
+
11
12
  @type = options[:type] || :decimal
13
+
12
14
  @token_splitter_regex = /([^0*#,\.]*)([0#,\.]+)([^0*#,\.]*)$/
13
- @token_type_regexes = [{ :type => :pattern, :regex => /[0?#,\.]*/ },
14
- { :type => :plaintext, :regex => // }]
15
- @base_path = "numbers.formats"
16
- @symbol_path = "numbers.symbols"
17
- @paths = { :default => "patterns.default",
18
- :positive => "patterns.positive",
19
- :negative => "patterns.negative" }
15
+ @token_type_regexes = [{ :type => :pattern, :regex => /[0?#,\.]*/ }, { :type => :plaintext, :regex => // }]
16
+
17
+ @base_path = [:numbers, :formats]
18
+ @symbol_path = [:numbers, :symbols]
19
+
20
+ @paths = {
21
+ :default => [:patterns, :default],
22
+ :positive => [:patterns, :positive],
23
+ :negative => [:patterns, :negative]
24
+ }
20
25
  end
21
26
 
22
27
  def tokens(options = {})
23
- unless self.traverse(self.full_path_for(:positive))
24
- key_path = self.full_path_for(:default)
25
- positive, negative = self.traverse(key_path).split(/;/)
26
- insert_point = self.traverse(KeyPath.dirname(key_path))
28
+ unless traverse(full_path_for(:positive))
29
+ key_path = full_path_for(:default)
30
+
31
+ positive, negative = traverse(key_path).split(/;/)
32
+
33
+ insert_point = traverse(key_path[0..-2])
27
34
  insert_point[:positive] = positive
28
- insert_point[:negative] = negative ? negative : "#{self.symbols[:minus] || '-'}#{positive}"
35
+ insert_point[:negative] = negative ? negative : "#{symbols[:minus] || '-'}#{positive}"
29
36
  end
30
37
 
31
38
  sign = options[:sign] || :positive
32
- self.tokens_for(self.full_path_for(sign), nil)
39
+ tokens_for(full_path_for(sign), nil)
33
40
  end
34
41
 
35
42
  def symbols
@@ -39,7 +46,7 @@ module TwitterCldr
39
46
  protected
40
47
 
41
48
  def full_path_for(path)
42
- KeyPath.join(@base_path, @type.to_s, self.paths[path])
49
+ @base_path + [@type] + paths[path]
43
50
  end
44
51
 
45
52
  def init_resources
@@ -17,6 +17,10 @@ module TwitterCldr
17
17
  def to_s
18
18
  @value
19
19
  end
20
+
21
+ def to_hash
22
+ { :value => @value, :type => @type }
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = "1.3.0"
7
+ VERSION = "1.3.6"
8
8
  end
@@ -0,0 +1,149 @@
1
+ ar:
2
+ units:
3
+ day:
4
+ few: "{0} أيام"
5
+ many: "{0} يوماً"
6
+ one: يوم
7
+ other: "{0} يوم"
8
+ two: يومان
9
+ zero: "لا أيام"
10
+ day-future:
11
+ 0: "خلال 0 يوم"
12
+ 1: "خلال يوم واحد"
13
+ few: "خلال {0} أيام"
14
+ many: "خلال {0} يومًا"
15
+ other: "خلال {0} من الأيام"
16
+ two: "خلال يومين"
17
+ day-past:
18
+ 0: "قبل 0 يوم"
19
+ 1: "قبل يوم واحد"
20
+ few: "قبل {0} أيام"
21
+ many: "قبل {0} يومًا"
22
+ other: "قبل {0} من الأيام"
23
+ two: "قبل يومين"
24
+ hour:
25
+ few: "{0} س"
26
+ many: "{0} س"
27
+ one: ساعة
28
+ other: "{0} س"
29
+ two: ساعتان
30
+ zero: "لا ساعات"
31
+ hour-future:
32
+ 0: "خلال 0 ساعة"
33
+ 1: "خلال ساعة واحدة"
34
+ few: "خلال {0} ساعات"
35
+ many: "خلال {0} ساعة"
36
+ other: "خلال {0} من الساعات"
37
+ two: "خلال ساعتين"
38
+ hour-past:
39
+ 0: "قبل 0 ساعة"
40
+ 1: "قبل ساعة واحدة"
41
+ few: "قبل {0} ساعات"
42
+ many: "قبل {0} ساعة"
43
+ other: "قبل {0} من الساعات"
44
+ two: "قبل ساعتين"
45
+ minute:
46
+ few: "{0} د"
47
+ many: "{0} د"
48
+ one: دقيقة
49
+ other: "{0} د"
50
+ two: دقيقتان
51
+ zero: "لا دقائق"
52
+ minute-future:
53
+ 0: "خلال 0 دقيقة"
54
+ 1: "خلال دقيقة واحدة"
55
+ few: "خلال {0} دقائق"
56
+ many: "خلال {0} دقيقة"
57
+ other: "خلال {0} من الدقائق"
58
+ two: "خلال دقيقتين"
59
+ minute-past:
60
+ 0: "قبل 0 دقيقة"
61
+ 1: "قبل دقيقة واحدة"
62
+ few: "قبل {0} دقائق"
63
+ many: "قبل {0} دقيقة"
64
+ other: "قبل {0} من الدقائق"
65
+ two: "قبل دقيقتين"
66
+ month:
67
+ few: "{0} أشهر"
68
+ many: "{0} شهراً"
69
+ one: شهر
70
+ other: "{0} شهر"
71
+ two: شهران
72
+ zero: "لا أشهر"
73
+ month-future:
74
+ 0: "خلال 0 شهر"
75
+ 1: "خلال شهر واحد"
76
+ few: "خلال {0} شهور"
77
+ many: "خلال {0} شهرًا"
78
+ other: "خلال {0} من الشهور"
79
+ two: "خلال شهرين"
80
+ month-past:
81
+ 0: "قبل 0 شهر"
82
+ 1: "قبل شهر واحد"
83
+ few: "قبل {0} أشهر"
84
+ many: "قبل {0} شهرًا"
85
+ other: "قبل {0} من الشهور"
86
+ two: "قبل شهرين"
87
+ second:
88
+ few: "{0} ث"
89
+ many: "{0} ث"
90
+ one: ثانية
91
+ other: "{0} ث"
92
+ two: ثانيتان
93
+ zero: "لا ثوان"
94
+ second-future:
95
+ 0: "خلال 0 ثانية"
96
+ 1: "خلال ثانية واحدة"
97
+ few: "خلال {0} ثوانِ"
98
+ many: "خلال {0} ثانية"
99
+ other: "خلال {0} من الثواني"
100
+ two: "خلال ثانيتين"
101
+ second-past:
102
+ 0: "قبل 0 ثانية"
103
+ 1: "قبل ثانية واحدة"
104
+ few: "قبل {0} ثوانِ"
105
+ many: "قبل {0} ثانية"
106
+ other: "قبل {0} من الثواني"
107
+ two: "قبل ثانيتين"
108
+ week:
109
+ few: "{0} أسابيع"
110
+ many: "{0} أسبوعاً"
111
+ one: أسبوع
112
+ other: "{0} أسبوع"
113
+ two: أسبوعان
114
+ zero: "لا أسابيع"
115
+ week-future:
116
+ 0: "خلال 0 أسبوع"
117
+ 1: "خلال أسبوع واحد"
118
+ few: "خلال {0} أسابيع"
119
+ many: "خلال {0} أسبوعًا"
120
+ other: "خلال {0} من الأسابيع"
121
+ two: "خلال أسبوعين"
122
+ week-past:
123
+ 0: "قبل 0 أسبوع"
124
+ 1: "قبل أسبوع واحد"
125
+ few: "قبل {0} أسابيع"
126
+ many: "قبل {0} أسبوعًا"
127
+ other: "قبل {0} من الأسابيع"
128
+ two: "قبل أسبوعين"
129
+ year:
130
+ few: "{0} سنوات"
131
+ many: "{0} سنةً"
132
+ one: سنة
133
+ other: "{0} سنة"
134
+ two: سنتان
135
+ zero: "لا سنوات"
136
+ year-future:
137
+ 0: "خلال 0 سنة"
138
+ 1: "خلال سنة واحدة"
139
+ few: "خلال {0} سنوات"
140
+ many: "خلال {0} سنة"
141
+ other: "خلال {0} من السنوات"
142
+ two: "خلال سنتين"
143
+ year-past:
144
+ 0: "قبل 0 سنة"
145
+ 1: "قبل سنة واحدة"
146
+ few: "قبل {0} سنوات"
147
+ many: "قبل {0} سنة"
148
+ other: "قبل {0} من السنوات"
149
+ two: "قبل سنتين"
@@ -0,0 +1,79 @@
1
+ da:
2
+ units:
3
+ day:
4
+ one: "{0} dag"
5
+ other: "{0} dage"
6
+ day-future:
7
+ 0: "Om 0 dage"
8
+ 1: "Om 1 dag"
9
+ other: "Om {0} dage"
10
+ day-past:
11
+ 0: "0 dage siden"
12
+ 1: "1 dag siden"
13
+ other: "{0} dage siden"
14
+ hour:
15
+ one: "{0} t."
16
+ other: "{0} t."
17
+ hour-future:
18
+ 0: "Om 0 timer"
19
+ 1: "Om 1 time"
20
+ other: "Om {0} timer"
21
+ hour-past:
22
+ 0: "0 timer siden"
23
+ 1: "1 time siden"
24
+ other: "{0} timer siden"
25
+ minute:
26
+ one: "{0} min."
27
+ other: "{0} min."
28
+ minute-future:
29
+ 0: "Om 0 minutter"
30
+ 1: "Om 1 minut"
31
+ other: "Om {0} minutter"
32
+ minute-past:
33
+ 0: "0 minutter siden"
34
+ 1: "1 minut siden"
35
+ other: "{0} minutter siden"
36
+ month:
37
+ one: "{0} mdr."
38
+ other: "{0} mdr."
39
+ month-future:
40
+ 0: "Om 0 måneder"
41
+ 1: "Om 1 måned"
42
+ other: "Om {0} måneder"
43
+ month-past:
44
+ 0: "0 måneder siden"
45
+ 1: "1 måned siden"
46
+ other: "{0} måneder siden"
47
+ second:
48
+ one: "{0} sek."
49
+ other: "{0} sek."
50
+ second-future:
51
+ 0: "Om 0 sekunder"
52
+ 1: "Om 1 sekund"
53
+ other: "Om {0} sekunder"
54
+ second-past:
55
+ 0: "0 sekunder siden"
56
+ 1: "1 sekund siden"
57
+ other: "{0} sekunder siden"
58
+ week:
59
+ one: "{0} uge"
60
+ other: "{0} uger"
61
+ week-future:
62
+ 0: "Om 0 uger"
63
+ 1: "om 1 uge"
64
+ other: "Om {0} uger"
65
+ week-past:
66
+ 0: "0 uger siden"
67
+ 1: "1 uge siden"
68
+ other: "{0} uger siden"
69
+ year:
70
+ one: "{0} år"
71
+ other: "{0} år"
72
+ year-future:
73
+ 0: "Om 0 år"
74
+ 1: "Om 1 år"
75
+ other: "Om {0} år"
76
+ year-past:
77
+ 0: "0 år siden"
78
+ 1: "1 år siden"
79
+ other: "{0} år siden"
@@ -0,0 +1,93 @@
1
+ de:
2
+ units:
3
+ day:
4
+ one: "{0} Tag"
5
+ other: "{0} Tage"
6
+ day-future:
7
+ 0: "In 0 Tagen"
8
+ 1: "In 1 Tag"
9
+ one: "In {0} Tag"
10
+ other: "In {0} Tagen"
11
+ day-past:
12
+ 0: "Vor 0 Tagen"
13
+ 1: "Vor 1 Tag"
14
+ one: "Vor {0} Tag"
15
+ other: "Vor {0} Tagen"
16
+ hour:
17
+ one: "{0} Std."
18
+ other: "{0} Std."
19
+ hour-future:
20
+ 0: "In 0 Stunden"
21
+ 1: "In 1 Stunde"
22
+ one: "In {0} Stunde"
23
+ other: "In {0} Stunden"
24
+ hour-past:
25
+ 0: "Vor 0 Stunden"
26
+ 1: "Vor 1 Stunde"
27
+ one: "Vor {0} Stunde"
28
+ other: "Vor {0} Stunden"
29
+ minute:
30
+ one: "{0} Min."
31
+ other: "{0} Min."
32
+ minute-future:
33
+ 0: "In 0 Minuten"
34
+ 1: "In 1 Minute"
35
+ one: "In {0} Minute"
36
+ other: "In {0} Minuten"
37
+ minute-past:
38
+ 0: "Vor 0 Minuten"
39
+ 1: "Vor 1 Minute"
40
+ one: "Vor {0} Minute"
41
+ other: "Vor {0} Minuten"
42
+ month:
43
+ one: "{0} Monat"
44
+ other: "{0} Monate"
45
+ month-future:
46
+ 0: "In 0 Monaten"
47
+ 1: "In 1 Monat"
48
+ one: "In {0} Monat"
49
+ other: "In {0} Monaten"
50
+ month-past:
51
+ 0: "Vor 0 Monaten"
52
+ 1: "Vor 1 Monat"
53
+ one: "Vor {0} Monat"
54
+ other: "Vor {0} Monaten"
55
+ second:
56
+ one: "{0} Sek."
57
+ other: "{0} Sek."
58
+ second-future:
59
+ 0: "In 0 Sekunden"
60
+ 1: "In 1 Sekunde"
61
+ one: "In {0} Sekunde"
62
+ other: "In {0} Sekunden"
63
+ second-past:
64
+ 0: "Vor 0 Sekunden"
65
+ 1: "Vor 1 Sekunde"
66
+ one: "Vor {0} Sekunde"
67
+ other: "Vor {0} Sekunden"
68
+ week:
69
+ one: "{0} Woche"
70
+ other: "{0} Wochen"
71
+ week-future:
72
+ 0: "In 0 Wochen"
73
+ 1: "In 1 Woche"
74
+ one: "In {0} Woche"
75
+ other: "In {0} Wochen"
76
+ week-past:
77
+ 0: "Vor 0 Wochen"
78
+ 1: "Vor 1 Woche"
79
+ one: "Vor {0} Woche"
80
+ other: "Vor {0} Wochen"
81
+ year:
82
+ one: "{0} Jahr"
83
+ other: "{0} Jahre"
84
+ year-future:
85
+ 0: "In 0 Jahren"
86
+ 1: "In 1 Jahr"
87
+ one: "In {0} Jahr"
88
+ other: "In {0} Jahren"
89
+ year-past:
90
+ 0: "Vor 0 Jahren"
91
+ 1: "Vor 1 Jahr"
92
+ one: "Vor {0} Jahr"
93
+ other: "Vor {0} Jahren"