asset_pipeline_i18n 3.2.8 → 3.2.13

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.
Files changed (3) hide show
  1. data/README.rdoc +29 -4
  2. data/lib/tasks/assets_i18n.rake +56 -55
  3. metadata +6 -6
data/README.rdoc CHANGED
@@ -23,17 +23,42 @@ In your application.rb
23
23
 
24
24
  config.assets.localized_precompile = ['application-it.js', 'application-fr.js', 'application-de.js', 'application-en.js']
25
25
 
26
- then
26
+ then you have to define one application-xx.js file for every locale like that:
27
27
 
28
- rake assets:precompile i18n:assets:precompile
28
+ //= require application
29
+
30
+ and of course, in your layout, you also have to use something like:
29
31
 
30
- Of course you also have to use something like:
31
32
  javascript_include_tag "application-#{I18n.locale}"
32
33
 
34
+ Finally:
35
+
36
+ rake assets:precompile i18n:assets:precompile
37
+
38
+ Sample application: https://github.com/pic/rails_asset_pipeline_i18n (thanks to Morgan Hallgren)
39
+
40
+ == Known problems
41
+
42
+ === Remove "require_tree ."
43
+
44
+ It is no more possible to write
45
+
46
+ //= require_tree .
47
+
48
+ in application.js because this will create a circular dependency now. One easy workaround is to move all the js files
49
+ in a subdirectory (e.g. lib) and then:
50
+
51
+ //= require_tree ./lib
52
+
53
+ === No proper i18n in development environment
54
+
55
+ This gem is intended for compiling translated assets for production environment.
56
+ Unfortunately it does not provide proper translations when running in development environment due to assets caching.
57
+
33
58
  == Versioning
34
59
 
35
60
  The idea is to use the same version number of the Rails version the gem is compatible with. So asset_pipeline_i18n version 3.2.5 is for Rails 3.2.5 and so on.
36
- If the gem is broken and we have to release a fix, then we will use a forth levelnumber, like 3.2.5.1
61
+ If the gem is broken and we have to release a fix, then we will use a forth level number, like 3.2.5.1
37
62
  To keep things easy, the dependency of the gem if of the form ~> x.x.x, so we assume that it works also with new versions of Rails, until proved otherwise :)
38
63
 
39
64
  == Contacts
@@ -1,7 +1,5 @@
1
1
  # actionpack-3.2.3/lib/sprockets/assets.rake
2
-
3
2
  require "fileutils"
4
-
5
3
  namespace :i18n do
6
4
  namespace :assets do
7
5
  def ruby_rake_task(task, fork = true)
@@ -11,9 +9,9 @@ namespace :i18n do
11
9
  args << "--trace" if Rake.application.options.trace
12
10
  if $0 =~ /rake\.bat\Z/i
13
11
  Kernel.exec $0, *args
14
- else
12
+ else
15
13
  fork ? ruby(*args) : Kernel.exec(FileUtils::RUBY, *args)
16
- end
14
+ end
17
15
  end
18
16
 
19
17
  # We are currently running with no explicit bundler group
@@ -31,129 +29,132 @@ namespace :i18n do
31
29
  task :precompile do
32
30
  invoke_or_reboot_rake_task "i18n:assets:precompile:all"
33
31
  end
34
-
32
+
35
33
  namespace :precompile do
36
-
37
34
  def internal_localized_precompile(digest = nil)
38
35
  unless Rails.application.config.assets.enabled
39
36
  warn "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
40
37
  exit
41
38
  end
42
-
39
+
43
40
  # Ensure that action view is loaded and the appropriate
44
41
  # sprockets hooks get executed
45
42
  _ = ActionView::Base
46
-
43
+
47
44
  config = Rails.application.config
48
45
  config.assets.compile = true
49
46
  config.assets.digest = digest unless digest.nil?
50
47
  config.assets.digests = {}
51
-
48
+
52
49
  # changes for i18n
53
50
  env = Rails.application.assets
54
51
  target = File.join(Rails.public_path, config.assets.prefix)
55
-
52
+
56
53
  asset = ENV['LOCALIZED_ASSET']
57
- # extract locale
58
- locale = asset.match(/.*-([[:alpha:]][[:alpha:]])\..*/)[1]
59
-
60
- I18n.locale = locale
61
-
62
- manifest_path = config.assets.manifest ? "#{config.assets.manifest}.#{locale}" : "#{target}/manifest.#{locale}"
63
- # end e18n
64
-
54
+ I18n.locale = manifest_locale(asset)
55
+
65
56
  compiler = Sprockets::StaticCompiler.new(env,
66
57
  target,
67
58
  [asset], # i18n change
68
- :manifest_path => manifest_path, # i18n change
59
+ :manifest_path => manifest_path(asset), # i18n change
69
60
  :digest => config.assets.digest,
70
61
  :manifest => digest.nil?)
71
62
  compiler.compile
72
63
  end
73
-
64
+
65
+ def manifest_locale(localized_asset)
66
+ localized_asset.match(/-([^.]+)/)[1]
67
+ end
68
+
69
+ def manifest_path(localized_asset)
70
+ (Rails.configuration.assets.manifest ? Rails.configuration.assets.manifest : File.join(Rails.public_path, Rails.configuration.assets.prefix)) + "/" + localized_asset.match(/([^.]+)/)[1]
71
+ end
72
+
73
+ def manifest_file
74
+ config = Rails.application.config
75
+ target = File.join(Rails.public_path, config.assets.prefix)
76
+ config.assets.manifest ? "#{config.assets.manifest}/manifest.yml" : "#{target}/manifest.yml"
77
+ end
78
+
74
79
  # i18n
