twitter_cldr 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/README.md +185 -31
  2. data/lib/ext/calendars/date.rb +2 -0
  3. data/lib/ext/calendars/datetime.rb +2 -0
  4. data/lib/ext/calendars/time.rb +2 -0
  5. data/lib/ext/localized_object.rb +2 -0
  6. data/lib/ext/numbers/bignum.rb +2 -0
  7. data/lib/ext/numbers/fixnum.rb +2 -0
  8. data/lib/ext/numbers/float.rb +2 -0
  9. data/lib/ext/numbers/localized_number.rb +2 -0
  10. data/lib/ext/strings/symbol.rb +2 -0
  11. data/lib/formatters/base.rb +2 -0
  12. data/lib/formatters/calendars/date_formatter.rb +2 -0
  13. data/lib/formatters/calendars/datetime_formatter.rb +2 -0
  14. data/lib/formatters/calendars/time_formatter.rb +2 -0
  15. data/lib/formatters/numbers/currency_formatter.rb +2 -0
  16. data/lib/formatters/numbers/decimal_formatter.rb +2 -0
  17. data/lib/formatters/numbers/helpers/base.rb +2 -0
  18. data/lib/formatters/numbers/helpers/fraction.rb +2 -0
  19. data/lib/formatters/numbers/helpers/integer.rb +2 -0
  20. data/lib/formatters/numbers/number_formatter.rb +2 -0
  21. data/lib/formatters/numbers/percent_formatter.rb +2 -0
  22. data/lib/formatters/plurals/rules.rb +2 -0
  23. data/lib/shared/currencies.rb +2 -0
  24. data/lib/shared/languages.rb +2 -0
  25. data/lib/shared/resources.rb +2 -0
  26. data/lib/shared/timezones.rb +2 -0
  27. data/lib/tokenizers/base.rb +10 -6
  28. data/lib/tokenizers/calendars/date_tokenizer.rb +2 -0
  29. data/lib/tokenizers/calendars/datetime_tokenizer.rb +2 -0
  30. data/lib/tokenizers/calendars/time_tokenizer.rb +2 -0
  31. data/lib/tokenizers/key_path.rb +2 -0
  32. data/lib/tokenizers/numbers/number_tokenizer.rb +2 -0
  33. data/lib/tokenizers/token.rb +2 -0
  34. data/lib/twitter_cldr.rb +4 -0
  35. data/lib/version.rb +1 -1
  36. data/spec/ext/calendars/date_spec.rb +2 -0
  37. data/spec/ext/calendars/datetime_spec.rb +2 -0
  38. data/spec/ext/calendars/time_spec.rb +2 -0
  39. data/spec/ext/numbers/bignum_spec.rb +2 -0
  40. data/spec/ext/numbers/fixnum_spec.rb +2 -0
  41. data/spec/ext/numbers/float_spec.rb +2 -0
  42. data/spec/ext/numbers/localized_number_spec.rb +2 -0
  43. data/spec/ext/strings/symbol_spec.rb +2 -0
  44. data/spec/formatters/base_spec.rb +2 -0
  45. data/spec/formatters/calendars/datetime_formatter_spec.rb +3 -1
  46. data/spec/formatters/numbers/currency_formatter_spec.rb +2 -0
  47. data/spec/formatters/numbers/decimal_formatter_spec.rb +2 -0
  48. data/spec/formatters/numbers/helpers/fraction_spec.rb +2 -0
  49. data/spec/formatters/numbers/helpers/integer_spec.rb +2 -0
  50. data/spec/formatters/numbers/number_formatter_spec.rb +2 -0
  51. data/spec/formatters/numbers/percent_formatter_spec.rb +2 -0
  52. data/spec/formatters/plurals/rules_spec.rb +2 -0
  53. data/spec/shared/currencies_spec.rb +2 -0
  54. data/spec/shared/languages_spec.rb +2 -0
  55. data/spec/shared/resources_spec.rb +2 -0
  56. data/spec/spec_helper.rb +2 -0
  57. data/spec/tokenizers/base_spec.rb +8 -3
  58. data/spec/tokenizers/calendars/date_tokenizer_spec.rb +2 -0
  59. data/spec/tokenizers/calendars/datetime_tokenizer_spec.rb +2 -0
  60. data/spec/tokenizers/calendars/time_tokenizer_spec.rb +2 -0
  61. data/spec/tokenizers/key_path_spec.rb +2 -0
  62. data/spec/tokenizers/numbers/number_tokenizer_spec.rb +2 -0
  63. data/spec/tokenizers/token_spec.rb +2 -0
  64. data/spec/twitter_cldr_spec.rb +2 -0
  65. metadata +16 -16
