translation 1.21 → 1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ce80b91f3c556815df4339c5fc0b98f5749dd2babb378826053fe99751e5aec
4
- data.tar.gz: 1d4126693818e8220f41fa74f56e4d4eec61df651ac52f6429930fda9294a5b6
3
+ metadata.gz: d45218917c9c922310e60826327cd83f9537b07ece00d855a36a83327e04f8ef
4
+ data.tar.gz: '009b17548c9e57c0a696d7910cd9a75a4e1329049406a45449e1a17382c94b72'
5
5
  SHA512:
6
- metadata.gz: b17f56630fba322a948c31b84fb7ed006ef647f4cba40fe2f7ef78fd63e470f5dbbfd01f1ceb31627caabda3d27c0ea6e6c441f377709cc4291dbda07d5f4dc4
7
- data.tar.gz: cf424585ff16540e92679195faaa0dff8db5b30faa1b9355ed203fa0e07f1d5a114c643a071f22c4afb7545d2e82d553cd7012a88200319679528a870603bbc6
6
+ metadata.gz: b438efc2955b5db716b73e8d4ae1044135c6296f57ea829b8f5bc3ba8734ec0f7ff73678842b8a88a0826cc3d8ade340a9dc18ea66e874690ce932b2f9f8c849
7
+ data.tar.gz: e46d5e83c77b4f3f7fc0b0496c753ca6634b39f0043992b77f83ce604163a4e5433730cff5b3c77318df698a98d936f99a9986fc7b643da1d87c6f009b9b1fbb
data/README.md CHANGED
@@ -35,6 +35,7 @@ Table of contents
35
35
  * [Add or Remove Language](#add-or-remove-language)
36
36
  * [Edit Language](#edit-language)
37
37
  * [Custom Languages](#custom-languages)
38
+ * [Fallbacks](#fallbacks)
38
39
  * [Change the current locale](#change-the-current-locale)
39
40
  * [Globally](#globally)
40
41
  * [Locally](#locally)
@@ -42,9 +43,9 @@ Table of contents
42
43
  * [Advanced Configuration Options](#advanced-configuration-options)
43
44
  * [Disable GetText or YAML](#disable-gettext-or-yaml)
44
45
  * [Ignored YAML keys](#ignored-yaml-keys)
46
+ * [Custom localization key prefixes](#custom-localization-key-prefixes)
45
47
  * [Source file formats (for GetText)](#source-file-formats-for-gettext)
46
48
  * [Gems with GetText strings](#gems-with-gettext-strings)
47
- * [Custom localization key prefixes](#custom-localization-key-prefixes)
48
49
  * [Paths where locales are stored (not recommended)](#paths-where-locales-are-stored-not-recommended)
49
50
  * [GetText Object Class Monkey-Patching](#gettext-object-class-monkey-patching)
50
51
  * [Pure Ruby (without Rails)](#pure-ruby-without-rails)
@@ -204,27 +205,37 @@ Since you created a new project, the translation history and tags will unfortuna
204
205
 
205
206
  ### Custom Languages
206
207
 
207
- A custom language is always derived from an existing language. It's useful if you want
208
- to adapt some translations to another instance of your application, or to a specific
209
- customer.
208
+ Custom languages are convenient if you want to customize translations for a specific customer
209
+ or another instance of your application.
210
+
211
+ A custom language is always be derived from an [existing language](https://translation.io/docs/languages).
212
+ Its structure should be like:
213
+
214
+ ```ruby
215
+ "#{existing_language_code}-#{custom_text}"
216
+ ```
210
217
 
211
- The structure of a custom language is: `existing language code` + `-` + `custom text`, where
212
- `custom text` can only contain alphanumeric characters and `-`.
218
+ where `custom_text` can only contain alphanumeric characters and `-`.
213
219
 
214
220
  Examples: `en-microsoft` or `fr-BE-custom`.
215
221
 
216
- Custom languages can be added and used like any other language.
222
+ ### Fallbacks
217
223
 
218
- Fallbacks work as expected. It means that if the `en-microsoft.some_key` is missing,
219
- then it will fallback to `en.some_key`. So you only need to translate keys that
220
- should be customized.
224
+ Using [I18n (YAML)](#i18n-yaml) syntax, fallbacks will work as expected for any regional or custom
225
+ language. It means that if the `en-microsoft.example` key is missing,
226
+ then it will fallback to `en.example`. So you only need to translate keys that
227
+ are different from the main language.
221
228
 
222
- Note that fallback are chained, so `fr-BE-custom` will fallback to `fr-BE` that will
229
+ Note that fallbacks are chained, so `fr-BE-custom` will fallback to `fr-BE` that will
223
230
  fallback to `fr`.
224
231
 
225
- Using GetText syntax, it will only fallback to the source language. So either you
226
- create a fallback mechanism by yourself or you avoid fallbacking
227
- by translating everything in Translation.io for that custom language.
232
+ Just make sure to add `config.i18n.fallbacks = true` to your `config/application.rb` file.
233
+ You can find more information about this
234
+ [here](https://guides.rubyonrails.org/configuring.html#configuring-i18n).
235
+
236
+ Using [GetText](#gettext) syntax, it will only fallback to the source language.
237
+ So either you create a fallback mechanism by yourself or you avoid fallbacking
238
+ by translating everything in Translation.io for the regional or custom language.
228
239
 
229
240
  ## Change the current locale
230
241
 
@@ -337,6 +348,32 @@ TranslationIO.configure do |config|
337
348
  end
338
349
  ```
339
350
 
351
+ ### Custom localization key prefixes
352
+
353
+ Rails YAML files contain not only translation strings but also localization values (integers, arrays, booleans)
354
+ in the same place and that's bad. For example: date formats, number separators, default
355
+ currency or measure units, etc.
356
+
357
+ A translator is supposed to translate, not localize. That's not his role to choose how you want your dates or
358
+ numbers to be displayed, right? Moreover, this special keys often contain special constructions (e.g.,
359
+ with percent signs or spaces) that he might break.
360
+
361
+ We think localization is part of the configuration of the app and it should not reach the translator UI at all.
362
+ That's why these localization keys are detected and separated on a dedicated YAML file with Translation.io.
363
+
364
+ We automatically treat [known localization keys](lib/translation_io/yaml_entry.rb), but if you would like
365
+ to add some more, use the `localization_key_prefixes` option.
366
+
367
+ For example:
368
+
369
+ ```ruby
370
+ TranslationIO.configure do |config|
371
+ ...
372
+ config.localization_key_prefixes = ['my_gem.date.formats']
373
+ ...
374
+ end
375
+ ```
376
+
340
377
  ### Source file formats (for GetText)
341
378
 
342
379
  If you are using GetText and you want to manage other file formats than:
@@ -372,32 +409,6 @@ TranslationIO.configure do |config|
372
409
  end
373
410
  ```
374
411
 
375
- ### Custom localization key prefixes
376
-
377
- Rails YAML files contain not only translation strings but also localization values (integers, arrays, booleans)
378
- in the same place and that's bad. For example: date formats, number separators, default
379
- currency or measure units, etc.
380
-
381
- A translator is supposed to translate, not localize. That's not his role to choose how you want your dates or
382
- numbers to be displayed, right? Moreover, this special keys often contain special constructions (e.g.,
383
- with percent signs or spaces) that he might break.
384
-
385
- We think localization is part of the configuration of the app and it should not reach the translator UI at all.
386
- That's why these localization keys are detected and separated on a dedicated YAML file with Translation.io.
387
-
388
- We automatically treat [known localization keys](lib/translation_io/yaml_entry.rb), but if you would like
389
- to add some more, use the `localization_key_prefixes` option.
390
-
391
- For example:
392
-
393
- ```ruby
394
- TranslationIO.configure do |config|
395
- ...
396
- config.localization_key_prefixes = ['my_gem.date.formats']
397
- ...
398
- end
399
- ```
400
-
401
412
  ### Paths where locales are stored (not recommended)
402
413
 
403
414
  You can specify where your GetText and YAML files are on disk:
@@ -14,6 +14,7 @@ module TranslationIO
14
14
  attr_accessor :ignored_key_prefixes
15
15
  attr_accessor :localization_key_prefixes
16
16
  attr_accessor :yaml_line_width
17
+ attr_accessor :yaml_remove_empty_keys
17
18
 
18
19
  attr_accessor :disable_gettext
19
20
 
@@ -75,6 +76,10 @@ module TranslationIO
75
76
  # Cf. https://github.com/translation/rails/issues/19
76
77
  self.yaml_line_width = nil
77
78
 
79
+ # Remove empty keys from translated YAML files
80
+ # Cf. https://github.com/translation/rails/pull/37
81
+ self.yaml_remove_empty_keys = false
82
+
78
83
  #######
79
84
  # GetText options
80
85
  #######
@@ -11,7 +11,7 @@ module TranslationIO
11
11
  hash = {}
12
12
 
13
13
  if remove_empty_keys
14
- flat_hash = flat_hash.reject { |k, v| v.nil? && !k.end_with?(']') }
14
+ flat_hash = flat_hash.reject { |k, v| v.blank? && !k.end_with?(']') }
15
15
  end
16
16
 
17
17
  flat_hash.each_pair do |key, value|
@@ -7,8 +7,10 @@ module TranslationIO
7
7
  require 'translation_io/tasks'
8
8
  end
9
9
 
10
- initializer 'translation.rails_extensions' do
11
- ActionController::Base.send(:include, TranslationIO::Controller)
10
+ initializer 'translation.controller_helper' do
11
+ ActiveSupport.on_load :action_controller do
12
+ ActionController::Base.send(:include, TranslationIO::Controller)
13
+ end
12
14
  end
13
15
 
14
16
  config.after_initialize do
@@ -36,7 +36,8 @@ module TranslationIO
36
36
  end
37
37
 
38
38
  def get_yaml_data_from_flat_translations(flat_translations)
39
- translations = FlatHash.to_hash(flat_translations)
39
+ remove_empty_keys = TranslationIO.config.yaml_remove_empty_keys
40
+ translations = FlatHash.to_hash(flat_translations, remove_empty_keys)
40
41
 
41
42
  if TranslationIO.config.yaml_line_width
42
43
  data = translations.to_yaml(:line_width => TranslationIO.config.yaml_line_width)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translation
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.21'
4
+ version: '1.22'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hoste
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-30 00:00:00.000000000 Z
12
+ date: 2020-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gettext
@@ -143,7 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.0.3
146
+ rubyforge_project:
147
+ rubygems_version: 2.7.6
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: Localize your app with YAML or GetText. Synchronize with your translators