socialcast-i18n-js 4.0.0.rc1 → 4.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/i18n/js/version.rb +1 -1
- data/vendor/assets/javascripts/i18n/translations.js.erb +8 -9
- data/vendor/assets/javascripts/i18n.js +587 -457
- metadata +17 -24
- data/app/assets/javascripts/i18n/translations.js.erb +0 -6
- data/app/assets/javascripts/i18n.js +0 -661
- data/lib/i18n-js/engine.rb +0 -63
- data/lib/i18n-js/middleware.rb +0 -59
- data/lib/i18n-js/railtie.rb +0 -13
- data/lib/i18n-js/rake.rb +0 -16
- data/lib/i18n-js/version.rb +0 -10
data/lib/i18n-js/engine.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
module SimplesIdeias
|
2
|
-
module I18n
|
3
|
-
class Engine < ::Rails::Engine
|
4
|
-
I18N_TRANSLATIONS_ASSET = "i18n/translations"
|
5
|
-
|
6
|
-
initializer "i18n-js.asset_dependencies", :after => "sprockets.environment",
|
7
|
-
:before => "i18n-js.initialize" do
|
8
|
-
next unless SimplesIdeias::I18n.has_asset_pipeline?
|
9
|
-
|
10
|
-
config = I18n.config_file
|
11
|
-
cache_file = I18n::Engine.load_path_hash_cache
|
12
|
-
|
13
|
-
Rails.application.assets.register_preprocessor "application/javascript", :"i18n-js_dependencies" do |context, data|
|
14
|
-
if context.logical_path == I18N_TRANSLATIONS_ASSET
|
15
|
-
context.depend_on(config) if I18n.config?
|
16
|
-
# also set up dependencies on every locale file
|
17
|
-
::I18n.load_path.each {|path| context.depend_on(path)}
|
18
|
-
|
19
|
-
# Set up a dependency on the contents of the load path
|
20
|
-
# itself. In some situations it is possible to get here
|
21
|
-
# before the path hash cache file has been written; in
|
22
|
-
# this situation, write it now.
|
23
|
-
I18n::Engine.write_hash! unless File.exists?(cache_file)
|
24
|
-
context.depend_on(cache_file)
|
25
|
-
end
|
26
|
-
|
27
|
-
data
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# rewrite path cache hash at startup and before each request in development
|
32
|
-
config.to_prepare do
|
33
|
-
next unless SimplesIdeias::I18n.has_asset_pipeline?
|
34
|
-
SimplesIdeias::I18n::Engine.write_hash_if_changed unless Rails.env.production?
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.load_path_hash_cache
|
38
|
-
@load_path_hash_cache ||= Rails.root.join("tmp/i18n-js.cache")
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.write_hash_if_changed
|
42
|
-
load_path_hash = ::I18n.load_path.hash
|
43
|
-
|
44
|
-
if load_path_hash != cached_load_path_hash
|
45
|
-
self.cached_load_path_hash = load_path_hash
|
46
|
-
write_hash!
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.write_hash!
|
51
|
-
FileUtils.mkdir_p Rails.root.join("tmp")
|
52
|
-
|
53
|
-
File.open(load_path_hash_cache, "w+") do |f|
|
54
|
-
f.write(cached_load_path_hash)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class << self
|
59
|
-
attr_accessor :cached_load_path_hash
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/i18n-js/middleware.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
module SimplesIdeias
|
2
|
-
module I18n
|
3
|
-
class Middleware
|
4
|
-
def initialize(app)
|
5
|
-
@app = app
|
6
|
-
end
|
7
|
-
|
8
|
-
def call(env)
|
9
|
-
@cache = nil
|
10
|
-
verify_locale_files!
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
def cache_path
|
16
|
-
@cache_path ||= Rails.root.join("tmp/cache/i18n-js.yml")
|
17
|
-
end
|
18
|
-
|
19
|
-
def cache
|
20
|
-
@cache ||= begin
|
21
|
-
if cache_path.exist?
|
22
|
-
YAML.load_file(cache_path) || {}
|
23
|
-
else
|
24
|
-
{}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Check if translations should be regenerated.
|
30
|
-
# ONLY REGENERATE when these conditions are met:
|
31
|
-
#
|
32
|
-
# # Cache file doesn't exist
|
33
|
-
# # Translations and cache size are different (files were removed/added)
|
34
|
-
# # Translation file has been updated
|
35
|
-
#
|
36
|
-
def verify_locale_files!
|
37
|
-
valid_cache = []
|
38
|
-
new_cache = {}
|
39
|
-
|
40
|
-
valid_cache.push cache_path.exist?
|
41
|
-
valid_cache.push ::I18n.load_path.uniq.size == cache.size
|
42
|
-
|
43
|
-
::I18n.load_path.each do |path|
|
44
|
-
changed_at = File.mtime(path).to_i
|
45
|
-
valid_cache.push changed_at == cache[path]
|
46
|
-
new_cache[path] = changed_at
|
47
|
-
end
|
48
|
-
|
49
|
-
unless valid_cache.all?
|
50
|
-
File.open(cache_path, "w+") do |file|
|
51
|
-
file << new_cache.to_yaml
|
52
|
-
end
|
53
|
-
|
54
|
-
SimplesIdeias::I18n.export!
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/lib/i18n-js/railtie.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module SimplesIdeias
|
2
|
-
module I18n
|
3
|
-
class Railtie < Rails::Railtie
|
4
|
-
rake_tasks do
|
5
|
-
require "i18n-js/rake"
|
6
|
-
end
|
7
|
-
|
8
|
-
initializer "i18n-js.initialize" do |app|
|
9
|
-
app.config.middleware.use(Middleware) if Rails.env.development? && !SimplesIdeias::I18n.has_asset_pipeline?
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/i18n-js/rake.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
namespace "i18n:js" do
|
2
|
-
desc "Copy i18n.js and configuration file"
|
3
|
-
task :setup => :environment do
|
4
|
-
SimplesIdeias::I18n.setup!
|
5
|
-
end
|
6
|
-
|
7
|
-
desc "Export the messages files"
|
8
|
-
task :export => :environment do
|
9
|
-
SimplesIdeias::I18n.export!
|
10
|
-
end
|
11
|
-
|
12
|
-
desc "Update the JavaScript library"
|
13
|
-
task :update => :environment do
|
14
|
-
SimplesIdeias::I18n.update!
|
15
|
-
end
|
16
|
-
end
|