data/README.md CHANGED
@@ -1,11 +1,39 @@
1
- ## twitter-cldr-rb
1
+ ## twitter-cldr-rb [![Build Status](https://secure.travis-ci.org/twitter/twitter-cldr-rb.png?branch=master)](http://travis-ci.org/twitter/twitter-cldr-rb)
2
2
 
3
3
  TwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their
4
- localized equivalents. Currently supported types of text include dates, times, currencies, decimals, and percentages.
4
+ localized equivalents. Currently supported types of text include dates, times, currencies, decimals, percentages, and symbols.
5
5
 
6
- ## Features
6
+ ## Installation
7
+
8
+ `gem install twitter_cldr`
9
+
10
+ ## Usage
11
+
12
+ ```ruby
13
+ require 'twitter_cldr'
14
+ ```
15
+
16
+ ### Basics
17
+
18
+ Get a list of all currently supported locales (these are all supported on twitter.com):
19
+
20
+ ```ruby
21
+ TwitterCldr.supported_locales # [:ar, :da, :de, :en, :es, ... ]
22
+ ```
23
+
24
+ Determine if a locale is supported by TwitterCLDR:
25
+
26
+ ```ruby
27
+ TwitterCldr.supported_locale?(:es) # true
28
+ TwitterCldr.supported_locale?(:xx) # false
29
+ ```
30
+
31
+
32
+ TwitterCldr patches core Ruby objects like Fixnum and Date to make localization as straightforward as possible.
7
33
 
8
- CLDR is missing complete number data for:
34
+ ### Numbers
35
+
36
+ **Note**: The CLDR is missing complete number data for:
9
37
 
10
38
  * hu (Hungarian)
11
39
  * id (Indonesian)
@@ -13,43 +41,87 @@ CLDR is missing complete number data for:
13
41
  * no (Norwegian),
14
42
  * zh-tw (Traditional Chinese)
15
43
 
16
- ## Synopsis
17
-
18
- TwitterCldr patches core Ruby objects like Fixnum and Date for an easy localization experience:
19
-
20
- Numbers (Fixnum, Bignum, and Float objects are supported):
44
+ Fixnum, Bignum, and Float objects are supported. Here are some examples:
21
45
 
22
46
  ```ruby
47
+ # default formatting with to_s
23
48
  1337.localize(:es).to_s # 1.337
49
+
50
+ # currencies, default USD
24
51
  1337.localize(:es).to_currency.to_s # $1.337,00
25
52
  1337.localize(:es).to_currency.to_s(:currency => "EUR") # €1.337,00
26
53
  1337.localize(:es).to_currency.to_s(:currency => "Peru") # S/.1.337,00
54
+
55
+ # percentages
27
56
  1337.localize(:es).to_percent.to_s # 1.337%
28
57
  1337.localize(:es).to_percent.to_s(:precision => 2) # 1.337,00%
58
+
59
+ # decimals
60
+ 1337.localize(:es).to_decimal.to_s(:precision => 3) # 1.337,000
61
+ ```
62
+
63
+ **Note**: The :precision option can be used with all these number formatters.
64
+
65
+ Behind the scenes, these convenience methods are creating instances of LocalizedNumber. You can do the same thing if you're feeling adventurous:
66
+
67
+ ```ruby
68
+ num = TwitterCldr::LocalizedNumber.new(1337, :es)
69
+ num.to_currency.to_s # ...etc
70
+ ```
71
+
72
+ #### More on Currencies
73
+
74
+ If you're looking for a list of supported countries and currencies, use the TwitterCldr::Shared::Currencies class:
75
+
76
+ ```ruby
77
+ # all supported countries
78
+ TwitterCldr::Shared::Currencies.countries # ["Lithuania", "Philippines", ... ]
79
+
80
+ # all supported currency codes
81
+ TwitterCldr::Shared::Currencies.currency_codes # ["LTL", "PHP" ... ]
82
+
83
+ # data for a specific country
84
+ TwitterCldr::Shared::Currencies.for_country("Canada") # { :currency => "Dollar", :symbol => "$", :code => "CAD" }
85
+
86
+ # data for a specific currency code
87
+ TwitterCldr::Shared::Currencies.for_code("CAD") # { :currency => "Dollar", :symbol => "$", :code => "CAD" }
88
+ ```
89
+
90
+ ### Dates and Times
91
+
92
+ Date, Time, and DateTime objects are supported:
93
+
94
+ ```ruby
95
+ DateTime.now.localize(:es).to_full_s # "21:44:57 UTC -0800 lunes 12 de diciembre de 2011"
96
+ DateTime.now.localize(:es).to_long_s # "21:45:42 -08:00 12 de diciembre de 2011"
97
+ DateTime.now.localize(:es).to_medium_s # "21:46:09 12/12/2011"
98
+ DateTime.now.localize(:es).to_short_s # "21:47 12/12/11"
99
+
100
+ Date.today.localize(:es).to_full_s # "lunes 12 de diciembre de 2011"
101
+ Date.today.localize(:es).to_long_s # "12 de diciembre de 2011"
102
+ Date.today.localize(:es).to_medium_s # "12/12/2011"
103
+ Date.today.localize(:es).to_short_s # "12/12/11"
104
+
105
+ Time.now.localize(:es).to_full_s # "21:44:57 UTC -0800"
106
+ Time.now.localize(:es).to_long_s # "21:45:42 -08:00"
107
+ Time.now.localize(:es).to_medium_s # "21:46:09"
108
+ Time.now.localize(:es).to_short_s # "21:47"
29
109
  ```
