angular-gettext-rails 2.1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8442a0a30db315bc2104c366b223be17d9afc214
4
+ data.tar.gz: 32891b41073cf9e3b7aa4da0fab1854c88ceface
5
+ SHA512:
6
+ metadata.gz: d9d87c8a12388c2cead85bf5cce347410aa7101d399e90d052ba9e66ea21a4dc86f910b6ff74142ba9ad08206f6989a7a2c336ac33763532dd48be3506086aaf
7
+ data.tar.gz: 3f78a3d5173191e3922aa0c93653f503abe761067b35db3a1dca75d5416597cf09e68cd917ddf679ac3da6f4a8ea8659fc513e93de743cce119ca84a42697bda
@@ -0,0 +1,14 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angular-gettext-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Toru Nayuki
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,15 @@
1
+ # angular-gettext-rails
2
+
3
+ angular-gettext-rails wraps the [angular-gettext.js](https://github.com/rubenv/angular-gettext) library in a rails engine for simple
4
+ use with the asset pipeline provided by Rails 3.1 and higher. The gem includes the development (non-minified)
5
+ source for ease of exploration. The asset pipeline will minify in production.
6
+
7
+ ## Usage
8
+
9
+ Add the following to your gemfile:
10
+
11
+ gem 'angular-gettext-rails'
12
+
13
+ Add the following directive to your Javascript manifest file (application.js):
14
+
15
+ //= require angular-gettext
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "angular-gettext-rails"
7
+ spec.version = "2.1.0.1"
8
+ spec.authors = ["Toru Nayuki"]
9
+ spec.email = ["tnayuki@icloud.com"]
10
+ spec.summary = "The Angular Gettext JavaScript module ready to play with Rails."
11
+ spec.description = "Super-simple translation support for Angular.JS"
12
+ spec.homepage = "https://github.com/tnayuki/angular-gettext-rails"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rails", "~> 3.2.12"
23
+ end
@@ -0,0 +1,352 @@
1
+ angular.module('gettext', []);
2
+
3
+ angular.module('gettext').constant('gettext', function (str) {
4
+ /*
5
+ * Does nothing, simply returns the input string.
6
+ *
7
+ * This function serves as a marker for `grunt-angular-gettext` to know that
8
+ * this string should be extracted for translations.
9
+ */
10
+ return str;
11
+ });
12
+
13
+ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "$http", "$cacheFactory", "$interpolate", "$rootScope", function (gettextPlurals, $http, $cacheFactory, $interpolate, $rootScope) {
14
+ var catalog;
15
+ var noContext = '$$noContext';
16
+
17
+ // IE8 returns UPPER CASE tags, even though the source is lower case.
18
+ // This can causes the (key) string in the DOM to have a different case to
19
+ // the string in the `po` files.
20
+ // IE9, IE10 and IE11 reorders the attributes of tags.
21
+ var test = '<span id="test" title="test" class="tested">test</span>';
22
+ var isHTMLModified = (angular.element('<span>' + test + '</span>').html() !== test);
23
+
24
+ var prefixDebug = function (string) {
25
+ if (catalog.debug && catalog.currentLanguage !== catalog.baseLanguage) {
26
+ return catalog.debugPrefix + string;
27
+ } else {
28
+ return string;
29
+ }
30
+ };
31
+
32
+ var addTranslatedMarkers = function (string) {
33
+ if (catalog.showTranslatedMarkers) {
34
+ return catalog.translatedMarkerPrefix + string + catalog.translatedMarkerSuffix;
35
+ } else {
36
+ return string;
37
+ }
38
+ };
39
+
40
+ function broadcastUpdated() {
41
+ $rootScope.$broadcast('gettextLanguageChanged');
42
+ }
43
+
44
+ catalog = {
45
+ debug: false,
46
+ debugPrefix: '[MISSING]: ',
47
+ showTranslatedMarkers: false,
48
+ translatedMarkerPrefix: '[',
49
+ translatedMarkerSuffix: ']',
50
+ strings: {},
51
+ baseLanguage: 'en',
52
+ currentLanguage: 'en',
53
+ cache: $cacheFactory('strings'),
54
+
55
+ setCurrentLanguage: function (lang) {
56
+ this.currentLanguage = lang;
57
+ broadcastUpdated();
58
+ },
59
+
60
+ getCurrentLanguage: function () {
61
+ return this.currentLanguage;
62
+ },
63
+
64
+ setStrings: function (language, strings) {
65
+ if (!this.strings[language]) {
66
+ this.strings[language] = {};
67
+ }
68
+
69
+ for (var key in strings) {
70
+ var val = strings[key];
71
+
72
+ if (isHTMLModified) {
73
+ // Use the DOM engine to render any HTML in the key (#131).
74
+ key = angular.element('<span>' + key + '</span>').html();
75
+ }
76
+
77
+ if (angular.isString(val) || angular.isArray(val)) {
78
+ // No context, wrap it in $$noContext.
79
+ var obj = {};
80
+ obj[noContext] = val;
81
+ val = obj;
82
+ }
83
+
84
+ // Expand single strings for each context.
85
+ for (var context in val) {
86
+ var str = val[context];
87
+ val[context] = angular.isArray(str) ? str : [str];
88
+ }
89
+ this.strings[language][key] = val;
90
+ }
91
+
92
+ broadcastUpdated();
93
+ },
94
+
95
+ getStringForm: function (string, n, context) {
96
+ var stringTable = this.strings[this.currentLanguage] || {};
97
+ var contexts = stringTable[string] || {};
98
+ var plurals = contexts[context || noContext] || [];
99
+ return plurals[n];
100
+ },
101
+
102
+ getString: function (string, scope, context) {
103
+ string = this.getStringForm(string, 0, context) || prefixDebug(string);
104
+ string = scope ? $interpolate(string)(scope) : string;
105
+ return addTranslatedMarkers(string);
106
+ },
107
+
108
+ getPlural: function (n, string, stringPlural, scope, context) {
109
+ var form = gettextPlurals(this.currentLanguage, n);
110
+ string = this.getStringForm(string, form, context) || prefixDebug(n === 1 ? string : stringPlural);
111
+ if (scope) {
112
+ scope.$count = n;
113
+ string = $interpolate(string)(scope);
114
+ }
115
+ return addTranslatedMarkers(string);
116
+ },
117
+
118
+ loadRemote: function (url) {
119
+ return $http({
120
+ method: 'GET',
121
+ url: url,
122
+ cache: catalog.cache
123
+ }).success(function (data) {
124
+ for (var lang in data) {
125
+ catalog.setStrings(lang, data[lang]);
126
+ }
127
+ });
128
+ }
129
+ };
130
+
131
+ return catalog;
132
+ }]);
133
+
134
+ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$animate", "$compile", "$window", function (gettextCatalog, $parse, $animate, $compile, $window) {
135
+ // Trim polyfill for old browsers (instead of jQuery)
136
+ // Based on AngularJS-v1.2.2 (angular.js#620)
137
+ var trim = (function () {
138
+ if (!String.prototype.trim) {
139
+ return function (value) {
140
+ return (typeof value === 'string') ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
141
+ };
142
+ }
143
+ return function (value) {
144
+ return (typeof value === 'string') ? value.trim() : value;
145
+ };
146
+ })();
147
+
148
+ function assert(condition, missing, found) {
149
+ if (!condition) {
150
+ throw new Error('You should add a ' + missing + ' attribute whenever you add a ' + found + ' attribute.');
151
+ }
152
+ }
153
+
154
+ var msie = parseInt((/msie (\d+)/.exec(angular.lowercase($window.navigator.userAgent)) || [])[1], 10);
155
+
156
+ return {
157
+ restrict: 'AE',
158
+ terminal: true,
159
+ compile: function compile(element, attrs) {
160
+ // Validate attributes
161
+ assert(!attrs.translatePlural || attrs.translateN, 'translate-n', 'translate-plural');
162
+ assert(!attrs.translateN || attrs.translatePlural, 'translate-plural', 'translate-n');
163
+
164
+ var msgid = trim(element.html());
165
+ var translatePlural = attrs.translatePlural;
166
+ var translateContext = attrs.translateContext;
167
+
168
+ if (msie <= 8) {
169
+ // Workaround fix relating to angular adding a comment node to
170
+ // anchors. angular/angular.js/#1949 / angular/angular.js/#2013
171
+ if (msgid.slice(-13) === '<!--IE fix-->') {
172
+ msgid = msgid.slice(0, -13);
173
+ }
174
+ }
175
+
176
+ return {
177
+ post: function (scope, element, attrs) {
178
+ var countFn = $parse(attrs.translateN);
179
+ var pluralScope = null;
180
+ var linking = true;
181
+
182
+ function update() {
183
+ // Fetch correct translated string.
184
+ var translated;
185
+ if (translatePlural) {
186
+ scope = pluralScope || (pluralScope = scope.$new());
187
+ scope.$count = countFn(scope);
188
+ translated = gettextCatalog.getPlural(scope.$count, msgid, translatePlural, null, translateContext);
189
+ } else {
190
+ translated = gettextCatalog.getString(msgid, null, translateContext);
191
+ }
192
+
193
+ var oldContents = element.contents();
194
+
195
+ if (oldContents.length === 0){
196
+ return;
197
+ }
198
+
199
+ // Avoid redundant swaps
200
+ if (translated === trim(oldContents.html())){
201
+ // Take care of unlinked content
202
+ if (linking){
203
+ $compile(oldContents)(scope);
204
+ }
205
+ return;
206
+ }
207
+
208
+ // Swap in the translation
209
+ var newWrapper = angular.element('<span>' + translated + '</span>');
210
+ $compile(newWrapper.contents())(scope);
211
+ var newContents = newWrapper.contents();
212
+
213
+ $animate.enter(newContents, element);
214
+ $animate.leave(oldContents);
215
+ }
216
+
217
+ if (attrs.translateN) {
218
+ scope.$watch(attrs.translateN, update);
219
+ }
220
+
221
+ scope.$on('gettextLanguageChanged', update);
222
+
223
+ update();
224
+ linking = false;
225
+ }
226
+ };
227
+ }
228
+ };
229
+ }]);
230
+
231
+ angular.module('gettext').filter('translate', ["gettextCatalog", function (gettextCatalog) {
232
+ function filter(input, context) {
233
+ return gettextCatalog.getString(input, null, context);
234
+ }
235
+ filter.$stateful = true;
236
+ return filter;
237
+ }]);
238
+
239
+ // Do not edit this file, it is autogenerated using genplurals.py!
240
+ angular.module("gettext").factory("gettextPlurals", function () {
241
+ return function (langCode, n) {
242
+ switch (langCode) {
243
+ case "ay": // Aymará
244
+ case "bo": // Tibetan
245
+ case "cgg": // Chiga
246
+ case "dz": // Dzongkha
247
+ case "fa": // Persian
248
+ case "id": // Indonesian
249
+ case "ja": // Japanese
250
+ case "jbo": // Lojban
251
+ case "ka": // Georgian
252
+ case "kk": // Kazakh
253
+ case "km": // Khmer
254
+ case "ko": // Korean
255
+ case "ky": // Kyrgyz
256
+ case "lo": // Lao
257
+ case "ms": // Malay
258
+ case "my": // Burmese
259
+ case "sah": // Yakut
260
+ case "su": // Sundanese
261
+ case "th": // Thai
262
+ case "tt": // Tatar
263
+ case "ug": // Uyghur
264
+ case "vi": // Vietnamese
265
+ case "wo": // Wolof
266
+ case "zh": // Chinese
267
+ // 1 form
268
+ return 0;
269
+ case "is": // Icelandic
270
+ // 2 forms
271
+ return (n%10!=1 || n%100==11) ? 1 : 0;
272
+ case "jv": // Javanese
273
+ // 2 forms
274
+ return n!=0 ? 1 : 0;
275
+ case "mk": // Macedonian
276
+ // 2 forms
277
+ return n==1 || n%10==1 ? 0 : 1;
278
+ case "ach": // Acholi
279
+ case "ak": // Akan
280
+ case "am": // Amharic
281
+ case "arn": // Mapudungun
282
+ case "br": // Breton
283
+ case "fil": // Filipino
284
+ case "fr": // French
285
+ case "gun": // Gun
286
+ case "ln": // Lingala
287
+ case "mfe": // Mauritian Creole
288
+ case "mg": // Malagasy
289
+ case "mi": // Maori
290
+ case "oc": // Occitan
291
+ case "pt_BR": // Brazilian Portuguese
292
+ case "tg": // Tajik
293
+ case "ti": // Tigrinya
294
+ case "tr": // Turkish
295
+ case "uz": // Uzbek
296
+ case "wa": // Walloon
297
+ case "zh": // Chinese
298
+ // 2 forms
299
+ return n>1 ? 1 : 0;
300
+ case "lv": // Latvian
301
+ // 3 forms
302
+ return (n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2);
303
+ case "lt": // Lithuanian
304
+ // 3 forms
305
+ return (n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);
306
+ case "be": // Belarusian
307
+ case "bs": // Bosnian
308
+ case "hr": // Croatian
309
+ case "ru": // Russian
310
+ case "sr": // Serbian
311
+ case "uk": // Ukrainian
312
+ // 3 forms
313
+ return (n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);
314
+ case "mnk": // Mandinka
315
+ // 3 forms
316
+ return (n==0 ? 0 : n==1 ? 1 : 2);
317
+ case "ro": // Romanian
318
+ // 3 forms
319
+ return (n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);
320
+ case "pl": // Polish
321
+ // 3 forms
322
+ return (n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);
323
+ case "cs": // Czech
324
+ case "sk": // Slovak
325
+ // 3 forms
326
+ return (n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;
327
+ case "sl": // Slovenian
328
+ // 4 forms
329
+ return (n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0);
330
+ case "mt": // Maltese
331
+ // 4 forms
332
+ return (n==1 ? 0 : n==0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);
333
+ case "gd": // Scottish Gaelic
334
+ // 4 forms
335
+ return (n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3;
336
+ case "cy": // Welsh
337
+ // 4 forms
338
+ return (n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3;
339
+ case "kw": // Cornish
340
+ // 4 forms
341
+ return (n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3;
342
+ case "ga": // Irish
343
+ // 5 forms
344
+ return n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4;
345
+ case "ar": // Arabic
346
+ // 6 forms
347
+ return (n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);
348
+ default: // Everything else
349
+ return n != 1 ? 1 : 0;
350
+ }
351
+ }
352
+ });
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-gettext-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Toru Nayuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.12
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.12
55
+ description: Super-simple translation support for Angular.JS
56
+ email:
57
+ - tnayuki@icloud.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - angular-gettext-rails.gemspec
68
+ - vendor/assets/javascripts/angular-gettext.js
69
+ homepage: https://github.com/tnayuki/angular-gettext-rails
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.2.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: The Angular Gettext JavaScript module ready to play with Rails.
93
+ test_files: []