75
80
  def merge_manifests
76
-
77
- config = Rails.application.config
78
- target = File.join(Rails.public_path, config.assets.prefix)
79
-
80
- manifest_file = config.assets.manifest ? "#{config.assets.manifest}/manifest.yml" : "#{target}/manifest.yml"
81
-
82
- manifest = {}
83
- if File.exist?(manifest_file)
84
- File.open(manifest_file) do |f|
85
- manifest = YAML::load(f)
86
- end
87
- else
81
+ puts "Merging all localized manifests into primary manifest..."
82
+
83
+ unless File.exist?(manifest_file)
88
84
  warn "Manifest file is missing. Please run standard assets:precompile before i18n:assets:precompile"
89
85
  exit 1
90
86
  end
91
-
92
- if config.assets.localized_precompile
93
- config.assets.localized_precompile.each do |asset|
94
- locale = asset.match(/.*-([[:alpha:]][[:alpha:]])\..*/)[1]
95
-
96
- localized_manifest_file = config.assets.manifest ? "#{config.assets.manifest}/manifest.#{locale}/manifest.yml" : "#{target}/manifest.#{locale}/manifest.yml"
97
- File.open(localized_manifest_file) do |f|
98
- localized_manifest = YAML::load(f)
99
- manifest.merge!(localized_manifest)
100
- end
87
+
88
+ manifest = nil
89
+ File.open(manifest_file) do |f|
90
+ manifest = YAML::load(f)
91
+ end
92
+
93
+ Array(Rails.application.config.assets.localized_precompile).each do |asset|
94
+ File.open(manifest_path(asset) + "/manifest.yml") do |f|
95
+ localized_manifest = YAML::load(f)
96
+ manifest.merge!(localized_manifest)
101
97
  end
102
98
  end
103
-
99
+
104
100
  File.open(manifest_file, 'wb') do |f|
105
101
  YAML.dump(manifest, f)
106
102
  end
107
103
  end
108
-
104
+
105
+ # i18n
106
+ def fixup_assets_manifest
107
+ assets_manifest_path = Rails.root.join("assets_manifest.yml")
108
+ puts "Copying primary manifest to #{assets_manifest_path}..."
109
+ FileUtils.cp(manifest_file, assets_manifest_path)
110
+ end
111
+
109
112
  # i18n
110
113
  task :merge_manifests do
111
114
  merge_manifests
112
115
  end
113
-
116
+
114
117
  task :all do
115
118
  ruby_rake_task "i18n:assets:precompile:localized"
116
-
117
119
  merge_manifests
120
+ fixup_assets_manifest
118
121
  end
119
-
122
+
120
123
  task :primary => ["assets:environment", "tmp:cache:clear"] do
121
124
  internal_precompile
122
125
  end
123
-
126
+
124
127
  task :nondigest => ["assets:environment", "tmp:cache:clear"] do
125
128
  internal_precompile(false)
126
129
  end
127
-
130
+
128
131
  # i18n
129
132
  task :localized do
130
133
  config = Rails.application.config
131
134
  if config.assets.localized_precompile
132
135
  config.assets.localized_precompile.each do |asset|
136
+ puts "Invoking assets precompile task for localized asset #{asset}..."
133
137
  ENV['LOCALIZED_ASSET'] = asset
134
138
  ruby_rake_task "i18n:assets:precompile:localized_asset"
135
139
  end
136
140
  end
137
141
  end
138
-
142
+
139
143
  # i18n
140
144
  task :localized_asset do
141
145
  Rake::Task["i18n:assets:precompile:localized_primary"].invoke
142
146
  ruby_rake_task("i18n:assets:precompile:localized_nondigest", false) if Rails.application.config.assets.digest
143
147
  end
144
-
148
+
145
149
  # i18n
146
150
  task :localized_primary => ["assets:environment", "tmp:cache:clear"] do
147
151
  internal_localized_precompile
148
152
  end
149
-
153
+
150
154
  # i18n
151
155
  task :localized_nondigest => ["assets:environment", "tmp:cache:clear"] do
152
156
  internal_localized_precompile(false)
153
157
  end
154
-
155
158
  end
156
-
157
159
  end
158
-
159
160
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_pipeline_i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.8
4
+ version: 3.2.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-13 00:00:00.000000000 Z
12
+ date: 2013-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.8
21
+ version: 3.2.13
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.2.8
29
+ version: 3.2.13
30
30
  description: Provide some additional rake task to precompile assets for any available
31
31
  locale
32
32
  email: nicola.piccinini@simplificator.com
@@ -34,9 +34,9 @@ executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
+ - lib/asset_pipeline_i18n.rb
37
38
  - lib/asset_pipeline_i18n/railtie.rb
38
39
  - lib/tasks/assets_i18n.rake
39
- - lib/asset_pipeline_i18n.rb
40
40
  - MIT-LICENSE
41
41
  - Rakefile
42
42
  - Gemfile
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
- rubygems_version: 1.8.21
64
+ rubygems_version: 1.8.25
65
65
  signing_key:
66
66
  specification_version: 3
67
67
  summary: Localized precompiled assets for rails