30
110
 
31
- NOTE: The :precision option can be used with all these number formatters.
111
+ The CLDR data set only includes 4 specific date formats, full, long, medium, and short, so you'll have to choose amongst them for the one that best fits your needs. Yes, it's limiting, but the 4 formats get the job done most of the time :)
32
112
 
33
- Dates and Times (Date, Time, and DateTime objects are supported):
113
+ Behind the scenes, these convenience methods are creating instances of LocalizedDate, LocalizedTime, and LocalizedDateTime. You can do the same thing if you're feeling adventurous:
34
114
 
35
115
  ```ruby
36
- DateTime.now.localize(:es).to_full_s # 21:44:57 UTC -0800 lunes 12 de diciembre de 2011
37
- DateTime.now.localize(:es).to_long_s # 21:45:42 -08:00 12 de diciembre de 2011
38
- DateTime.now.localize(:es).to_medium_s # 21:46:09 12/12/2011
39
- DateTime.now.localize(:es).to_short_s # 21:47 12/12/11
40
-
41
- Date.today.localize(:es).to_full_s # lunes 12 de diciembre de 2011
42
- Date.today.localize(:es).to_long_s # 12 de diciembre de 2011
43
- Date.today.localize(:es).to_medium_s # 12/12/2011
44
- Date.today.localize(:es).to_short_s # 12/12/11
45
-
46
- Time.now.localize(:es).to_full_s # 21:44:57 UTC -0800
47
- Time.now.localize(:es).to_long_s # 21:45:42 -08:00
48
- Time.now.localize(:es).to_medium_s # 21:46:09
49
- Time.now.localize(:es).to_short_s # 21:47
116
+ dt = TwitterCldr::LocalizedDateTime.new(DateTime.now, :es)
117
+ dt.to_short_s # ...etc
50
118
  ```
51
119
 
52
- Plural Rules:
120
+ ### Plural Rules
121
+
122
+ Some languages, like English, have "countable" nouns. You probably know this concept better as "plural" and "singular", i.e. the difference between "strawberry" and "strawberries". Other languages, like Russian, have three plural forms: one (numbers ending in 1), few (numbers ending in 2, 3, or 4), and many (everything else). Still other languages like Japanese don't use countable nouns at all.
123
+
124
+ TwitterCLDR makes it easy to find the plural rules for any numeric value:
53
125
 
54
126
  ```ruby
55
127
  1.localize(:ru).plural_rule # :one
@@ -57,27 +129,109 @@ Plural Rules:
57
129
  5.localize(:ru).plural_rule # :many
58
130
  ```
59
131
 
