angular-dynamic-locale-rails 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +15 -0
- data/Rakefile +2 -0
- data/angular-dynamic-locale-rails.gemspec +23 -0
- data/lib/angular-dynamic-locale-rails.rb +6 -0
- data/vendor/assets/javascripts/tmhDynamicLocale.js +249 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eeb0905aac80d2fa55a1436efb0b0359426fcf67
|
4
|
+
data.tar.gz: 340f181b3a04d0e3310f7bcd36efac703aa59cb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ba27a097a44a7908be42f4bea3327225cd68de608f4fcf61cdfdd2cf911cd487af112f449e72e5f456b260154d06306179b9e260c9194c9fb58770653db6d74
|
7
|
+
data.tar.gz: 2600665e604584bff80c032b07e25513f1e7ae79c350bf6781b35f56c9e50a3861aa44f8fa83b36c0203625f050bc4a1dec4ae268a4142ba6578f3894733602d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
angular-dynamic-locale-rails RubyGem Copyright (c) 2016 Toru Nayuki
|
2
|
+
|
3
|
+
angular-dynamic-locale Copyright (c) 2013 Lucas Galfasó
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# angular-dynamic-locale-rails
|
2
|
+
|
3
|
+
angular-dynamic-locale-rails wraps the [angular-dynamic-locale.js](https://github.com/lgalfaso/angular-dynamic-locale) 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-dynamic-locale-rails'
|
12
|
+
|
13
|
+
Add the following directive to your Javascript manifest file (application.js):
|
14
|
+
|
15
|
+
//= require tmhDynamicLocale
|
data/Rakefile
ADDED
@@ -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-dynamic-locale-rails"
|
7
|
+
spec.version = "0.1.30"
|
8
|
+
spec.authors = ["Toru Nayuki"]
|
9
|
+
spec.email = ["tnayuki@icloud.com"]
|
10
|
+
spec.summary = "The Angular Dynamic Locale JavaScript module ready to play with Rails."
|
11
|
+
spec.description = "Module to be able to change the locale at an angularjs application"
|
12
|
+
spec.homepage = "https://github.com/tnayuki/angular-dynamic-locale-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,249 @@
|
|
1
|
+
(function (root, factory) {
|
2
|
+
if (typeof define === 'function' && define.amd) {
|
3
|
+
// AMD. Register as an anonymous module unless amdModuleId is set
|
4
|
+
define([], function () {
|
5
|
+
return (factory());
|
6
|
+
});
|
7
|
+
} else if (typeof exports === 'object') {
|
8
|
+
// Node. Does not work with strict CommonJS, but
|
9
|
+
// only CommonJS-like environments that support module.exports,
|
10
|
+
// like Node.
|
11
|
+
module.exports = factory();
|
12
|
+
} else {
|
13
|
+
factory();
|
14
|
+
}
|
15
|
+
}(this, function () {
|
16
|
+
'use strict';
|
17
|
+
angular.module('tmh.dynamicLocale', []).config(['$provide', function($provide) {
|
18
|
+
function makeStateful($delegate) {
|
19
|
+
$delegate.$stateful = true;
|
20
|
+
return $delegate;
|
21
|
+
}
|
22
|
+
|
23
|
+
$provide.decorator('dateFilter', ['$delegate', makeStateful]);
|
24
|
+
$provide.decorator('numberFilter', ['$delegate', makeStateful]);
|
25
|
+
$provide.decorator('currencyFilter', ['$delegate', makeStateful]);
|
26
|
+
|
27
|
+
}])
|
28
|
+
.constant('tmhDynamicLocale.STORAGE_KEY', 'tmhDynamicLocale.locale')
|
29
|
+
.provider('tmhDynamicLocale', ['tmhDynamicLocale.STORAGE_KEY', function(STORAGE_KEY) {
|
30
|
+
|
31
|
+
var defaultLocale,
|
32
|
+
localeLocationPattern = 'angular/i18n/angular-locale_{{locale}}.js',
|
33
|
+
nodeToAppend,
|
34
|
+
storageFactory = 'tmhDynamicLocaleStorageCache',
|
35
|
+
storage,
|
36
|
+
storageKey = STORAGE_KEY,
|
37
|
+
promiseCache = {},
|
38
|
+
activeLocale;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Loads a script asynchronously
|
42
|
+
*
|
43
|
+
* @param {string} url The url for the script
|
44
|
+
@ @param {function} callback A function to be called once the script is loaded
|
45
|
+
*/
|
46
|
+
function loadScript(url, callback, errorCallback, $timeout) {
|
47
|
+
var script = document.createElement('script'),
|
48
|
+
element = nodeToAppend ? nodeToAppend : document.getElementsByTagName("body")[0],
|
49
|
+
removed = false;
|
50
|
+
|
51
|
+
script.type = 'text/javascript';
|
52
|
+
if (script.readyState) { // IE
|
53
|
+
script.onreadystatechange = function () {
|
54
|
+
if (script.readyState === 'complete' ||
|
55
|
+
script.readyState === 'loaded') {
|
56
|
+
script.onreadystatechange = null;
|
57
|
+
$timeout(
|
58
|
+
function () {
|
59
|
+
if (removed) return;
|
60
|
+
removed = true;
|
61
|
+
element.removeChild(script);
|
62
|
+
callback();
|
63
|
+
}, 30, false);
|
64
|
+
}
|
65
|
+
};
|
66
|
+
} else { // Others
|
67
|
+
script.onload = function () {
|
68
|
+
if (removed) return;
|
69
|
+
removed = true;
|
70
|
+
element.removeChild(script);
|
71
|
+
callback();
|
72
|
+
};
|
73
|
+
script.onerror = function () {
|
74
|
+
if (removed) return;
|
75
|
+
removed = true;
|
76
|
+
element.removeChild(script);
|
77
|
+
errorCallback();
|
78
|
+
};
|
79
|
+
}
|
80
|
+
script.src = url;
|
81
|
+
script.async = true;
|
82
|
+
element.appendChild(script);
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Loads a locale and replaces the properties from the current locale with the new locale information
|
87
|
+
*
|
88
|
+
* @param {string} localeUrl The path to the new locale
|
89
|
+
* @param {Object} $locale The locale at the curent scope
|
90
|
+
* @param {string} localeId The locale id to load
|
91
|
+
* @param {Object} $rootScope The application $rootScope
|
92
|
+
* @param {Object} $q The application $q
|
93
|
+
* @param {Object} localeCache The current locale cache
|
94
|
+
* @param {Object} $timeout The application $timeout
|
95
|
+
*/
|
96
|
+
function loadLocale(localeUrl, $locale, localeId, $rootScope, $q, localeCache, $timeout) {
|
97
|
+
|
98
|
+
function overrideValues(oldObject, newObject) {
|
99
|
+
if (activeLocale !== localeId) {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
angular.forEach(oldObject, function(value, key) {
|
103
|
+
if (!newObject[key]) {
|
104
|
+
delete oldObject[key];
|
105
|
+
} else if (angular.isArray(newObject[key])) {
|
106
|
+
oldObject[key].length = newObject[key].length;
|
107
|
+
}
|
108
|
+
});
|
109
|
+
angular.forEach(newObject, function(value, key) {
|
110
|
+
if (angular.isArray(newObject[key]) || angular.isObject(newObject[key])) {
|
111
|
+
if (!oldObject[key]) {
|
112
|
+
oldObject[key] = angular.isArray(newObject[key]) ? [] : {};
|
113
|
+
}
|
114
|
+
overrideValues(oldObject[key], newObject[key]);
|
115
|
+
} else {
|
116
|
+
oldObject[key] = newObject[key];
|
117
|
+
}
|
118
|
+
});
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
if (promiseCache[localeId]) {
|
123
|
+
activeLocale = localeId;
|
124
|
+
return promiseCache[localeId];
|
125
|
+
}
|
126
|
+
|
127
|
+
var cachedLocale,
|
128
|
+
deferred = $q.defer();
|
129
|
+
if (localeId === activeLocale) {
|
130
|
+
deferred.resolve($locale);
|
131
|
+
} else if ((cachedLocale = localeCache.get(localeId))) {
|
132
|
+
activeLocale = localeId;
|
133
|
+
$rootScope.$evalAsync(function() {
|
134
|
+
overrideValues($locale, cachedLocale);
|
135
|
+
storage.put(storageKey, localeId);
|
136
|
+
$rootScope.$broadcast('$localeChangeSuccess', localeId, $locale);
|
137
|
+
deferred.resolve($locale);
|
138
|
+
});
|
139
|
+
} else {
|
140
|
+
activeLocale = localeId;
|
141
|
+
promiseCache[localeId] = deferred.promise;
|
142
|
+
loadScript(localeUrl, function() {
|
143
|
+
// Create a new injector with the new locale
|
144
|
+
var localInjector = angular.injector(['ngLocale']),
|
145
|
+
externalLocale = localInjector.get('$locale');
|
146
|
+
|
147
|
+
overrideValues($locale, externalLocale);
|
148
|
+
localeCache.put(localeId, externalLocale);
|
149
|
+
delete promiseCache[localeId];
|
150
|
+
|
151
|
+
$rootScope.$applyAsync(function() {
|
152
|
+
storage.put(storageKey, localeId);
|
153
|
+
$rootScope.$broadcast('$localeChangeSuccess', localeId, $locale);
|
154
|
+
deferred.resolve($locale);
|
155
|
+
});
|
156
|
+
}, function() {
|
157
|
+
delete promiseCache[localeId];
|
158
|
+
|
159
|
+
$rootScope.$applyAsync(function() {
|
160
|
+
if (activeLocale === localeId) {
|
161
|
+
activeLocale = $locale.id;
|
162
|
+
}
|
163
|
+
$rootScope.$broadcast('$localeChangeError', localeId);
|
164
|
+
deferred.reject(localeId);
|
165
|
+
});
|
166
|
+
}, $timeout);
|
167
|
+
}
|
168
|
+
return deferred.promise;
|
169
|
+
}
|
170
|
+
|
171
|
+
this.localeLocationPattern = function(value) {
|
172
|
+
if (value) {
|
173
|
+
localeLocationPattern = value;
|
174
|
+
return this;
|
175
|
+
} else {
|
176
|
+
return localeLocationPattern;
|
177
|
+
}
|
178
|
+
};
|
179
|
+
|
180
|
+
this.appendScriptTo = function(nodeElement) {
|
181
|
+
nodeToAppend = nodeElement;
|
182
|
+
};
|
183
|
+
|
184
|
+
this.useStorage = function(storageName) {
|
185
|
+
storageFactory = storageName;
|
186
|
+
};
|
187
|
+
|
188
|
+
this.useCookieStorage = function() {
|
189
|
+
this.useStorage('$cookieStore');
|
190
|
+
};
|
191
|
+
|
192
|
+
this.defaultLocale = function(value) {
|
193
|
+
defaultLocale = value;
|
194
|
+
};
|
195
|
+
|
196
|
+
this.storageKey = function(value) {
|
197
|
+
if (value) {
|
198
|
+
storageKey = value;
|
199
|
+
return this;
|
200
|
+
} else {
|
201
|
+
return storageKey;
|
202
|
+
}
|
203
|
+
};
|
204
|
+
|
205
|
+
this.$get = ['$rootScope', '$injector', '$interpolate', '$locale', '$q', 'tmhDynamicLocaleCache', '$timeout', function($rootScope, $injector, interpolate, locale, $q, tmhDynamicLocaleCache, $timeout) {
|
206
|
+
var localeLocation = interpolate(localeLocationPattern);
|
207
|
+
|
208
|
+
storage = $injector.get(storageFactory);
|
209
|
+
$rootScope.$evalAsync(function() {
|
210
|
+
var initialLocale;
|
211
|
+
if ((initialLocale = (storage.get(storageKey) || defaultLocale))) {
|
212
|
+
loadLocaleFn(initialLocale);
|
213
|
+
}
|
214
|
+
});
|
215
|
+
return {
|
216
|
+
/**
|
217
|
+
* @ngdoc method
|
218
|
+
* @description
|
219
|
+
* @param {string} value Sets the locale to the new locale. Changing the locale will trigger
|
220
|
+
* a background task that will retrieve the new locale and configure the current $locale
|
221
|
+
* instance with the information from the new locale
|
222
|
+
*/
|
223
|
+
set: loadLocaleFn,
|
224
|
+
/**
|
225
|
+
* @ngdoc method
|
226
|
+
* @description Returns the configured locale
|
227
|
+
*/
|
228
|
+
get: function() {
|
229
|
+
return activeLocale;
|
230
|
+
}
|
231
|
+
};
|
232
|
+
|
233
|
+
function loadLocaleFn(localeId) {
|
234
|
+
return loadLocale(localeLocation({locale: localeId, angularVersion: angular.version.full}), locale, localeId, $rootScope, $q, tmhDynamicLocaleCache, $timeout);
|
235
|
+
}
|
236
|
+
}];
|
237
|
+
}]).provider('tmhDynamicLocaleCache', function() {
|
238
|
+
this.$get = ['$cacheFactory', function($cacheFactory) {
|
239
|
+
return $cacheFactory('tmh.dynamicLocales');
|
240
|
+
}];
|
241
|
+
}).provider('tmhDynamicLocaleStorageCache', function() {
|
242
|
+
this.$get = ['$cacheFactory', function($cacheFactory) {
|
243
|
+
return $cacheFactory('tmh.dynamicLocales.store');
|
244
|
+
}];
|
245
|
+
}).run(['tmhDynamicLocale', angular.noop]);
|
246
|
+
|
247
|
+
return 'tmh.dynamicLocale';
|
248
|
+
|
249
|
+
}));
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: angular-dynamic-locale-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.30
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toru Nayuki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-24 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: Module to be able to change the locale at an angularjs application
|
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-dynamic-locale-rails.gemspec
|
68
|
+
- lib/angular-dynamic-locale-rails.rb
|
69
|
+
- vendor/assets/javascripts/tmhDynamicLocale.js
|
70
|
+
homepage: https://github.com/tnayuki/angular-dynamic-locale-rails
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: The Angular Dynamic Locale JavaScript module ready to play with Rails.
|
94
|
+
test_files: []
|