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
data/LICENSE
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
data/NOTICE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
twitter-cldr-rb is a Ruby implementation of the Common Locale Data Repository
|
2
|
+
Copyright (C) 2012 Twitter, Inc.
|
3
|
+
|
4
|
+
Portions of this gem were borrowed from Sven Fuchs' ruby-cldr gem. Here is
|
5
|
+
the license that accompanied Mr. Fuchs' code:
|
6
|
+
|
7
|
+
Copyright (c) 2009 Sven Fuchs
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
a copy of this software and associated documentation files (the
|
11
|
+
"Software"), to deal in the Software without restriction, including
|
12
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
14
|
+
permit persons to whom the Software is furnished to do so, subject to
|
15
|
+
the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be
|
18
|
+
included in all copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
24
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
25
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
26
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
## twitter-cldr-rb
|
2
|
+
|
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.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
|
8
|
+
CLDR is missing complete number data for:
|
9
|
+
|
10
|
+
* hu (Hungarian)
|
11
|
+
* id (Indonesian)
|
12
|
+
* msa (Malay)
|
13
|
+
* no (Norwegian),
|
14
|
+
* zh-tw (Traditional Chinese)
|
15
|
+
|
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):
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
1337.localize(:es).to_s # 1.337
|
24
|
+
1337.localize(:es).to_currency.to_s # $1.337,00
|
25
|
+
1337.localize(:es).to_currency.to_s(:currency => "EUR") # €1.337,00
|
26
|
+
1337.localize(:es).to_currency.to_s(:currency => "Peru") # S/.1.337,00
|
27
|
+
1337.localize(:es).to_percent.to_s # 1.337%
|
28
|
+
1337.localize(:es).to_percent.to_s(:precision => 2) # 1.337,00%
|
29
|
+
```
|
30
|
+
|
31
|
+
NOTE: The :precision option can be used with all these number formatters.
|
32
|
+
|
33
|
+
Dates and Times (Date, Time, and DateTime objects are supported):
|
34
|
+
|
35
|
+
```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
|
50
|
+
```
|
51
|
+
|
52
|
+
Plural Rules:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
1.localize(:ru).plural_rule # :one
|
56
|
+
2.localize(:ru).plural_rule # :few
|
57
|
+
5.localize(:ru).plural_rule # :many
|
58
|
+
```
|
59
|
+
|
60
|
+
World Languages:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
:es.localize(:es).as_language_code # español
|
64
|
+
```
|
65
|
+
|
66
|
+
## Requirements
|
67
|
+
|
68
|
+
No external requirements.
|
69
|
+
|
70
|
+
## Installation
|
71
|
+
|
72
|
+
`gem install twitter_cldr`
|
73
|
+
|
74
|
+
## Authors
|
75
|
+
|
76
|
+
* Cameron C. Dutro: http://github.com/camertron
|
77
|
+
* Sven Fuchs: http://github.com/svenfuchs
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
Copyright 2012 Twitter, Inc.
|
82
|
+
|
83
|
+
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rubygems/specification'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
require 'spec/rake/verify_rcov'
|
7
|
+
require 'digest'
|
8
|
+
|
9
|
+
spec = Gem::Specification.load("#{File.dirname(__FILE__)}/twitter_cldr.gemspec")
|
10
|
+
|
11
|
+
task :default => :spec
|
12
|
+
|
13
|
+
desc "Run specs"
|
14
|
+
Spec::Rake::SpecTask.new do |t|
|
15
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
16
|
+
t.spec_opts = %w(-fs --color)
|
17
|
+
t.libs << ["spec", '.']
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run all examples with RCov"
|
21
|
+
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
22
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
t.rcov = true
|
24
|
+
t.rcov_opts = ['-T', '--sort', 'coverage', '--exclude', 'gems/*,spec/*']
|
25
|
+
end
|
26
|
+
|
27
|
+
# Gem tasks
|
28
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
29
|
+
pkg.gem_spec = spec
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "install the gem locally"
|
33
|
+
task :install => [:package] do
|
34
|
+
sh %{gem install pkg/#{spec.name}-#{spec.version}}
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Date
|
2
|
+
def localize(locale = TwitterCldr.get_locale)
|
3
|
+
TwitterCldr::LocalizedDate.new(self, locale)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module TwitterCldr
|
8
|
+
class LocalizedDate < LocalizedDateTime
|
9
|
+
def to_datetime(time)
|
10
|
+
time_obj = time.is_a?(LocalizedTime) ? time.base_obj : time
|
11
|
+
LocalizedDateTime.new(DateTime.parse("#{@base_obj.strftime("%Y-%m-%d")}T#{time_obj.strftime("%H:%M:%S%z")}"), @locale)
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def formatter_const
|
17
|
+
TwitterCldr::Formatters::DateFormatter
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class DateTime
|
2
|
+
def localize(locale = TwitterCldr.get_locale)
|
3
|
+
TwitterCldr::LocalizedDateTime.new(self, locale)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module TwitterCldr
|
8
|
+
class LocalizedDateTime < LocalizedObject
|
9
|
+
def method_missing(method, *args, &block)
|
10
|
+
type = method.to_s.match(/to_(\w+)_s/)[1]
|
11
|
+
if type && !type.empty? && TwitterCldr::Tokenizers::DateTimeTokenizer::VALID_TYPES.include?(type.to_sym)
|
12
|
+
@formatter.format(@base_obj, :type => type.to_sym)
|
13
|
+
else
|
14
|
+
raise "Method not supported"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
self.to_default_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_date
|
23
|
+
LocalizedDate.new(Date.parse(@base_obj.strftime("%Y-%m-%dT%H:%M:%S%z")), @locale)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_time
|
27
|
+
LocalizedTime.new(Time.parse(@base_obj.strftime("%Y-%m-%dT%H:%M:%S%z")), @locale)
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def formatter_const
|
33
|
+
TwitterCldr::Formatters::DateTimeFormatter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Time
|
2
|
+
def localize(locale = TwitterCldr.get_locale)
|
3
|
+
TwitterCldr::LocalizedTime.new(self, locale)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module TwitterCldr
|
8
|
+
class LocalizedTime < LocalizedDateTime
|
9
|
+
def to_datetime(date)
|
10
|
+
date_obj = date.is_a?(LocalizedDate) ? date.base_obj : date
|
11
|
+
LocalizedDateTime.new(DateTime.parse("#{date_obj.strftime("%Y-%m-%d")}T#{@base_obj.strftime("%H:%M:%S%z")}"), @locale)
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def formatter_const
|
17
|
+
TwitterCldr::Formatters::TimeFormatter
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
class LocalizedObject
|
3
|
+
attr_reader :locale, :base_obj, :formatter
|
4
|
+
|
5
|
+
def initialize(obj, locale)
|
6
|
+
@base_obj = obj
|
7
|
+
@locale = locale
|
8
|
+
@formatter = self.formatter_const.new(:locale => @locale) if self.formatter_const
|
9
|
+
end
|
10
|
+
|
11
|
+
def formatter_const
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module LocalizedNumberMixin
|
3
|
+
def localize(locale = TwitterCldr.get_locale)
|
4
|
+
TwitterCldr::LocalizedNumber.new(self, locale)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class LocalizedNumber < LocalizedObject
|
9
|
+
DEFAULT_TYPE = :decimal
|
10
|
+
attr_reader :type
|
11
|
+
|
12
|
+
def to_decimal(options = {})
|
13
|
+
self.setup_for(:decimal)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_currency(options = {})
|
18
|
+
self.setup_for(:currency)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_percent(options = {})
|
23
|
+
self.setup_for(:percent)
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def plural_rule
|
28
|
+
TwitterCldr::Formatters::Plurals::Rules.rule_for(@base_obj, @locale)
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s(options = {})
|
32
|
+
opts = options
|
33
|
+
opts = { :precision => 0 }.merge(opts) if @base_obj.is_a?(Fixnum)
|
34
|
+
@formatter.format(@base_obj, opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def plural_rule
|
38
|
+
TwitterCldr::Formatters::Plurals::Rules.rule_for(@base_obj, @locale)
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def formatter_const
|
44
|
+
TwitterCldr::Formatters::DecimalFormatter
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_for(type)
|
48
|
+
@type = type
|
49
|
+
fmt_class = TwitterCldr::Formatters.const_get("#{(@type || DEFAULT_TYPE).to_s.capitalize}Formatter".to_sym)
|
50
|
+
@formatter = fmt_class.new(:locale => locale.to_sym)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Symbol
|
2
|
+
def localize(locale = TwitterCldr.get_locale)
|
3
|
+
TwitterCldr::LocalizedSymbol.new(self, locale)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module TwitterCldr
|
8
|
+
class LocalizedSymbol < LocalizedObject
|
9
|
+
def as_language_code
|
10
|
+
TwitterCldr::Shared::Languages.from_code_for_locale(@base_obj, @locale)
|
11
|
+
end
|
12
|
+
|
13
|
+
def formatter_const
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module TwitterCldr
|
2
|
+
module Formatters
|
3
|
+
class Base
|
4
|
+
attr_reader :tokenizer
|
5
|
+
|
6
|
+
def format(obj, options = {})
|
7
|
+
final = StringIO.new
|
8
|
+
|
9
|
+
result = self.get_tokens(obj, options).each_with_index do |token, index|
|
10
|
+
case token.type
|
11
|
+
when :pattern
|
12
|
+
final << self.result_for_token(token, index, obj)
|
13
|
+
else
|
14
|
+
if token.value.size > 0 && token.value[0].chr == "'" && token.value[-1].chr == "'"
|
15
|
+
final << token.value[1..-2]
|
16
|
+
else
|
17
|
+
final << token.value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
final.string
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def get_tokens(obj, options = {})
|
28
|
+
@tokenizer.tokens(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract_locale(options)
|
32
|
+
options[:locale] || TwitterCldr::DEFAULT_LOCALE
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|