60
- World Languages:
132
+ Behind the scenes, these convenience methods use the TwitterCldr::Formatters::Plurals::Rules class. You can do the same thing (and a bit more) if you're feeling adventurous:
133
+
134
+ ```ruby
135
+ # get all rules for the default locale
136
+ TwitterCldr::Formatters::Plurals::Rules.all # [:one, ... ]
137
+
138
+ # get all rules for a specific locale
139
+ TwitterCldr::Formatters::Plurals::Rules.all_for(:es) # [:one, :other]
140
+ TwitterCldr::Formatters::Plurals::Rules.all_for(:ru) # [:one, :few, :many, :other]
141
+
142
+ # get the rule for a number in a specific locale
143
+ TwitterCldr::Formatters::Plurals::Rules.rule_for(1, :ru) # :one
144
+ TwitterCldr::Formatters::Plurals::Rules.rule_for(2, :ru) # :few
145
+ ```
146
+
147
+ ### World Languages
148
+
149
+ You can use the localize convenience method on language code symbols to get their equivalents in another language:
150
+
151
+ ```ruby
152
+ :es.localize(:es).as_language_code # "español"
153
+ :ru.localize(:es).as_langauge_code # "ruso"
154
+ ```
155
+
156
+ Behind the scenes, these convenience methods are creating instances of LocalizedSymbol. You can do the same thing if you're feeling adventurous:
157
+
158
+ ```ruby
159
+ ls = LocalizedSymbol.new(:ru, :es)
160
+ ls.as_language_code # "ruso"
161
+ ```
162
+
163
+ In addition to translating language codes, TwitterCLDR provides access to the full set of supported languages via the TwitterCldr::Shared::Languages class:
164
+
165
+ ```ruby
166
+ # get all languages for the default locale
167
+ TwitterCldr::Shared::Languages.all # { ... :"zh-Hant" => "Traditional Chinese", :vi => "Vietnamese" ... }
168
+
169
+ # get all languages for a specific locale
170
+ TwitterCldr::Shared::Languages.all_for(:es) # { ... :"zh-Hant" => "chino tradicional", :vi => "vietnamita" ... }
171
+
172
+ # get a language by its code for the default locale
173
+ TwitterCldr::Shared::Languages.from_code(:'zh-Hant') # "Traditional Chinese"
174
+
175
+ # get a language from its code for a specific locale
176
+ TwitterCldr::Shared::Languages.from_code_for_locale(:'zh-Hant', :es) # "chino tradicional"
177
+
178
+ # translate a language from one locale to another
179
+ # signature: translate_language(lang, source_locale, destination_locale)
180
+ TwitterCldr::Shared::Languages.translate_language("chino tradicional", :es, :en) # "Traditional Chinese"
181
+ TwitterCldr::Shared::Languages.translate_language("Traditional Chinese", :en, :es) # "chino tradicional"
182
+ ```
183
+
184
+ ## About Twitter-specific Locales
185
+
186
+ Twitter tries to always use BCP-47 language codes. Data from the CLDR doesn't always match those codes, so TwitterCLDR provides a `convert_locale` method to convert between the two. All functionality throughout the entire gem defers to `convert_locale` before retrieving CLDR data. `convert_locale` supports Twitter-supported BCP-47 language codes as well as CLDR locale codes, so you don't have to guess which one to use. Here are a few examples:
187
+
188
+ ```ruby
189
+ TwitterCldr.convert_locale(:'zh-cn') # :zh
190
+ TwitterCldr.convert_locale(:zh) # :zh
191
+ TwitterCldr.convert_locale(:'zh-tw') # :'zh-Hant'
192
+ TwitterCldr.convert_locale(:'zh-Hant') # :'zh-Hant'
193
+
194
+ TwitterCldr.convert_locale(:msa) # :ms
195
+ TwitterCldr.convert_locale(:ms) # :ms
196
+ ```
197
+
198
+ There are a few functions in TwitterCLDR that don't require a locale code, and instead use the default locale by calling `TwitterCldr.get_locale`. The `get_locale` function defers to `FastGettext.locale` when the FastGettext library is available, and falls back on :en (English) when it's not. (Twitter uses the FastGettext gem to retrieve translations efficiently in Ruby).
61
199
 
62
200
  ```ruby
63
- :es.localize(:es).as_language_code # español
201
+ TwitterCldr.get_locale # will return :en
202
+
203
+ require 'fast_gettext'
204
+ FastGettext.locale = "ru"
205
+
206
+ TwitterCldr.get_locale # will return :ru
64
207
  ```
