ember-validations-rails-ja 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92d5f3435e21d6a474dde913e705ae382dfc17bd
4
+ data.tar.gz: 69211bbd9258529f3b903e5378588534f8e2018b
5
+ SHA512:
6
+ metadata.gz: 561ffdbce15d070a53af2c0960c0b734d720f457d8b4c21e4316cc6fcca0cf92cc7d16b2009d49b05daed36dc25251dc422ab72da6d9d7c67232cdb279a60107
7
+ data.tar.gz: b938c5c6c1855116890ae21b08da9d6f8bf6f13fe0003cf97cd19c1a52e1f95a3ad6cbf73b79d6607810d67e248a36e1565dec4a1bad9678cfaca39fa153c737
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ember-validations-rails-ja.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 kozo yamagata
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # EmberValidationsRailsJa
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ember-validations-rails-ja'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ember-validations-rails-ja
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/halenohi/ember-validations-rails-ja/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,240 @@
1
+ (function(globals) {
2
+
3
+ Ember.assert('i18n-plurals must be included after i18n.', globals.Ember.I18n != null);
4
+
5
+ // CLDR Pluralization Data
6
+ // see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
7
+
8
+ // The six plural forms. Not all languages use all six forms.
9
+ var Zero = 'zero',
10
+ One = 'one',
11
+ Two = 'two',
12
+ Few = 'few',
13
+ Many = 'many',
14
+ Other = 'other',
15
+ Data = {};
16
+
17
+ function isInt(value) {
18
+ return value << 0 === value;
19
+ }
20
+
21
+ function isAmong(value, array) {
22
+ for ( var i = 0; i < array.length; ++i ) {
23
+ if (array[i] === value) { return true; }
24
+ }
25
+ return false;
26
+ }
27
+
28
+ function defineLanguageRule(languages, rule) {
29
+ for ( var i = 0; i < languages.length; ++i ) {
30
+ Data[ languages[i] ] = rule;
31
+ }
32
+ }
33
+
34
+ defineLanguageRule([
35
+ 'az', 'bm', 'my', 'zh', 'dz', 'ka', 'hu', 'ig', 'id', 'ja', 'jv', 'kea',
36
+ 'kn', 'km', 'ko', 'ses', 'lo', 'kde', 'ms', 'fa', 'root', 'sah', 'sg',
37
+ 'ii', 'th', 'bo', 'to', 'tr', 'vi', 'wo', 'yo'
38
+ ], function(/* n */) {
39
+ return Other;
40
+ });
41
+
42
+ defineLanguageRule([ 'gv' ], function(n) {
43
+ if ( isAmong(n % 10, [ 1, 2 ]) || n % 20 === 0 ) { return One; }
44
+ return Other;
45
+ });
46
+
47
+ defineLanguageRule([ 'tzm' ], function(n) {
48
+ if ( n === 0 || n === 1 ) { return One; }
49
+ if ( isInt(n) && n >= 11 && n <= 99 ) { return One; }
50
+ return Other;
51
+ });
52
+
53
+ defineLanguageRule([ 'mk' ], function(n) {
54
+ return n % 10 === 1 && n !== 11 ? One : Other;
55
+ });
56
+
57
+ defineLanguageRule([ 'fr', 'ff', 'kab' ], function(n) {
58
+ return n >= 0 && n < 2 ? One : Other;
59
+ });
60
+
61
+ defineLanguageRule([
62
+ 'ak', 'am', 'bh', 'fil', 'guw', 'hi', 'ln', 'mg', 'nso', 'tl', 'ti', 'wa'
63
+ ], function(n) {
64
+ return n === 0 || n === 1 ? One : Other;
65
+ });
66
+
67
+ defineLanguageRule([
68
+ 'af', 'sq', 'eu', 'bem', 'bn', 'brx', 'bg', 'ca', 'chr', 'cgg', 'da', 'dv',
69
+ 'nl', 'en', 'eo', 'et', 'ee', 'fo', 'fi', 'fur', 'gl', 'lg', 'de', 'el',
70
+ 'gu', 'ha', 'haw', 'he', 'is', 'it', 'kl', 'kk', 'ku', 'lb', 'ml', 'mr',
71
+ 'mas', 'mn', 'nah', 'ne', 'no', 'nb', 'nn', 'nyn', 'or', 'om', 'pap', 'ps',
72
+ 'pt', 'pa', 'rm', 'ssy', 'saq', 'xog', 'so', 'es', 'sw', 'sv', 'gsw',
73
+ 'syr', 'ta', 'te', 'tk', 'ur', 'wae', 'fy', 'zu'
74
+ ], function(n) {
75
+ return n === 1 ? One : Other;
76
+ });
77
+
78
+ defineLanguageRule([ 'lv' ], function(n) {
79
+ if (n === 0) { return Zero; }
80
+ if (n % 10 === 1 && n % 100 !== 11) { return One; }
81
+ return Other;
82
+ });
83
+
84
+ defineLanguageRule([ 'ksh' ], function(n) {
85
+ if (n === 0) { return Zero; }
86
+ if (n === 1) { return One; }
87
+ return Other;
88
+ });
89
+
90
+ defineLanguageRule([ 'lag' ], function(n) {
91
+ if (n === 0) { return Zero; }
92
+ if (n > 0 && n < 2) { return One; }
93
+ return Other;
94
+ });
95
+
96
+ defineLanguageRule([
97
+ 'kw', 'smn', 'iu', 'ga', 'smj', 'se', 'smi', 'sms', 'sma'
98
+ ], function(n) {
99
+ if (n === 1) { return One; }
100
+ if (n === 2) { return Two; }
101
+ return Other;
102
+ });
103
+
104
+ defineLanguageRule([
105
+ 'be', 'bs', 'hr', 'ru', 'sr', 'sh', 'uk'
106
+ ], function(n) {
107
+ var mod10 = n % 10,
108
+ mod100 = n % 100;
109
+
110
+ if ( mod10 === 1 && n % 100 !== 11 ) { return One; }
111
+
112
+ if ( isAmong(mod10, [ 2, 3, 4 ]) &&
113
+ !isAmong(mod100, [ 12, 13, 14 ]) ) { return Few; }
114
+
115
+ if ( isAmong(mod10, [ 0, 5, 6, 7, 8, 9 ]) ||
116
+ isAmong(mod100, [ 11, 12, 13, 14 ]) ) { return Many; }
117
+
118
+ return Other;
119
+ });
120
+
121
+ defineLanguageRule([ 'pl' ], function(n) {
122
+ var mod10 = n % 10,
123
+ mod100 = n % 100;
124
+
125
+ if ( n === 1 ) { return One; }
126
+
127
+ if ( isAmong(mod10, [ 2, 3, 4 ]) &&
128
+ !isAmong(mod100, [ 12, 13, 14 ]) ) { return Few; }
129
+
130
+ if ( isAmong(mod10, [ 0, 1, 5, 6, 7, 8, 9 ]) ||
131
+ isAmong(mod100, [ 12, 13, 14 ]) ) { return Many; }
132
+
133
+ return Other;
134
+ });
135
+
136
+ defineLanguageRule([ 'lt' ], function(n) {
137
+ var mod10 = n % 10,
138
+ mod100 = n % 100;
139
+
140
+ if ( mod10 === 1 && mod100 !== 11 ) { return One; }
141
+
142
+ if ( isInt(n) &&
143
+ mod10 >= 2 && mod10 <= 9 &&
144
+ mod100 >= 12 && mod100 <= 19 ) { return Few; }
145
+
146
+ return Other;
147
+ });
148
+
149
+ defineLanguageRule([ 'shi' ], function(n) {
150
+ if ( n >= 0 && n <= 1 ) { return One; }
151
+ if ( isInt(n) && n >= 2 && n <= 9 ) { return Few; }
152
+ return Other;
153
+ });
154
+
155
+ defineLanguageRule([ 'mo', 'ro' ], function(n) {
156
+ var mod100 = n % 100;
157
+
158
+ if ( n === 1 ) { return One; }
159
+
160
+ if ( n === 0 ||
161
+ (isInt(n) && mod100 >= 1 && mod100 <= 19) ) { return Few; }
162
+
163
+ return Other;
164
+ });
165
+
166
+ defineLanguageRule([ 'cs', 'sk' ], function(n) {
167
+ if ( n === 1 ) { return One; }
168
+ if ( isAmong(n, [ 2, 3, 4 ]) ) { return Few; }
169
+ return Other;
170
+ });
171
+
172
+ defineLanguageRule([ 'sl' ], function(n) {
173
+ var mod100 = n % 100;
174
+ if ( mod100 === 1 ) { return One; }
175
+ if ( mod100 === 2 ) { return Two; }
176
+ if ( mod100 === 3 || mod100 === 4 ) { return Few; }
177
+ return Other;
178
+ });
179
+
180
+ defineLanguageRule([ 'mt' ], function(n) {
181
+ if ( n === 1 ) { return One; }
182
+ var mod100 = n % 100;
183
+ if ( isInt(mod100) && mod100 >= 2 && mod100 <= 10 ) { return Few; }
184
+ if ( isInt(mod100) && mod100 >= 11 && mod100 <= 19 ) { return Many; }
185
+ return Other;
186
+ });
187
+
188
+ defineLanguageRule([ 'ar' ], function(n) {
189
+ if ( n === 0 ) { return Zero; }
190
+ if ( n === 1 ) { return One; }
191
+ if ( n === 2 ) { return Two; }
192
+ var mod100 = n % 100;
193
+ if ( isInt(mod100) && mod100 >= 3 && mod100 <= 10 ) { return Few; }
194
+ if ( isInt(mod100) && mod100 >= 11 && mod100 <= 99 ) { return Many; }
195
+ return Other;
196
+ });
197
+
198
+ defineLanguageRule([ 'br', 'cy' ], function(n) {
199
+ switch ( n ) {
200
+ case 0: return Zero;
201
+ case 1: return One;
202
+ case 2: return Two;
203
+ case 3: return Few;
204
+ case 6: return Many;
205
+ default: return Other;
206
+ }
207
+ });
208
+
209
+ // Look up the proper plural key for a count and language.
210
+ // If Ember.I18n.locale is set, language is optional.
211
+ //
212
+ // For example:
213
+ //
214
+ // Ember.I18n.pluralForm(0, 'en'); // => 'other'
215
+ // Ember.I18n.pluralForm(1, 'en-US'); // => 'one'
216
+ // Ember.I18n.pluralForm(2.383, 'fr'); // => 'other'
217
+ // Ember.I18n.pluralForm(1, 'zh'); // => 'other'
218
+ // Ember.I18n.pluralForm(26, 'uk'); // => 'many'
219
+ //
220
+ // @return [String] the proper key (one of `Ember.I18n.pluralForm.Zero`,
221
+ // `.One`, `.Two`, `.Few`, `.Many`, or `.Other`).
222
+ function pluralForm(count, language) {
223
+ if (count == null) { throw new Error("Ember.I18n.pluralForm requires a count"); }
224
+ language = language || Ember.I18n.locale;
225
+ if (language == null) { throw new Error("Ember.I18n.pluralForm requires a language"); }
226
+ language = language.replace(/^(\w\w\w?)-?.*/, "$1");
227
+ if (Data[language] == null) { throw new Error("No pluralization information for " + language); }
228
+ return Data[language].call(undefined, +count);
229
+ }
230
+
231
+ pluralForm.Zero = Zero;
232
+ pluralForm.One = One;
233
+ pluralForm.Two = Two;
234
+ pluralForm.Few = Few;
235
+ pluralForm.Many = Many;
236
+ pluralForm.Other = Other;
237
+
238
+ Ember.I18n.pluralForm = pluralForm;
239
+
240
+ }(this));
@@ -0,0 +1,159 @@
1
+ (function() {
2
+ var I18n, assert, findTemplate, get, set, lookupKey,
3
+ EmHandlebars, keyExists;
4
+
5
+ EmHandlebars = Ember.Handlebars;
6
+ get = Ember.get;
7
+ set = Ember.set;
8
+ assert = Ember.assert;
9
+
10
+ lookupKey = function(key, hash) {
11
+ var firstKey, idx, remainingKeys;
12
+
13
+ if (hash[key] != null) { return hash[key]; }
14
+
15
+ if ((idx = key.indexOf('.')) !== -1) {
16
+ firstKey = key.substr(0, idx);
17
+ remainingKeys = key.substr(idx + 1);
18
+ hash = hash[firstKey];
19
+ if (hash) { return lookupKey(remainingKeys, hash); }
20
+ }
21
+ };
22
+
23
+ findTemplate = function(key, setOnMissing) {
24
+ assert("You must provide a translation key string, not %@".fmt(key), typeof key === 'string');
25
+ var result = lookupKey(key, I18n.translations);
26
+
27
+ if (setOnMissing) {
28
+ if (result == null) {
29
+ result = I18n.translations[key] = function() { return I18n.missingMessage(key); };
30
+ result._isMissing = true;
31
+ I18n.trigger('missing', key);
32
+ }
33
+ }
34
+
35
+ if ((result != null) && !Ember.$.isFunction(result)) {
36
+ result = I18n.translations[key] = I18n.compile(result);
37
+ }
38
+
39
+ return result;
40
+ };
41
+
42
+ keyExists = function(key) {
43
+ var translation = lookupKey(key, I18n.translations);
44
+ return translation != null && !translation._isMissing;
45
+ };
46
+
47
+ function eachTranslatedAttribute(object, fn) {
48
+ var isTranslatedAttribute = /(.+)Translation$/,
49
+ isTranslatedAttributeMatch;
50
+
51
+ for (var key in object) {
52
+ isTranslatedAttributeMatch = key.match(isTranslatedAttribute);
53
+ if (isTranslatedAttributeMatch) {
54
+ var translation = object[key] == null ? null : I18n.t(object[key]);
55
+ fn.call(object, isTranslatedAttributeMatch[1], translation);
56
+ }
57
+ }
58
+ }
59
+
60
+ var escapeExpression = EmHandlebars.Utils.escapeExpression;
61
+
62
+ function compileTemplate(template) {
63
+ return function(data) {
64
+ return template
65
+ .replace(/\{\{\{\s*(.*?)\s*\}\}\}/g, function(i, match) {
66
+ // tripple curlies -> no-escaping
67
+ return get(data, match);
68
+ }).replace(/\{\{\s*(.*?)\s*\}\}/g, function(i, match) {
69
+ return escapeExpression( get(data, match) );
70
+ });
71
+ };
72
+ }
73
+
74
+ I18n = Ember.Evented.apply({
75
+ pluralForm: undefined,
76
+
77
+ compile: compileTemplate,
78
+
79
+ translations: {},
80
+
81
+ // Ember.I18n.eachTranslatedAttribute(object, callback)
82
+ //
83
+ // Iterate over the keys in `object`; for each property that ends in "Translation",
84
+ // call `callback` with the property name (minus the "Translation" suffix) and the
85
+ // translation whose key is the property's value.
86
+ eachTranslatedAttribute: eachTranslatedAttribute,
87
+
88
+ template: function(key, count) {
89
+ var interpolatedKey, result, suffix;
90
+ if ((count != null) && (I18n.pluralForm != null)) {
91
+ suffix = I18n.pluralForm(count);
92
+ interpolatedKey = "%@.%@".fmt(key, suffix);
93
+ result = findTemplate(interpolatedKey, false);
94
+ }
95
+ return result != null ? result : result = findTemplate(key, true);
96
+ },
97
+
98
+ t: function(key, context) {
99
+ var template;
100
+ if (context == null) context = {};
101
+ template = I18n.template(key, get(context, 'count'));
102
+ return template(context);
103
+ },
104
+
105
+ exists: keyExists,
106
+
107
+ missingMessage: function(key) {
108
+ return "Missing translation: " + key;
109
+ },
110
+
111
+ TranslateableProperties: Ember.Mixin.create({
112
+ init: function() {
113
+ var result = this._super.apply(this, arguments);
114
+ eachTranslatedAttribute(this, function(attribute, translation) {
115
+ this.addObserver(attribute + 'Translation', this, function(){
116
+ set(this, attribute, I18n.t(this.get(attribute + 'Translation')));
117
+ });
118
+ set(this, attribute, translation);
119
+ });
120
+
121
+ return result;
122
+ }
123
+ }),
124
+
125
+ TranslateableAttributes: Ember.Mixin.create({
126
+ didInsertElement: function() {
127
+ var result = this._super.apply(this, arguments);
128
+ eachTranslatedAttribute(this, function(attribute, translation) {
129
+ this.$().attr(attribute, translation);
130
+ });
131
+ return result;
132
+ }
133
+ })
134
+ });
135
+
136
+ Ember.I18n = I18n;
137
+
138
+ EmHandlebars.registerBoundHelper('t', function(key, options) {
139
+ return new EmHandlebars.SafeString(I18n.t(key, options.hash));
140
+ });
141
+
142
+ var attrHelperFunction = function(options) {
143
+ var attrs, result;
144
+ attrs = options.hash;
145
+ result = [];
146
+
147
+ Ember.keys(attrs).forEach(function(property) {
148
+ var translatedValue;
149
+ translatedValue = I18n.t(attrs[property]);
150
+ return result.push('%@="%@"'.fmt(property, translatedValue));
151
+ });
152
+
153
+ return new EmHandlebars.SafeString(result.join(' '));
154
+ };
155
+
156
+ EmHandlebars.registerHelper('translateAttr', attrHelperFunction);
157
+ EmHandlebars.registerHelper('ta', attrHelperFunction);
158
+
159
+ }).call(undefined);