gettext_i18n_rails 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Readme.md +69 -0
- data/lib/gettext_i18n_rails/tasks.rb +33 -18
- data/lib/gettext_i18n_rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b639edb5db08cc33d5d8e91ea03aa2bb4b05f7b
|
4
|
+
data.tar.gz: 0bdd9275776ba4458410db76f8cd588ab67da765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45eb5bd57c4597d22fd44233211d244b32bd9a168ef495b1cf3482a11f5ae6f0a21baae09f4919ae561242f70a9add71bf1ea3fc9449fd902ec2150d6da54691
|
7
|
+
data.tar.gz: e79b893ecbadeeeb8fafdadded2aef8c4c7e3ced9e38694e0189d6bf105dc199adeb32c4f5e9f32c3a3b2844f78a588ee88a16c21fd99d8be3cc400dbd26da8a
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -34,6 +34,21 @@ Add `ruby_parser` if you want to find translations inside haml/slim files
|
|
34
34
|
gem 'gettext', '>=3.0.2', :require => false, :group => :development
|
35
35
|
gem 'ruby_parser', :require => false, :group => :development
|
36
36
|
|
37
|
+
###### Add first language:
|
38
|
+
Add the first language using:
|
39
|
+
|
40
|
+
rake gettext:add_language[XX]
|
41
|
+
|
42
|
+
or
|
43
|
+
|
44
|
+
LANGUAGE=[XX] rake gettext:add_languange
|
45
|
+
|
46
|
+
where XX is the [ISO 639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) 2-letter code for the language you want to create.
|
47
|
+
|
48
|
+
This will also create the `locale` directory (where the translations are being stored) and run `gettext:find` to find any strings marked for translation.
|
49
|
+
|
50
|
+
You can, of course, add more languages using the same command.
|
51
|
+
|
37
52
|
#### Rails 2
|
38
53
|
|
39
54
|
##### As plugin:
|
@@ -202,6 +217,60 @@ lib/tasks/gettext.rake:
|
|
202
217
|
end
|
203
218
|
end
|
204
219
|
|
220
|
+
Customizing text domains setup task
|
221
|
+
===================================
|
222
|
+
|
223
|
+
By default a single application text domain is created (named `app` or if you load the environment the value of `FastGettext.text_domain` is being used).
|
224
|
+
|
225
|
+
If you want to have multiple text domains or change the definition of the text domains in any way, you can do so by overriding the `:setup` task in a file like lib/tasks/gettext.rake:
|
226
|
+
|
227
|
+
# Remove the provided gettext setup task
|
228
|
+
Rake::Task["gettext:setup"].clear
|
229
|
+
|
230
|
+
namespace :gettext do
|
231
|
+
task :setup => [:environment] do
|
232
|
+
domains = Application.config.gettext["domains"]
|
233
|
+
|
234
|
+
domains.each do |domain, options|
|
235
|
+
files = Dir.glob(options["paths"])
|
236
|
+
|
237
|
+
GetText::Tools::Task.define do |task|
|
238
|
+
task.package_name = options["name"]
|
239
|
+
task.package_version = "1.0.0"
|
240
|
+
task.domain = options["name"]
|
241
|
+
task.po_base_directory = locale_path
|
242
|
+
task.mo_base_directory = locale_path
|
243
|
+
task.files = files
|
244
|
+
task.enable_description = false
|
245
|
+
task.msgmerge_options = gettext_msgmerge_options
|
246
|
+
task.xgettext_options = gettext_xgettext_options
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
Changing msgmerge and xgettext options
|
253
|
+
======================================
|
254
|
+
|
255
|
+
The default options for parsing and create `.po` files are:
|
256
|
+
|
257
|
+
--sort-by-msgid --no-location --no-wrap
|
258
|
+
|
259
|
+
These options sort the translations by the msgid (original / source string), don't add location information in the po file and don't wrap long message lines into several lines.
|
260
|
+
|
261
|
+
If you want to override them you can put the following into an initializer like config/initializers/gettext.rb:
|
262
|
+
|
263
|
+
Rails.application.config.gettext_i18n_rails.msgmerge = %w[--no-location]
|
264
|
+
Rails.application.config.gettext_i18n_rails.xgettext = %w[--no-location]
|
265
|
+
|
266
|
+
or
|
267
|
+
|
268
|
+
Rails.application.config.gettext_i18n_rails.default_options = %w[--no-location]
|
269
|
+
|
270
|
+
to override both.
|
271
|
+
|
272
|
+
You can see the available options by running `rgettext -h` and `rxgettext -h`.
|
273
|
+
|
205
274
|
Using your translations from javascript
|
206
275
|
=======================================
|
207
276
|
|
@@ -17,33 +17,48 @@ namespace :gettext do
|
|
17
17
|
Dir.glob("{app,lib,config,#{locale_path}}/**/*.{rb,erb,haml,slim}")
|
18
18
|
end
|
19
19
|
|
20
|
+
def gettext_default_options
|
21
|
+
config = (Rails.application.config.gettext_i18n_rails.default_options if defined?(Rails.application))
|
22
|
+
config || %w[--sort-by-msgid --no-location --no-wrap]
|
23
|
+
end
|
24
|
+
|
25
|
+
def gettext_msgmerge_options
|
26
|
+
config = (Rails.application.config.gettext_i18n_rails.msgmerge if defined?(Rails.application))
|
27
|
+
config || gettext_default_options
|
28
|
+
end
|
29
|
+
|
30
|
+
def gettext_xgettext_options
|
31
|
+
config = (Rails.application.config.gettext_i18n_rails.xgettext if defined?(Rails.application))
|
32
|
+
config || gettext_default_options
|
33
|
+
end
|
34
|
+
|
20
35
|
$LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib') # needed when installed as plugin
|
21
36
|
|
22
37
|
require "gettext_i18n_rails/haml_parser"
|
23
38
|
require "gettext_i18n_rails/slim_parser"
|
24
39
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
config = (Rails.application.config.gettext_i18n_rails.xgettext if defined?(Rails.application))
|
38
|
-
task.xgettext_options = config || default
|
40
|
+
task :setup => [:environment] do
|
41
|
+
GetText::Tools::Task.define do |task|
|
42
|
+
task.package_name = text_domain
|
43
|
+
task.package_version = "1.0.0"
|
44
|
+
task.domain = text_domain
|
45
|
+
task.po_base_directory = locale_path
|
46
|
+
task.mo_base_directory = locale_path
|
47
|
+
task.files = files_to_translate
|
48
|
+
task.enable_description = false
|
49
|
+
task.msgmerge_options = gettext_msgmerge_options
|
50
|
+
task.xgettext_options = gettext_xgettext_options
|
51
|
+
end
|
39
52
|
end
|
40
53
|
|
41
|
-
desc "Create mo-files
|
42
|
-
task :pack => [:
|
54
|
+
desc "Create mo-files"
|
55
|
+
task :pack => [:setup] do
|
56
|
+
Rake::Task["gettext:mo:update"].invoke
|
43
57
|
end
|
44
58
|
|
45
|
-
desc "Update pot/po files
|
46
|
-
task :find => [:
|
59
|
+
desc "Update pot/po files"
|
60
|
+
task :find => [:setup] do
|
61
|
+
Rake::Task["gettext:po:update"].invoke
|
47
62
|
end
|
48
63
|
|
49
64
|
# This is more of an example, ignoring
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gettext_i18n_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_gettext
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.0.
|
100
|
+
rubygems_version: 2.0.3
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: Simple FastGettext Rails integration.
|