65
208
 
66
209
  ## Requirements
67
210
 
68
211
  No external requirements.
69
212
 
70
- ## Installation
213
+ ## Running Tests
71
214
 
72
- `gem install twitter_cldr`
215
+ `bundle exec rake` should do the trick. Tests are written in RSpec using RR as the mocking framework.
73
216
 
74
217
  ## Authors
75
218
 
76
219
  * Cameron C. Dutro: http://github.com/camertron
77
- * Sven Fuchs: http://github.com/svenfuchs
220
+ * Portions taken from the ruby-cldr gem by Sven Fuchs: http://github.com/svenfuchs/ruby-cldr
221
+
222
+ ## Links
223
+ * ruby-cldr gem: [http://github.com/svenfuchs/ruby-cldr](http://github.com/svenfuchs/ruby-cldr)
224
+ * fast_gettext gem: [https://github.com/grosser/fast_gettext](https://github.com/grosser/fast_gettext)
225
+ * CLDR homepage: [http://cldr.unicode.org/](http://cldr.unicode.org/)
78
226
 
79
227
  ## License
80
228
 
81
229
  Copyright 2012 Twitter, Inc.
82
230
 
83
231
  Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
232
+
233
+ ## Future Plans
234
+
235
+ * Add Javascript support
236
+ * Implement algorithms for Unicode normalization, collation, and capitalization
237
+ * Patch Ruby 1.8 strings to provide better Unicode support (probably using pack and unpack).
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class Date
2
4
  def localize(locale = TwitterCldr.get_locale)
3
5
  TwitterCldr::LocalizedDate.new(self, locale)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class DateTime
2
4
  def localize(locale = TwitterCldr.get_locale)
3
5
  TwitterCldr::LocalizedDateTime.new(self, locale)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class Time
2
4
  def localize(locale = TwitterCldr.get_locale)
3
5
  TwitterCldr::LocalizedTime.new(self, locale)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  class LocalizedObject
3
5
  attr_reader :locale, :base_obj, :formatter
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class Bignum
2
4
  include TwitterCldr::LocalizedNumberMixin
3
5
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class Fixnum
2
4
  include TwitterCldr::LocalizedNumberMixin
3
5
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class Float
2
4
  include TwitterCldr::LocalizedNumberMixin
3
5
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module LocalizedNumberMixin
3
5
  def localize(locale = TwitterCldr.get_locale)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class Symbol
2
4
  def localize(locale = TwitterCldr.get_locale)
3
5
  TwitterCldr::LocalizedSymbol.new(self, locale)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  class Base
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  class DateFormatter < DateTimeFormatter
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  # This class has been adapted from Sven Fuch's ruby-cldr gem
2
4
  # See LICENSE for the accompanying license for his contributions
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  class TimeFormatter < DateTimeFormatter
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  class CurrencyFormatter < NumberFormatter
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  class DecimalFormatter < NumberFormatter
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  module Numbers
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  module Numbers
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  module Numbers
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  class NumberFormatter < Base
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  class PercentFormatter < NumberFormatter
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Formatters
3
5
  module Plurals
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Shared
3
5
  class Currencies
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Shared
3
5
  class Languages
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Shared
3
5
  class Resources
@@ -1 +1,3 @@
1
+ # encoding: UTF-8
2
+
1
3
  # not yet implemented
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Tokenizers
3
5
  class Base
@@ -50,12 +52,14 @@ module TwitterCldr
50
52
  end
51
53
 
52
54
  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
55
+ needle.to_s.split('.').inject(haystack) do |current, segment|
56
+ key = segment.to_sym
57
+ if current.is_a?(Hash) && current.has_key?(key)
58
+ current[key]
59
+ else
60
+ return
61
+ end
62
+ end
59
63
  end
60
64
 
61
65
  def expand_pattern(format_str, type)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Tokenizers
3
5
  class DateTokenizer < TwitterCldr::Tokenizers::DateTimeTokenizer
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Tokenizers
3
5
  class DateTimeTokenizer < Base
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Tokenizers
3
5
  class TimeTokenizer < TwitterCldr::Tokenizers::DateTimeTokenizer
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Tokenizers
3
5
  class KeyPath
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Tokenizers
3
5
  class NumberTokenizer < Base
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TwitterCldr
2
4
  module Tokenizers
3
5
  class Token
data/lib/twitter_cldr.rb CHANGED
@@ -1,5 +1,9 @@
1
+ # encoding: UTF-8
2
+
1
3
  $:.push(File.dirname(__FILE__))
2
4
 
5
+ $KCODE = 'UTF-8' unless RUBY_VERSION >= '1.9.0'
6
+
3
7
  require 'yaml'
4
8
  require 'date'
5
9
  require 'time'
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TwitterCldr
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
4
  include TwitterCldr::Formatters
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Formatters
3
5
 
@@ -276,7 +278,7 @@ describe DateTimeFormatter do
276
278
  @formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'z', 1).should == 'UTC'
277
279
  @formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'zz', 2).should == 'UTC'
278
280
  @formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'zzz', 3).should == 'UTC'
