gettext_i18n_rails 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE.txt +20 -0
- data/lib/gettext_i18n_rails/version.rb +1 -1
- metadata +3 -29
- data/.gitignore +0 -2
- data/.travis.yml +0 -14
- data/Appraisals +0 -6
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -125
- data/Rakefile +0 -12
- data/Readme.md +0 -313
- data/gemfiles/rails23.gemfile +0 -16
- data/gemfiles/rails23.gemfile.lock +0 -73
- data/gemfiles/rails30.gemfile +0 -16
- data/gemfiles/rails30.gemfile.lock +0 -122
- data/gemfiles/rails31.gemfile +0 -16
- data/gemfiles/rails31.gemfile.lock +0 -132
- data/gemfiles/rails32.gemfile +0 -16
- data/gemfiles/rails32.gemfile.lock +0 -130
- data/gettext_i18n_rails.gemspec +0 -13
- data/init.rb +0 -14
- data/spec/gettext_i18n_rails/action_controller_spec.rb +0 -54
- data/spec/gettext_i18n_rails/active_model/name_spec.rb +0 -20
- data/spec/gettext_i18n_rails/active_record_spec.rb +0 -71
- data/spec/gettext_i18n_rails/backend_spec.rb +0 -106
- data/spec/gettext_i18n_rails/haml_parser_spec.rb +0 -50
- data/spec/gettext_i18n_rails/model_attributes_finder_spec.rb +0 -42
- data/spec/gettext_i18n_rails/slim_parser_spec.rb +0 -40
- data/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb +0 -32
- data/spec/gettext_i18n_rails_spec.rb +0 -91
- data/spec/spec_helper.rb +0 -112
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 623301d35d7171c487fa85ccd3c38e908ec9353e
|
4
|
+
data.tar.gz: 0fdb42391b384319f2e97cec0c8915468222d425
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53771e1602ea5452e617cbaa54cebeb2bbddace5b7ddb9a270f43eedc16adc8973c22f408b8c5e977e6d54a7f4846755a58d24688fd923b40c85a290c949c2ed
|
7
|
+
data.tar.gz: d7d88f58653a25ba059d81bd1077e1b55995eaf1d7efeec46891d820ed4542c89e4eaa9025bb1415d40098e0589b6bf836bafd582aee66fcaaff9c2ddcbafd63
|
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2013 Michael Grosser <michael@grosser.it>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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.3
|
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-
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_gettext
|
@@ -30,23 +30,7 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
- .
|
34
|
-
- .travis.yml
|
35
|
-
- Appraisals
|
36
|
-
- Gemfile
|
37
|
-
- Gemfile.lock
|
38
|
-
- Rakefile
|
39
|
-
- Readme.md
|
40
|
-
- gemfiles/rails23.gemfile
|
41
|
-
- gemfiles/rails23.gemfile.lock
|
42
|
-
- gemfiles/rails30.gemfile
|
43
|
-
- gemfiles/rails30.gemfile.lock
|
44
|
-
- gemfiles/rails31.gemfile
|
45
|
-
- gemfiles/rails31.gemfile.lock
|
46
|
-
- gemfiles/rails32.gemfile
|
47
|
-
- gemfiles/rails32.gemfile.lock
|
48
|
-
- gettext_i18n_rails.gemspec
|
49
|
-
- init.rb
|
33
|
+
- MIT-LICENSE.txt
|
50
34
|
- lib/gettext_i18n_rails.rb
|
51
35
|
- lib/gettext_i18n_rails/action_controller.rb
|
52
36
|
- lib/gettext_i18n_rails/active_model.rb
|
@@ -67,16 +51,6 @@ files:
|
|
67
51
|
- lib/gettext_i18n_rails/tasks.rb
|
68
52
|
- lib/gettext_i18n_rails/version.rb
|
69
53
|
- lib/tasks/gettext_rails_i18n.rake
|
70
|
-
- spec/gettext_i18n_rails/action_controller_spec.rb
|
71
|
-
- spec/gettext_i18n_rails/active_model/name_spec.rb
|
72
|
-
- spec/gettext_i18n_rails/active_record_spec.rb
|
73
|
-
- spec/gettext_i18n_rails/backend_spec.rb
|
74
|
-
- spec/gettext_i18n_rails/haml_parser_spec.rb
|
75
|
-
- spec/gettext_i18n_rails/model_attributes_finder_spec.rb
|
76
|
-
- spec/gettext_i18n_rails/slim_parser_spec.rb
|
77
|
-
- spec/gettext_i18n_rails/string_interpolate_fix_spec.rb
|
78
|
-
- spec/gettext_i18n_rails_spec.rb
|
79
|
-
- spec/spec_helper.rb
|
80
54
|
homepage: http://github.com/grosser/gettext_i18n_rails
|
81
55
|
licenses:
|
82
56
|
- MIT
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
bundler_args: ""
|
2
|
-
script: "bundle exec rake spec"
|
3
|
-
gemfile:
|
4
|
-
- gemfiles/rails23.gemfile
|
5
|
-
- gemfiles/rails30.gemfile
|
6
|
-
- gemfiles/rails31.gemfile
|
7
|
-
- gemfiles/rails32.gemfile
|
8
|
-
matrix:
|
9
|
-
exclude:
|
10
|
-
- rvm: 2.0
|
11
|
-
gemfile: gemfiles/rails23.gemfile
|
12
|
-
rvm:
|
13
|
-
- 1.9.3
|
14
|
-
- 2.0.0
|
data/Appraisals
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
gettext_i18n_rails (1.0.2)
|
5
|
-
fast_gettext (>= 0.4.8)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
actionmailer (4.0.0)
|
11
|
-
actionpack (= 4.0.0)
|
12
|
-
mail (~> 2.5.3)
|
13
|
-
actionpack (4.0.0)
|
14
|
-
activesupport (= 4.0.0)
|
15
|
-
builder (~> 3.1.0)
|
16
|
-
erubis (~> 2.7.0)
|
17
|
-
rack (~> 1.5.2)
|
18
|
-
rack-test (~> 0.6.2)
|
19
|
-
activemodel (4.0.0)
|
20
|
-
activesupport (= 4.0.0)
|
21
|
-
builder (~> 3.1.0)
|
22
|
-
activerecord (4.0.0)
|
23
|
-
activemodel (= 4.0.0)
|
24
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
25
|
-
activesupport (= 4.0.0)
|
26
|
-
arel (~> 4.0.0)
|
27
|
-
activerecord-deprecated_finders (1.0.3)
|
28
|
-
activesupport (4.0.0)
|
29
|
-
i18n (~> 0.6, >= 0.6.4)
|
30
|
-
minitest (~> 4.2)
|
31
|
-
multi_json (~> 1.3)
|
32
|
-
thread_safe (~> 0.1)
|
33
|
-
tzinfo (~> 0.3.37)
|
34
|
-
appraisal (0.5.2)
|
35
|
-
bundler
|
36
|
-
rake
|
37
|
-
arel (4.0.0)
|
38
|
-
atomic (1.1.12)
|
39
|
-
builder (3.1.4)
|
40
|
-
bump (0.4.2)
|
41
|
-
diff-lcs (1.2.4)
|
42
|
-
erubis (2.7.0)
|
43
|
-
fast_gettext (0.8.0)
|
44
|
-
gettext (3.0.2)
|
45
|
-
locale (>= 2.0.5)
|
46
|
-
text
|
47
|
-
haml (4.0.3)
|
48
|
-
tilt
|
49
|
-
hike (1.2.3)
|
50
|
-
i18n (0.6.4)
|
51
|
-
locale (2.0.9)
|
52
|
-
mail (2.5.4)
|
53
|
-
mime-types (~> 1.16)
|
54
|
-
treetop (~> 1.4.8)
|
55
|
-
mime-types (1.23)
|
56
|
-
minitest (4.7.5)
|
57
|
-
multi_json (1.7.8)
|
58
|
-
polyglot (0.3.3)
|
59
|
-
rack (1.5.2)
|
60
|
-
rack-test (0.6.2)
|
61
|
-
rack (>= 1.0)
|
62
|
-
rails (4.0.0)
|
63
|
-
actionmailer (= 4.0.0)
|
64
|
-
actionpack (= 4.0.0)
|
65
|
-
activerecord (= 4.0.0)
|
66
|
-
activesupport (= 4.0.0)
|
67
|
-
bundler (>= 1.3.0, < 2.0)
|
68
|
-
railties (= 4.0.0)
|
69
|
-
sprockets-rails (~> 2.0.0)
|
70
|
-
railties (4.0.0)
|
71
|
-
actionpack (= 4.0.0)
|
72
|
-
activesupport (= 4.0.0)
|
73
|
-
rake (>= 0.8.7)
|
74
|
-
thor (>= 0.18.1, < 2.0)
|
75
|
-
rake (10.1.0)
|
76
|
-
rspec (2.14.1)
|
77
|
-
rspec-core (~> 2.14.0)
|
78
|
-
rspec-expectations (~> 2.14.0)
|
79
|
-
rspec-mocks (~> 2.14.0)
|
80
|
-
rspec-core (2.14.4)
|
81
|
-
rspec-expectations (2.14.0)
|
82
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
83
|
-
rspec-mocks (2.14.2)
|
84
|
-
ruby_parser (3.2.2)
|
85
|
-
sexp_processor (~> 4.1)
|
86
|
-
sexp_processor (4.2.1)
|
87
|
-
slim (2.0.1)
|
88
|
-
temple (~> 0.6.6)
|
89
|
-
tilt (>= 1.3.3, < 2.1)
|
90
|
-
sprockets (2.10.0)
|
91
|
-
hike (~> 1.2)
|
92
|
-
multi_json (~> 1.0)
|
93
|
-
rack (~> 1.0)
|
94
|
-
tilt (~> 1.1, != 1.3.0)
|
95
|
-
sprockets-rails (2.0.0)
|
96
|
-
actionpack (>= 3.0)
|
97
|
-
activesupport (>= 3.0)
|
98
|
-
sprockets (~> 2.8)
|
99
|
-
sqlite3 (1.3.7)
|
100
|
-
temple (0.6.6)
|
101
|
-
text (1.2.3)
|
102
|
-
thor (0.18.1)
|
103
|
-
thread_safe (0.1.2)
|
104
|
-
atomic
|
105
|
-
tilt (1.4.1)
|
106
|
-
treetop (1.4.14)
|
107
|
-
polyglot
|
108
|
-
polyglot (>= 0.3.1)
|
109
|
-
tzinfo (0.3.37)
|
110
|
-
|
111
|
-
PLATFORMS
|
112
|
-
ruby
|
113
|
-
|
114
|
-
DEPENDENCIES
|
115
|
-
appraisal
|
116
|
-
bump
|
117
|
-
gettext (>= 3.0.2)
|
118
|
-
gettext_i18n_rails!
|
119
|
-
haml
|
120
|
-
rails
|
121
|
-
rake
|
122
|
-
rspec
|
123
|
-
ruby_parser (>= 3)
|
124
|
-
slim
|
125
|
-
sqlite3
|
data/Rakefile
DELETED
data/Readme.md
DELETED
@@ -1,313 +0,0 @@
|
|
1
|
-
[FastGettext](http://github.com/grosser/fast_gettext) / Rails integration.
|
2
|
-
|
3
|
-
Translate via FastGettext, use any other I18n backend as extension/fallback.
|
4
|
-
|
5
|
-
Rails does: `I18n.t('syntax.with.lots.of.dots')` with nested yml files
|
6
|
-
We do: `_('Just translate my damn text!')` with simple, flat mo/po/yml files or directly from db
|
7
|
-
To use I18n calls add a `syntax.with.lots.of.dots` translation.
|
8
|
-
|
9
|
-
[See it working in the example application.](https://github.com/grosser/gettext_i18n_rails_example)
|
10
|
-
|
11
|
-
Setup
|
12
|
-
=====
|
13
|
-
### Installation
|
14
|
-
|
15
|
-
#### Rails 3
|
16
|
-
|
17
|
-
##### As plugin:
|
18
|
-
|
19
|
-
rails plugin install git://github.com/grosser/gettext_i18n_rails.git
|
20
|
-
|
21
|
-
# Gemfile
|
22
|
-
gem 'fast_gettext', '>=0.4.8'
|
23
|
-
|
24
|
-
##### As gem:
|
25
|
-
|
26
|
-
# Gemfile
|
27
|
-
gem 'gettext_i18n_rails'
|
28
|
-
|
29
|
-
##### Optional:
|
30
|
-
Add `gettext` if you want to find translations or build .mo files<br/>
|
31
|
-
Add `ruby_parser` if you want to find translations inside haml/slim files
|
32
|
-
|
33
|
-
# Gemfile
|
34
|
-
gem 'gettext', '>=3.0.2', :require => false, :group => :development
|
35
|
-
gem 'ruby_parser', :require => false, :group => :development
|
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
|
-
|
52
|
-
#### Rails 2
|
53
|
-
|
54
|
-
##### As plugin:
|
55
|
-
|
56
|
-
script/plugin install git://github.com/grosser/gettext_i18n_rails.git
|
57
|
-
sudo gem install fast_gettext
|
58
|
-
|
59
|
-
# config/environment.rb
|
60
|
-
config.gem "fast_gettext", :version => '>=0.4.8'
|
61
|
-
|
62
|
-
##### As gem:
|
63
|
-
|
64
|
-
gem install gettext_i18n_rails
|
65
|
-
|
66
|
-
# config/environment.rb
|
67
|
-
config.gem 'gettext_i18n_rails'
|
68
|
-
|
69
|
-
#Rakefile
|
70
|
-
begin
|
71
|
-
require "gettext_i18n_rails/tasks"
|
72
|
-
rescue LoadError
|
73
|
-
puts "gettext_i18n_rails is not installed, you probably should run 'rake gems:install' or 'bundle install'."
|
74
|
-
end
|
75
|
-
|
76
|
-
##### Optional:
|
77
|
-
If you want to find translations or build .mo files
|
78
|
-
# config/environments/development.rb
|
79
|
-
config.gem "gettext", :version => '>=1.9.3', :lib => false
|
80
|
-
|
81
|
-
### Locales & initialisation
|
82
|
-
Copy default locales with dates/sentence-connectors/AR-errors you want from e.g.
|
83
|
-
[rails i18n](http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/) into 'config/locales'
|
84
|
-
|
85
|
-
To initialize:
|
86
|
-
|
87
|
-
# config/initializers/fast_gettext.rb
|
88
|
-
FastGettext.add_text_domain 'app', :path => 'locale', :type => :po
|
89
|
-
FastGettext.default_available_locales = ['en','de'] #all you want to allow
|
90
|
-
FastGettext.default_text_domain = 'app'
|
91
|
-
|
92
|
-
And in your application:
|
93
|
-
|
94
|
-
# app/controllers/application_controller.rb
|
95
|
-
class ApplicationController < ...
|
96
|
-
before_filter :set_gettext_locale
|
97
|
-
|
98
|
-
Translating
|
99
|
-
===========
|
100
|
-
Performance is almost the same for all backends since translations are cached after first use.
|
101
|
-
|
102
|
-
### Option A: .po files
|
103
|
-
|
104
|
-
FastGettext.add_text_domain 'app', :path => 'locale', :type => :po
|
105
|
-
|
106
|
-
- use some _('translations')
|
107
|
-
- run `rake gettext:find`, to let GetText find all translations used
|
108
|
-
- (optional) run `rake gettext:store_model_attributes`, to parse the database for columns that can be translated
|
109
|
-
- if this is your first translation: `cp locale/app.pot locale/de/app.po` for every locale you want to use
|
110
|
-
- translate messages in 'locale/de/app.po' (leave msgstr blank and msgstr == msgid)
|
111
|
-
|
112
|
-
New translations will be marked "fuzzy", search for this and remove it, so that they will be used.
|
113
|
-
Obsolete translations are marked with ~#, they usually can be removed since they are no longer needed
|
114
|
-
|
115
|
-
#### Unfound translations with rake gettext:find
|
116
|
-
Dynamic translations like `_("x"+"u")` cannot be fond. You have 4 options:
|
117
|
-
|
118
|
-
- add `N_('xu')` somewhere else in the code, so the parser sees it
|
119
|
-
- add `N_('xu')` in a totally separate file like `locale/unfound_translations.rb`, so the parser sees it
|
120
|
-
- use the [gettext_test_log rails plugin ](http://github.com/grosser/gettext_test_log) to find all translations that where used while testing
|
121
|
-
- add a Logger to a translation Chain, so every unfound translations is logged ([example]((http://github.com/grosser/fast_gettext)))
|
122
|
-
|
123
|
-
### Option B: Traditional .po/.mo files
|
124
|
-
|
125
|
-
FastGettext.add_text_domain 'app', :path => 'locale'
|
126
|
-
|
127
|
-
- follow Option A
|
128
|
-
- run `rake gettext:pack` to write binary GetText .mo files
|
129
|
-
|
130
|
-
### Option C: Database
|
131
|
-
Most scalable method, all translators can work simultaneously and online.
|
132
|
-
|
133
|
-
Easiest to use with the [translation database Rails engine](http://github.com/grosser/translation_db_engine).
|
134
|
-
Translations can be edited under `/translation_keys`
|
135
|
-
|
136
|
-
FastGettext::TranslationRepository::Db.require_models
|
137
|
-
FastGettext.add_text_domain 'app', :type => :db, :model => TranslationKey
|
138
|
-
|
139
|
-
I18n
|
140
|
-
====
|
141
|
-
I18n.locale <==> FastGettext.locale.to_sym
|
142
|
-
I18n.locale = :de <==> FastGettext.locale = 'de'
|
143
|
-
|
144
|
-
Any call to I18n that matches a gettext key will be translated through FastGettext.
|
145
|
-
|
146
|
-
Namespaces
|
147
|
-
==========
|
148
|
-
Car|Model means Model in namespace Car.
|
149
|
-
You do not have to translate this into english "Model", if you use the
|
150
|
-
namespace-aware translation
|
151
|
-
s_('Car|Model') == 'Model' #when no translation was found
|
152
|
-
|
153
|
-
XSS / html_safe
|
154
|
-
===============
|
155
|
-
If you trust your translators and all your usages of % on translations:<br/>
|
156
|
-
# config/environment.rb
|
157
|
-
GettextI18nRails.translations_are_html_safe = true
|
158
|
-
|
159
|
-
String % vs html_safe is buggy (can be used for XSS on 1.8 and is always non-safe in 1.9)<br/>
|
160
|
-
My recommended fix is: `require 'gettext_i18n_rails/string_interpolate_fix'`
|
161
|
-
|
162
|
-
- safe stays safe (escape added strings)
|
163
|
-
- unsafe stays unsafe (do not escape added strings)
|
164
|
-
|
165
|
-
ActiveRecord - error messages
|
166
|
-
=============================
|
167
|
-
ActiveRecord error messages are translated through Rails::I18n, but
|
168
|
-
model names and model attributes are translated through FastGettext.
|
169
|
-
Therefore a validation error on a BigCar's wheels_size needs `_('big car')` and `_('BigCar|Wheels size')`
|
170
|
-
to display localized.
|
171
|
-
|
172
|
-
The model/attribute translations can be found through `rake gettext:store_model_attributes`,
|
173
|
-
(which ignores some commonly untranslated columns like id,type,xxx_count,...).
|
174
|
-
|
175
|
-
Error messages can be translated through FastGettext, if the ':message' is a translation-id or the matching Rails I18n key is translated.
|
176
|
-
|
177
|
-
####Option A:
|
178
|
-
Define a translation for "I need my rating!" and use it as message.
|
179
|
-
validates_inclusion_of :rating, :in=>1..5, :message=>N_('I need my rating!')
|
180
|
-
|
181
|
-
####Option B:
|
182
|
-
validates_inclusion_of :rating, :in=>1..5
|
183
|
-
Make a translation for the I18n key: `activerecord.errors.models.rating.attributes.rating.inclusion`
|
184
|
-
|
185
|
-
####Option C:
|
186
|
-
Add a translation to each config/locales/*.yml files
|
187
|
-
en:
|
188
|
-
activerecord:
|
189
|
-
errors:
|
190
|
-
models:
|
191
|
-
rating:
|
192
|
-
attributes:
|
193
|
-
rating:
|
194
|
-
inclusion: " -- please choose!"
|
195
|
-
The [rails I18n guide](http://guides.rubyonrails.org/i18n.html) can help with Option B and C.
|
196
|
-
|
197
|
-
Plurals
|
198
|
-
=======
|
199
|
-
FastGettext supports pluralization
|
200
|
-
n_('Apple','Apples',3) == 'Apples'
|
201
|
-
|
202
|
-
Abnormal plurals like e.g. Polish that has 4 different can also be addressed, see [FastGettext Readme](http://github.com/grosser/fast_gettext)
|
203
|
-
|
204
|
-
Customizing list of translatable files
|
205
|
-
======================================
|
206
|
-
When you run
|
207
|
-
|
208
|
-
rake gettext:find
|
209
|
-
|
210
|
-
by default the following files are going to be scanned for translations: {app,lib,config,locale}/**/*.{rb,erb,haml,slim}. If
|
211
|
-
you want to specify a different list, you can redefine files_to_translate in the gettext namespace in a file like
|
212
|
-
lib/tasks/gettext.rake:
|
213
|
-
|
214
|
-
namespace :gettext do
|
215
|
-
def files_to_translate
|
216
|
-
Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,slim,rhtml}")
|
217
|
-
end
|
218
|
-
end
|
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
|
-
|
274
|
-
Using your translations from javascript
|
275
|
-
=======================================
|
276
|
-
|
277
|
-
If want to use your .PO files on client side javascript you should have a look at the [GettextI18nRailsJs](https://github.com/nubis/gettext_i18n_rails_js) extension.
|
278
|
-
|
279
|
-
[Contributors](http://github.com/grosser/gettext_i18n_rails/contributors)
|
280
|
-
======
|
281
|
-
- [ruby gettext extractor](http://github.com/retoo/ruby_gettext_extractor/tree/master) from [retoo](http://github.com/retoo)
|
282
|
-
- [Paul McMahon](http://github.com/pwim)
|
283
|
-
- [Duncan Mac-Vicar P](http://duncan.mac-vicar.com/blog)
|
284
|
-
- [Ramihajamalala Hery](http://my.rails-royce.org)
|
285
|
-
- [J. Pablo Fernández](http://pupeno.com)
|
286
|
-
- [Anh Hai Trinh](http://blog.onideas.ws)
|
287
|
-
- [ed0h](http://github.com/ed0h)
|
288
|
-
- [Nikos Dimitrakopoulos](http://blog.nikosd.com)
|
289
|
-
- [Ben Tucker](http://btucker.net/)
|
290
|
-
- [Kamil Śliwak](https://github.com/cameel)
|
291
|
-
- [Paul McMahon](https://github.com/pwim)
|
292
|
-
- [Rainux Luo](https://github.com/rainux)
|
293
|
-
- [Lucas Hills](https://github.com/2potatocakes)
|
294
|
-
- [Ladislav Slezák](https://github.com/lslezak)
|
295
|
-
- [Greg Weber](https://github.com/gregwebs)
|
296
|
-
- [Sean Kirby](https://github.com/sskirby)
|
297
|
-
- [Julien Letessier](https://github.com/mezis)
|
298
|
-
- [Seb Bacon](https://github.com/sebbacon)
|
299
|
-
- [Ramón Cahenzli](https://github.com/psy-q)
|
300
|
-
- [rustygeldmacher](https://github.com/rustygeldmacher)
|
301
|
-
- [Jeroen Knoops](https://github.com/JeroenKnoops)
|
302
|
-
- [Ivan Necas](https://github.com/iNecas)
|
303
|
-
- [Andrey Chernih](https://github.com/AndreyChernyh)
|
304
|
-
- [Imre Farkas](https://github.com/ifarkas)
|
305
|
-
- [Trong Tran](https://github.com/trongrg)
|
306
|
-
- [Dmitri Dolguikh](https://github.com/witlessbird)
|
307
|
-
- [Joe Ferris](https://github.com/jferris)
|
308
|
-
|
309
|
-
[Michael Grosser](http://grosser.it)<br/>
|
310
|
-
grosser.michael@gmail.com<br/>
|
311
|
-
License: MIT<br/>
|
312
|
-
[![Build Status](https://travis-ci.org/grosser/gettext_i18n_rails.png)](https://travis-ci.org/grosser/gettext_i18n_rails)
|
313
|
-
|