i18n-js-pika 3.0.0.rc7 → 3.0.0.rc8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +14 -6
- data/lib/i18n/js.rb +2 -7
- data/lib/i18n/js/dependencies.rb +55 -0
- data/lib/i18n/js/engine.rb +5 -5
- data/lib/i18n/js/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b21ed07eefec40e50743b457da773fb86f45d3ec
|
4
|
+
data.tar.gz: 3db4c9f1b5a99d9e4c10426105cb5743e236a136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d31f4436c68595dfe7547499b7761fbdb83fb4a8cf15a6eca112c77ced270b798b9780b47dd3f98e26110e1cdf31e8492b739f913ccca9f118167bedbfd18bc5
|
7
|
+
data.tar.gz: dab5552f33f48382b205849dd7d35db26f385ef5be6d1b6b8dc16062b8e0fba8a062f278847709709e1fd74824ea6fed3ae61c8c1b6be31af63c630afc0f3123
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,16 @@ Changelog
|
|
3
3
|
|
4
4
|
Major changes to I18n.js for each release. Please see the Git log for complete list of changes.
|
5
5
|
|
6
|
+
3.0.0.rc8 (2014-01-09)
|
7
|
+
-------------------
|
8
|
+
|
9
|
+
* Fix local reload regression in development
|
10
|
+
|
11
|
+
3.0.0.rc7 (2013-12-23)
|
12
|
+
-------------------
|
13
|
+
|
14
|
+
* If loaded in browser (which is not in jasmine spec) and I18n object is defined and has some options set (e.g. locale, defaultLocale), they will be kept
|
15
|
+
|
6
16
|
3.0.0.rc6 (2013-12-13)
|
7
17
|
-------------------
|
8
18
|
|
data/README.md
CHANGED
@@ -62,13 +62,21 @@ by hand or using your favorite programming language. More info below.
|
|
62
62
|
You **don't** need to set up a thing. The default settings will work just okay. But if you want to split translations into several files or specify specific contexts, you can follow the rest of this setting up section.
|
63
63
|
|
64
64
|
Set your locale is easy as
|
65
|
+
```javascript
|
66
|
+
I18n.defaultLocale = "pt-BR";
|
67
|
+
I18n.locale = "pt-BR";
|
68
|
+
I18n.currentLocale();
|
69
|
+
// pt-BR
|
70
|
+
```
|
65
71
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
**NOTE:** Since `3.0.0.rc7`, you can apply your configuration **before I18n** is loaded like this:
|
73
|
+
```javascript
|
74
|
+
I18n = {} // You must define this object in top namespace, which should be `window`
|
75
|
+
I18n.defaultLocale = "pt-BR";
|
76
|
+
I18n.locale = "pt-BR";
|
77
|
+
I18n.currentLocale();
|
78
|
+
// pt-BR
|
79
|
+
```
|
72
80
|
|
73
81
|
In practice, you'll have something like the following in your `application.html.erb`:
|
74
82
|
|
data/lib/i18n/js.rb
CHANGED
@@ -3,7 +3,8 @@ require "FileUtils" unless defined?(FileUtils)
|
|
3
3
|
|
4
4
|
module I18n
|
5
5
|
module JS
|
6
|
-
|
6
|
+
require "i18n/js/dependencies"
|
7
|
+
if JS::Dependencies.rails?
|
7
8
|
require "i18n/js/middleware"
|
8
9
|
require "i18n/js/engine"
|
9
10
|
end
|
@@ -13,12 +14,6 @@ module I18n
|
|
13
14
|
Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2
|
14
15
|
end
|
15
16
|
|
16
|
-
# Detect if Rails app has asset pipeline support.
|
17
|
-
#
|
18
|
-
def self.has_asset_pipeline?
|
19
|
-
Rails.configuration.respond_to?(:assets) && Rails.configuration.assets.enabled
|
20
|
-
end
|
21
|
-
|
22
17
|
# The configuration file. This defaults to the `config/i18n-js.yml` file.
|
23
18
|
#
|
24
19
|
def self.config_file
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module I18n
|
2
|
+
module JS
|
3
|
+
module Dependencies
|
4
|
+
class << self
|
5
|
+
def rails3?
|
6
|
+
safe_gem_check("rails", "~> 3") && running_rails3?
|
7
|
+
end
|
8
|
+
|
9
|
+
def rails4?
|
10
|
+
safe_gem_check("rails", "~> 4.0") && running_rails4?
|
11
|
+
end
|
12
|
+
|
13
|
+
def rails?
|
14
|
+
rails_available? && running_rails?
|
15
|
+
end
|
16
|
+
|
17
|
+
def rails_available?
|
18
|
+
safe_gem_check("rails", '>= 3')
|
19
|
+
end
|
20
|
+
|
21
|
+
def using_asset_pipeline?
|
22
|
+
assets_pipeline_available = (rails3? || rails4?) && Rails.respond_to?(:application) && Rails.application.respond_to?(:assets)
|
23
|
+
rails3_assets_enabled = rails3? && assets_pipeline_available && Rails.application.config.assets.enabled != false
|
24
|
+
# Might need to check if gem `sprocket-rails` exists if someone does not use it on rails 4 (rare case)
|
25
|
+
assets_pipeline_available && (rails4? || rails3_assets_enabled)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def running_rails3?
|
31
|
+
running_rails? && Rails.version.to_i == 3
|
32
|
+
end
|
33
|
+
|
34
|
+
def running_rails4?
|
35
|
+
running_rails? && Rails.version.to_i == 4
|
36
|
+
end
|
37
|
+
|
38
|
+
def running_rails?
|
39
|
+
defined?(Rails) && Rails.respond_to?(:version)
|
40
|
+
end
|
41
|
+
|
42
|
+
def safe_gem_check(gem_name, version_string)
|
43
|
+
if Gem::Specification.respond_to?(:find_by_name)
|
44
|
+
Gem::Specification.find_by_name(gem_name, version_string)
|
45
|
+
elsif Gem.respond_to?(:available?)
|
46
|
+
Gem.available?(gem_name, version_string)
|
47
|
+
end
|
48
|
+
rescue Gem::LoadError
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/i18n/js/engine.rb
CHANGED
@@ -5,14 +5,14 @@ module I18n
|
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
initializer :after => "sprockets.environment" do
|
7
7
|
ActiveSupport.on_load(:after_initialize, :yield => true) do
|
8
|
-
next unless JS.
|
8
|
+
next unless JS::Dependencies.using_asset_pipeline?
|
9
9
|
next unless Rails.configuration.assets.compile
|
10
10
|
|
11
|
-
|
11
|
+
Rails.application.assets.register_preprocessor "application/javascript", :"i18n-js_dependencies" do |context, source|
|
12
|
+
if context.logical_path == "i18n/filtered"
|
13
|
+
::I18n.load_path.each {|path| context.depend_on(File.expand_path(path))}
|
14
|
+
end
|
12
15
|
|
13
|
-
registry.register_preprocessor "application/javascript", :"i18n-js_dependencies" do |context, source|
|
14
|
-
next source unless context.logical_path == "i18n/filtered"
|
15
|
-
::I18n.load_path.each {|path| context.depend_on(File.expand_path(path))}
|
16
16
|
source
|
17
17
|
end
|
18
18
|
end
|
data/lib/i18n/js/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-js-pika
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- i18n-js.gemspec
|
105
105
|
- lib/i18n-js.rb
|
106
106
|
- lib/i18n/js.rb
|
107
|
+
- lib/i18n/js/dependencies.rb
|
107
108
|
- lib/i18n/js/engine.rb
|
108
109
|
- lib/i18n/js/middleware.rb
|
109
110
|
- lib/i18n/js/version.rb
|
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
version: 1.3.1
|
159
160
|
requirements: []
|
160
161
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.2.0
|
162
163
|
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: Forked version of original i18n-js. It's a small library to provide the Rails
|