gettext_i18n_rails 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -1,46 +1,52 @@
1
- Simple [FastGettext](http://github.com/grosser/fast_gettext) / Rails integration.
1
+ [FastGettext](http://github.com/grosser/fast_gettext) / Rails integration.
2
2
 
3
- Do all translations you want with FastGettext, use any other I18n backend as extension/fallback.
3
+ Translate via FastGettext, use any other I18n backend as extension/fallback.
4
4
 
5
- Rails does: `I18n.t('weir.rails.syntax.i.hate')`
6
- We do: `_('Just translate my damn text!')`
7
- To use I18n calls define a `weir.rails.syntax.i.hate` translation.
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
8
 
9
9
  [See it working in the example application.](https://github.com/grosser/gettext_i18n_rails_example)
10
10
 
11
11
  Setup
12
12
  =====
13
- ###Installation
14
- As plugin: ` script/plugin install git://github.com/grosser/gettext_i18n_rails.git `
15
- Or Gem: ` sudo gem install gettext_i18n_rails `
13
+ ### Installation
16
14
 
17
- [FastGettext](http://github.com/grosser/fast_gettext): ` sudo gem install fast_gettext `
15
+ #### Rails 3
18
16
 
19
- ### Want to find used messages in your ruby files ?
20
- GetText 1.93 or GetText 2.0: ` sudo gem install gettext `
21
- GetText 2.0 will render 1.93 unusable, so only install if you do not have apps that use 1.93!
17
+ ##### As plugin:
22
18
 
23
- ` sudo gem install ruby_parser `
19
+ rails plugin install git://github.com/grosser/gettext_i18n_rails.git
24
20
 
25
- ### Locales & initialisation
26
- Copy default locales with dates/sentence-connectors/AR-errors you want from e.g.
27
- [rails i18n](http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/) into 'config/locales'
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
+ If you want to find translations or build .mo files
31
+ # Gemfile
32
+ gem 'gettext', '>=1.9.3', :require => false, :group => :development
33
+
34
+ #### Rails 2
28
35
 
29
- Rails 2:
36
+ ##### As plugin:
37
+
38
+ script/plugin install git://github.com/grosser/gettext_i18n_rails.git
39
+ sudo gem install fast_gettext
30
40
 
31
41
  # config/environment.rb
32
42
  config.gem "fast_gettext", :version => '>=0.4.8'
33
43
 
34
- # only needed for mo/po file generation in development
35
- config.gem "gettext", :version => '>=1.9.3', :lib => false
36
-
37
- With bundler:
44
+ ##### As gem:
38
45
 
39
- # Gemfile
40
- gem 'fast_gettext', '>=0.4.8'
41
- gem 'gettext', '>=1.9.3', :require => false
46
+ gem install gettext_i18n_rails
42
47
 
43
- Installed as gem and on Rails 2? Add to your Rakefile:
48
+ # config/environment.rb
49
+ config.gem 'gettext_i18n_rails'
44
50
 
45
51
  #Rakefile
46
52
  begin
@@ -49,10 +55,19 @@ Installed as gem and on Rails 2? Add to your Rakefile:
49
55
  puts "gettext_i18n_rails is not installed, you probably should run 'rake gems:install' or 'bundle install'."
50
56
  end
51
57
 
58
+ ##### Optional:
59
+ If you want to find translations or build .mo files
60
+ # config/environments/development.rb
61
+ config.gem "gettext", :version => '>=1.9.3', :lib => false
62
+
63
+ ### Locales & initialisation
64
+ Copy default locales with dates/sentence-connectors/AR-errors you want from e.g.
65
+ [rails i18n](http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/) into 'config/locales'
66
+
52
67
  To initialize:
53
68
 
54
69
  # config/initializers/fast_gettext.rb
55
- FastGettext.add_text_domain 'app', :path => 'locale'
70
+ FastGettext.add_text_domain 'app', :path => 'locale', :type => :po
56
71
  FastGettext.default_available_locales = ['en','de'] #all you want to allow
57
72
  FastGettext.default_text_domain = 'app'
58
73
 
@@ -62,31 +77,49 @@ And in your application:
62
77
  class ApplicationController < ...
63
78
  before_filter :set_gettext_locale
64
79
 
65
-
66
80
  Translating
67
81
  ===========
68
- ###Getting started
69
- ####Option A: Traditional mo/po files
82
+ Performance is almost the same for all backends since translations are cached after first use.
83
+
84
+ ### Option A: .po files
85
+
86
+ FastGettext.add_text_domain 'app', :path => 'locale', :type => :po
87
+
70
88
  - use some _('translations')
71
89
  - run `rake gettext:find`, to let GetText find all translations used
72
90
  - (optional) run `rake gettext:store_model_attributes`, to parse the database for columns that can be translated
73
91
  - if this is your first translation: `cp locale/app.pot locale/de/app.po` for every locale you want to use
74
- - translate messages in 'locale/de/app.po' (leave msgstr blank and msgstr == msgid)
75
- new translations will be marked "fuzzy", search for this and remove it, so that they will be used.
92
+ - translate messages in 'locale/de/app.po' (leave msgstr blank and msgstr == msgid)
93
+
94
+ New translations will be marked "fuzzy", search for this and remove it, so that they will be used.
76
95
  Obsolete translations are marked with ~#, they usually can be removed since they are no longer needed
77
- - run `rake gettext:pack` to write GetText format translation files
78
96
 
79
- ####Option B: Database
80
- This is the most scalable method, since all translators can work simultanousely and online.
97
+ #### Unfound translations with rake gettext:find
98
+ Dynamic translations like `_("x"+"u")` cannot be fond. You have 4 options:
99
+
100
+ - add `N_('xu')` somewhere else in the code, so the parser sees it
101
+ - add `N_('xu')` in a totally separate file like `locale/unfound_translations.rb`, so the parser sees it
102
+ - use the [gettext_test_log rails plugin ](http://github.com/grosser/gettext_test_log) to find all translations that where used while testing
103
+ - add a Logger to a translation Chain, so every unfound translations is logged ([example]((http://github.com/grosser/fast_gettext)))
81
104
 
82
- Most easy to use with the [translation database Rails engine](http://github.com/grosser/translation_db_engine).
83
- FastGettext setup would look like:
84
- include FastGettext::TranslationRepository::Db.require_models #load and include default models
85
- FastGettext.add_text_domain 'app', :type=>:db, :model=>TranslationKey
105
+ ### Option B: Traditional .po/.mo files
106
+
107
+ FastGettext.add_text_domain 'app', :path => 'locale'
108
+
109
+ - follow Option A
110
+ - run `rake gettext:pack` to write binary GetText .mo files
111
+
112
+ ### Option C: Database
113
+ Most scalable method, all translators can work simultaneously and online.
114
+
115
+ Easiest to use with the [translation database Rails engine](http://github.com/grosser/translation_db_engine).
86
116
  Translations can be edited under `/translation_keys`
87
117
 
88
- ###I18n
118
+ FastGettext::TranslationRepository::Db.require_models
119
+ FastGettext.add_text_domain 'app', :type => :db, :model => TranslationKey
89
120
 
121
+ I18n
122
+ ====
90
123
  I18n.locale <==> FastGettext.locale.to_sym
91
124
  I18n.locale = :de <==> FastGettext.locale = 'de'
92
125
 
@@ -117,16 +150,14 @@ The model/attribute translations can be found through `rake gettext:store_model_
117
150
  (which ignores some commonly untranslated columns like id,type,xxx_count,...).
118
151
 
119
152
  Error messages can be translated through FastGettext, if the ':message' is a translation-id or the matching Rails I18n key is translated.
120
- In any other case they go through the SimpleBackend.
121
153
 
122
154
  ####Option A:
123
155
  Define a translation for "I need my rating!" and use it as message.
124
156
  validates_inclusion_of :rating, :in=>1..5, :message=>N_('I need my rating!')
125
157
 
126
158
  ####Option B:
127
- Do not use :message
128
159
  validates_inclusion_of :rating, :in=>1..5
129
- and make a translation for the I18n key: `activerecord.errors.models.rating.attributes.rating.inclusion`
160
+ Make a translation for the I18n key: `activerecord.errors.models.rating.attributes.rating.inclusion`
130
161
 
131
162
  ####Option C:
132
163
  Add a translation to each config/locales/*.yml files
@@ -145,20 +176,11 @@ Plurals
145
176
  FastGettext supports pluralization
146
177
  n_('Apple','Apples',3) == 'Apples'
147
178
 
148
- Unfound translations
149
- ====================
150
- Sometimes translations like `_("x"+"u")` cannot be fond. You have 4 options:
151
-
152
- - add `N_('xu')` somewhere else in the code, so the parser sees it
153
- - add `N_('xu')` in a totally seperate file like `locale/unfound_translations.rb`, so the parser sees it
154
- - use the [gettext_test_log rails plugin ](http://github.com/grosser/gettext_test_log) to find all translations that where used while testing
155
- - add a Logger to a translation Chain, so every unfound translations is logged ([example]((http://github.com/grosser/fast_gettext)))
156
-
179
+ Abnormal plurals like e.g. Polish that has 4 different can also be addressed, see [FastGettext Readme](http://github.com/grosser/fast_gettext)
157
180
 
158
181
  TODO
159
182
  =====
160
183
  - fix % on string to respect html_safe: `("<a>%{x}</a>".html_safe % {:x=>'<script>y</script>'})` should escape the `<script>y</script>` part)
161
- - refactor Readme
162
184
 
163
185
  Contributors
164
186
  ======
@@ -169,6 +191,6 @@ Contributors
169
191
  - [J. Pablo Fernández](http://pupeno.com)
170
192
  - [Anh Hai Trinh](http://blog.onideas.ws)
171
193
 
172
- [Michael Grosser](http://pragmatig.wordpress.com)
194
+ [Michael Grosser](http://grosser.it)
173
195
  grosser.michael@gmail.com
174
196
  Hereby placed under public domain, do what you want, just do not hold me accountable...
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gettext_i18n_rails}
8
- s.version = "0.2.6"
8
+ s.version = "0.2.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-09-27}
12
+ s.date = %q{2010-10-13}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.files = [
15
15
  ".gitignore",
@@ -109,7 +109,7 @@ module RubyGettextExtractor
109
109
  def new_call recv, meth, args = nil
110
110
  # we dont care if the method is called on a a object
111
111
  if recv.nil?
112
- if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext)
112
+ if (meth == :_ || meth == :p_ || meth == :N_ || meth == :pgettext || meth == :s_)
113
113
  key = extract_key(args, "\004")
114
114
  elsif meth == :n_
115
115
  key = extract_key(args, "\000")
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 6
9
- version: 0.2.6
8
+ - 7
9
+ version: 0.2.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-27 00:00:00 +02:00
17
+ date: 2010-10-13 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency