twitter_cldr_js 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/History.txt +3 -0
- data/LICENSE +177 -0
- data/NOTICE +120 -0
- data/README.md +161 -0
- data/Rakefile +66 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_af.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ar.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ca.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_cs.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_da.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_de.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_el.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_es.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_eu.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fa.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fi.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fil.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fr.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_he.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hi.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hu.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_id.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_it.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ja.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ko.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_msa.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_nl.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_no.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pl.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pt.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ru.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_sv.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_th.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_tr.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_uk.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ur.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-cn.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-tw.js +887 -0
- data/lib/twitter_cldr/js/compiler.rb +49 -0
- data/lib/twitter_cldr/js/mustache/bundle.coffee +15 -0
- data/lib/twitter_cldr/js/mustache/calendars/datetime.coffee +240 -0
- data/lib/twitter_cldr/js/mustache/calendars/timespan.coffee +52 -0
- data/lib/twitter_cldr/js/mustache/numbers/numbers.coffee +179 -0
- data/lib/twitter_cldr/js/mustache/plurals/rules.coffee +14 -0
- data/lib/twitter_cldr/js/mustache/shared/currencies.coffee +27 -0
- data/lib/twitter_cldr/js/renderers/base.rb +18 -0
- data/lib/twitter_cldr/js/renderers/bundle.rb +18 -0
- data/lib/twitter_cldr/js/renderers/calendars/datetime_renderer.rb +34 -0
- data/lib/twitter_cldr/js/renderers/calendars/timespan_renderer.rb +39 -0
- data/lib/twitter_cldr/js/renderers/numbers/numbers_renderer.rb +31 -0
- data/lib/twitter_cldr/js/renderers/plurals/rules/plural_rules_compiler.rb +93 -0
- data/lib/twitter_cldr/js/renderers/plurals/rules/plural_rules_renderer.rb +26 -0
- data/lib/twitter_cldr/js/renderers/shared/currencies_renderer.rb +23 -0
- data/lib/twitter_cldr/js/renderers.rb +31 -0
- data/lib/twitter_cldr/js/tasks/tasks.rake +14 -0
- data/lib/twitter_cldr/js/tasks/tasks.rb +88 -0
- data/lib/twitter_cldr/js/version.rb +10 -0
- data/lib/twitter_cldr/js.rb +31 -0
- data/spec/js/calendars/datetime.spec.js +418 -0
- data/spec/js/calendars/timespan.spec.js +91 -0
- data/spec/js/numbers/currency.spec.js +34 -0
- data/spec/js/numbers/decimal.spec.js +24 -0
- data/spec/js/numbers/helpers/fraction.spec.js +23 -0
- data/spec/js/numbers/helpers/integer.spec.js +100 -0
- data/spec/js/numbers/number.spec.js +70 -0
- data/spec/js/numbers/percent.spec.js +22 -0
- data/spec/js/plurals/plural_rules.spec.js +28 -0
- data/spec/ruby/renderers/plurals/plural_rules_compiler_spec.rb +56 -0
- data/spec/ruby/spec_helper.rb +11 -0
- data/twitter_cldr_js.gemspec +34 -0
- metadata +224 -0
data/Gemfile
ADDED
data/History.txt
ADDED
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,120 @@
|
|
1
|
+
twitter-cldr-rb is a Ruby implementation of the Common Locale Data Repository
|
2
|
+
Copyright (C) 2012 Twitter, Inc.
|
3
|
+
|
4
|
+
|
5
|
+
Portions of this gem were borrowed from Sven Fuchs' ruby-cldr gem. Here is
|
6
|
+
the license that accompanied Mr. Fuchs' code:
|
7
|
+
|
8
|
+
Copyright (c) 2009 Sven Fuchs
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
11
|
+
a copy of this software and associated documentation files (the
|
12
|
+
"Software"), to deal in the Software without restriction, including
|
13
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
14
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to
|
16
|
+
the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be
|
19
|
+
included in all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
22
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
24
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
25
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
26
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28
|
+
|
29
|
+
|
30
|
+
Backporting of String interpolation from Ruby 1.9 to Ruby 1.8 implemented in
|
31
|
+
this gem (see file interpolation.rb) was partially copied and heavily based
|
32
|
+
on the implementation of i18n and gettext gems. Below are the license agreements
|
33
|
+
that accompanied these gems.
|
34
|
+
|
35
|
+
License agreement of the i18n gem (https://github.com/svenfuchs/i18n):
|
36
|
+
|
37
|
+
Copyright (c) 2008 The Ruby I18n team
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
"Software"), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
53
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
54
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
55
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
56
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
57
|
+
|
58
|
+
License of the gettext gem (https://github.com/mutoh/gettext):
|
59
|
+
|
60
|
+
Copyright (C) 2005-2009 Masao Mutoh
|
61
|
+
|
62
|
+
You may redistribute it [the code] and/or modify it under the same license
|
63
|
+
terms as Ruby or LGPL [http://www.gnu.org/licenses/lgpl-3.0.txt].
|
64
|
+
|
65
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
66
|
+
You can redistribute it and/or modify it under either the terms of the GPL
|
67
|
+
version 2 (see the file GPL), or the conditions below:
|
68
|
+
|
69
|
+
1. You may make and give away verbatim copies of the source form of the
|
70
|
+
software without restriction, provided that you duplicate all of the
|
71
|
+
original copyright notices and associated disclaimers.
|
72
|
+
|
73
|
+
2. You may modify your copy of the software in any way, provided that
|
74
|
+
you do at least ONE of the following:
|
75
|
+
|
76
|
+
a) place your modifications in the Public Domain or otherwise
|
77
|
+
make them Freely Available, such as by posting said
|
78
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
79
|
+
the author to include your modifications in the software.
|
80
|
+
|
81
|
+
b) use the modified software only within your corporation or
|
82
|
+
organization.
|
83
|
+
|
84
|
+
c) give non-standard binaries non-standard names, with
|
85
|
+
instructions on where to get the original software distribution.
|
86
|
+
|
87
|
+
d) make other distribution arrangements with the author.
|
88
|
+
|
89
|
+
3. You may distribute the software in object code or binary form,
|
90
|
+
provided that you do at least ONE of the following:
|
91
|
+
|
92
|
+
a) distribute the binaries and library files of the software,
|
93
|
+
together with instructions (in the manual page or equivalent)
|
94
|
+
on where to get the original distribution.
|
95
|
+
|
96
|
+
b) accompany the distribution with the machine-readable source of
|
97
|
+
the software.
|
98
|
+
|
99
|
+
c) give non-standard binaries non-standard names, with
|
100
|
+
instructions on where to get the original software distribution.
|
101
|
+
|
102
|
+
d) make other distribution arrangements with the author.
|
103
|
+
|
104
|
+
4. You may modify and include the part of the software into any other
|
105
|
+
software (possibly commercial). But some files in the distribution
|
106
|
+
are not written by the author, so that they are not under these terms.
|
107
|
+
|
108
|
+
For the list of those files and their copying conditions, see the
|
109
|
+
file LEGAL.
|
110
|
+
|
111
|
+
5. The scripts and library files supplied as input to or produced as
|
112
|
+
output from the software do not automatically fall under the
|
113
|
+
copyright of the software, but belong to whomever generated them,
|
114
|
+
and may be sold commercially, and may be aggregated with this
|
115
|
+
software.
|
116
|
+
|
117
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
118
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
119
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
120
|
+
PURPOSE.
|
data/README.md
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
## twitter-cldr-js [![Build Status](https://secure.travis-ci.org/twitter/twitter-cldr-js.png?branch=master)](http://travis-ci.org/twitter/twitter-cldr-js)
|
2
|
+
|
3
|
+
TwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their
|
4
|
+
localized equivalents via the Rails asset pipeline. It is a port of [twitter-cldr-rb](http://github.com/twitter/twitter-cldr-rb), a Ruby gem that uses the same CLDR data. Originally, this project was not a gem, but a collection of JavaScript files. It has been turned into a gem to move the JavaScript compiling routines from twitter-cldr-rb and provide support for the asset pipeline.
|
5
|
+
|
6
|
+
Currently, twitter-cldr-js supports the following:
|
7
|
+
|
8
|
+
1. Date and time formatting
|
9
|
+
2. Relative date and time formatting (eg. 1 month ago)
|
10
|
+
3. Number formatting (decimal, currency, and percentage)
|
11
|
+
4. Plural rules
|
12
|
+
|
13
|
+
## Usage in the Rails Asset Pipeline
|
14
|
+
|
15
|
+
twitter-cldr-js provides a single `.js` file per locale. You can include a locale-specific version (eg. Spanish) in your JavaScript manifest (`app/assets/javascripts/application.js`) like this:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
//= require twitter_cldr/twitter_cldr_es
|
19
|
+
```
|
20
|
+
|
21
|
+
This will make the Spanish version of twitter-cldr-js available to the JavaScript in your app. If your app supports multiple languages however, this single-locale approach won't be much use. Instead, require the right file with `javascript_include_tag` for example in a view or a layout:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
<%= javascript_include_tag "twitter_cldr/twitter_cldr_#{TwitterCldr.convert_locale(I18n.locale)}.js" %>
|
25
|
+
```
|
26
|
+
|
27
|
+
### Dates and Times
|
28
|
+
|
29
|
+
```javascript
|
30
|
+
// include twitter_cldr_es.js for the Spanish DateTimeFormatter
|
31
|
+
var fmt = new TwitterCldr.DateTimeFormatter();
|
32
|
+
|
33
|
+
fmt.format(new Date(), {"type": "full"}); // "lunes, 12 de diciembre de 2011 21:44:57 UTC -0800"
|
34
|
+
fmt.format(new Date(), {"type": "long"}); // "12 de diciembre de 201121:45:42 -08:00"
|
35
|
+
fmt.format(new Date(), {"type": "medium"}); // "12/12/2011 21:46:09"
|
36
|
+
fmt.format(new Date(), {"type": "short"}); // "12/12/11 21:47"
|
37
|
+
|
38
|
+
fmt.format(new Date(), {"format": "date", "type": "full"}); // "lunes, 12 de diciembre de 2011"
|
39
|
+
fmt.format(new Date(), {"format": "date", "type": "long"}); // "12 de diciembre de 2011"
|
40
|
+
fmt.format(new Date(), {"format": "date", "type": "medium"}); // "12/12/2011"
|
41
|
+
fmt.format(new Date(), {"format": "date", "type": "short"}); // "12/12/11"
|
42
|
+
|
43
|
+
fmt.format(new Date(), {"format": "time", "type": "full"}); // "21:44:57 UTC -0800"
|
44
|
+
fmt.format(new Date(), {"format": "time", "type": "long"}); // "21:45:42 -08:00"
|
45
|
+
fmt.format(new Date(), {"format": "time", "type": "medium"}); // "21:46:09"
|
46
|
+
fmt.format(new Date(), {"format": "time", "type": "short"}); // "21:47"
|
47
|
+
```
|
48
|
+
|
49
|
+
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 :)
|
50
|
+
|
51
|
+
### Relative Dates and Times
|
52
|
+
|
53
|
+
In addition to formatting full dates and times, TwitterCLDR supports relative time spans. It tries to guess the best time unit (eg. days, hours, minutes, etc) based on the length of time given. Indicate past or future by using negative or positive numbers respectively:
|
54
|
+
|
55
|
+
```javascript
|
56
|
+
// include twitter_cldr_en.js for the English TimespanFormatter
|
57
|
+
var fmt = new TwitterCldr.TimespanFormatter();
|
58
|
+
var then = Math.round(new Date(2012, 1, 1, 12, 0, 0).getTime() / 1000);
|
59
|
+
var now = Math.round(Date.now() / 1000);
|
60
|
+
|
61
|
+
fmt.format(then - now); // "6 months ago"
|
62
|
+
fmt.format(then - now, {unit: "week"}); // "24 weeks ago"
|
63
|
+
fmt.format(then - now, {unit: "year"}); // "0 years ago"
|
64
|
+
fmt.format(then + now, {unit: "week"}); // "In 24 weeks"
|
65
|
+
fmt.format(then + now, {unit: "year"}); // "In 0 years"
|
66
|
+
```
|
67
|
+
|
68
|
+
The `TimespanFormatter` can also handle time spans without a direction via the `direction: "none"` option. Directionless timespans can be combined with the `type` option:
|
69
|
+
|
70
|
+
```javascript
|
71
|
+
fmt.format(180, {direction: "none", type: "short"}); // "3 mins"
|
72
|
+
fmt.format(180, {direction: "none", type: "abbreviated"}); // "3m"
|
73
|
+
fmt.format(180, {direction: "none", type: "short", unit: "second"}); // "180 secs"
|
74
|
+
```
|
75
|
+
|
76
|
+
### Numbers
|
77
|
+
|
78
|
+
twitter-cldr-js number formatting supports decimals, currencies, and percentages.
|
79
|
+
|
80
|
+
#### Decimals
|
81
|
+
|
82
|
+
```javascript
|
83
|
+
// include twitter_cldr_es.js for the Spanish NumberFormatter
|
84
|
+
var fmt = new TwitterCldr.DecimalFormatter();
|
85
|
+
fmt.format(1337); // "1.337"
|
86
|
+
fmt.format(-1337); // "-1.337"
|
87
|
+
fmt.format(1337, {precision: 2}); // "1.337,00"
|
88
|
+
```
|
89
|
+
|
90
|
+
#### Currencies
|
91
|
+
|
92
|
+
```javascript
|
93
|
+
var fmt = new TwitterCldr.CurrencyFormatter();
|
94
|
+
fmt.format(1337, {currency: "EUR"}); // 1.337,00 €
|
95
|
+
fmt.format(1337, {currency: "Peru"}); // 1.337,00 S/.
|
96
|
+
fmt.format(1337, {currency: "Peru", precision: 3}); // 1.337,000 S/.
|
97
|
+
```
|
98
|
+
|
99
|
+
#### Percentages
|
100
|
+
|
101
|
+
```javascript
|
102
|
+
var fmt = new TwitterCldr.PercentFormatter();
|
103
|
+
fmt.format(1337); // 1.337%
|
104
|
+
fmt.format(1337, {precision: 2}); // 1.337,00%
|
105
|
+
```
|
106
|
+
|
107
|
+
### Plural Rules
|
108
|
+
|
109
|
+
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.
|
110
|
+
|
111
|
+
TwitterCLDR makes it easy to find the plural rules for any numeric value:
|
112
|
+
|
113
|
+
```javascript
|
114
|
+
// include twitter_cldr_ru.js for access to Russian Plural rules
|
115
|
+
TwitterCldr.PluralRules.rule_for(1); // "one"
|
116
|
+
TwitterCldr.PluralRules.rule_for(2); // "few"
|
117
|
+
TwitterCldr.PluralRules.rule_for(8); // "many"
|
118
|
+
```
|
119
|
+
|
120
|
+
Get all the rules for your language:
|
121
|
+
|
122
|
+
```javascript
|
123
|
+
TwitterCldr.PluralRules.all(); // ["one", "few", "many", "other"]
|
124
|
+
```
|
125
|
+
|
126
|
+
### Generating the JavaScript
|
127
|
+
|
128
|
+
The JavaScript files that make up twitter-cldr-js can be automatically generated for each language via a set of Rake tasks.
|
129
|
+
|
130
|
+
* Build js files in the current directory: `bundle exec rake twitter_cldr:compile`
|
131
|
+
* Build js files into a given directory: `bundle exec rake twitter_cldr:compile OUTPUT_DIR=/path/to/output/dir`
|
132
|
+
* Build only the specified locales: `bundle exec rake twitter_cldr:compile OUTPUT_DIR=/path/to/output/dir LOCALES=ar,he,ko,ja`
|
133
|
+
|
134
|
+
* Rebuild the js files internally in the gem: `bundle exec rake twitter_cldr:update`
|
135
|
+
|
136
|
+
## Requirements
|
137
|
+
|
138
|
+
twitter-cldr-js requires Rails 3.1 or later. To run the JavaScript test suite, you'll need Node and the jasmine-node NPM package.
|
139
|
+
|
140
|
+
## Running Tests
|
141
|
+
|
142
|
+
1. Install node (eg. `brew install node`, `sudo apt-get install node`, etc)
|
143
|
+
2. Install jasmine-node: `npm install jasmine-node -g`
|
144
|
+
2. Run `bundle install`
|
145
|
+
3. Run `bundle exec rake`
|
146
|
+
|
147
|
+
## Authors
|
148
|
+
|
149
|
+
* Cameron C. Dutro: https://github.com/camertron
|
150
|
+
* Portions taken from the ruby-cldr gem by Sven Fuchs: https://github.com/svenfuchs/ruby-cldr
|
151
|
+
|
152
|
+
## Links
|
153
|
+
* twitter-cldr-rb [https://github.com/twitter/twitter-cldr-rb](https://github.com/twitter/twitter-cldr-rb)
|
154
|
+
* ruby-cldr gem: [https://github.com/svenfuchs/ruby-cldr](https://github.com/svenfuchs/ruby-cldr)
|
155
|
+
* CLDR homepage: [http://cldr.unicode.org/](http://cldr.unicode.org/)
|
156
|
+
|
157
|
+
## License
|
158
|
+
|
159
|
+
Copyright 2012 Twitter, Inc.
|
160
|
+
|
161
|
+
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
7
|
+
|
8
|
+
require 'bundler'
|
9
|
+
require 'digest'
|
10
|
+
require 'fileutils'
|
11
|
+
require 'rexml/document'
|
12
|
+
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
require 'rubygems/package_task'
|
15
|
+
|
16
|
+
require './lib/twitter_cldr/js'
|
17
|
+
|
18
|
+
Bundler::GemHelper.install_tasks
|
19
|
+
|
20
|
+
task :default => :spec
|
21
|
+
|
22
|
+
desc 'Run specs'
|
23
|
+
task :spec => ["spec:ruby", "spec:js"]
|
24
|
+
|
25
|
+
desc 'Run Ruby specs'
|
26
|
+
RSpec::Core::RakeTask.new("spec:ruby") do |t|
|
27
|
+
t.pattern = './spec/**/*_spec.rb'
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Run JavaScript specs'
|
31
|
+
task "spec:js" => ["twitter_cldr:update"] do
|
32
|
+
puts "\nJasmine Specs"
|
33
|
+
failures = 0
|
34
|
+
|
35
|
+
if `which jasmine-node`.strip.empty?
|
36
|
+
puts "ERROR: You need to install jasmine-node to run JavaScript tests:"
|
37
|
+
puts " `npm install jasmine-node -g`"
|
38
|
+
exit 1
|
39
|
+
else
|
40
|
+
puts `jasmine-node #{File.dirname(__FILE__)} --junitreport`
|
41
|
+
doc_files = Dir.glob(File.join(File.dirname(__FILE__), "reports/**"))
|
42
|
+
|
43
|
+
doc_files.each do |doc_file|
|
44
|
+
doc = REXML::Document.new(File.read(doc_file))
|
45
|
+
failures += doc.elements.to_a("testsuites/testsuite").inject(0) do |sum, element|
|
46
|
+
sum += element.attributes["failures"].to_i
|
47
|
+
sum
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if failures > 0
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if RUBY_VERSION < '1.9.0'
|
58
|
+
desc 'Run all examples with RCov'
|
59
|
+
RSpec::Core::RakeTask.new('spec:rcov') do |t|
|
60
|
+
t.rcov = true
|
61
|
+
t.pattern = './spec/**/*_spec.rb'
|
62
|
+
t.rcov_opts = %w(-T --sort coverage --exclude gems/,spec/)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
load "./lib/twitter_cldr/js/tasks/tasks.rake"
|