279
- @formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'zzzz', 4).should match(/UTC\s\-?\d{4}/)
281
+ @formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'zzzz', 4).should =~ /^UTC (-|\+)\d{4}$/
280
282
  end
281
283
  end
282
284
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Formatters
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Formatters
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))), "spec_helper")
2
4
  include TwitterCldr::Formatters::Numbers
3
5
  include TwitterCldr::Tokenizers
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))), "spec_helper")
2
4
  include TwitterCldr::Formatters::Numbers
3
5
  include TwitterCldr::Tokenizers
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Formatters
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Formatters
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Formatters::Plurals
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
4
  include TwitterCldr::Shared
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
4
  include TwitterCldr::Shared
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
4
  include TwitterCldr::Shared
3
5
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib twitter_cldr]))
2
4
  FIXTURE_DIR = File.expand_path(File.join(File.dirname(__FILE__), %w[fixtures]))
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(__FILE__)), "spec_helper")
2
4
  include TwitterCldr::Tokenizers
3
5
 
@@ -12,12 +14,15 @@ end
12
14
 
13
15
  describe Base do
14
16
  before(:each) do
15
- @base = Base.new # do NOT do this in production - must use subclass
17
+ @base = TwitterCldr::Tokenizers::Base.new # do NOT do this in production - must use subclass
16
18
  end
17
19
 
18
- it "creating a new base without a locale should default to English, with a locale should not" do
20
+ it "should use English locale by default" do
19
21
  @base.locale.should == :en
20
- Base.new(:locale => :de).locale.should == :de
22
+ end
23
+
24
+ it "should use provided locale if there is one" do
25
+ TwitterCldr::Tokenizers::Base.new(:locale => :de).locale.should == :de
21
26
  end
22
27
 
23
28
  # tokenize_pattern is supposed to take a pattern found in the YAML resource files and break it into placeholders and plaintext.
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Tokenizers
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Tokenizers
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Tokenizers
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(__FILE__)), "spec_helper")
2
4
  include TwitterCldr::Tokenizers
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
2
4
  include TwitterCldr::Tokenizers
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(File.dirname(__FILE__)), "spec_helper")
2
4
  include TwitterCldr::Tokenizers
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require File.join(File.dirname(__FILE__), "spec_helper")
2
4
 
3
5
  describe TwitterCldr do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_cldr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Cameron Dutro
@@ -15,14 +15,13 @@ autorequire: ""
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-29 00:00:00 -07:00
18
+ date: 2012-04-03 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :development
24
22
  name: rspec
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
28
27
  - - ~>
@@ -33,12 +32,12 @@ dependencies:
33
32
  - 3
34
33
  - 2
35
34
  version: 1.3.2
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- prerelease: false
39
35
  type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
40
38
  name: rr
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
44
43
  - - ~>
@@ -49,12 +48,12 @@ dependencies:
49
48
  - 0
50
49
  - 4
51
50
  version: 1.0.4
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
54
- prerelease: false
55
51
  type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
56
54
  name: rake
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
58
57
  none: false
59
58
  requirements:
60
59
  - - ~>
@@ -65,7 +64,8 @@ dependencies:
65
64
  - 8
66
65
  - 7
67
66
  version: 0.8.7
68
- requirement: *id003
67
+ type: :development
68
+ version_requirements: *id003
69
69
  description: Provides date, time, number, and list formatting functionality for various Twitter-supported locales in Ruby and Javascript.
70
70
  email:
71
71
  - cdutro@twitter.com