translation 1.21 → 1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -40
- data/lib/translation_io/config.rb +5 -0
- data/lib/translation_io/flat_hash.rb +1 -1
- data/lib/translation_io/railtie.rb +4 -2
- data/lib/translation_io/yaml_conversion.rb +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d45218917c9c922310e60826327cd83f9537b07ece00d855a36a83327e04f8ef
|
4
|
+
data.tar.gz: '009b17548c9e57c0a696d7910cd9a75a4e1329049406a45449e1a17382c94b72'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
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
|
-
|
222
|
+
### Fallbacks
|
217
223
|
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
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
|
-
|
226
|
-
|
227
|
-
|
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
|
#######
|
@@ -7,8 +7,10 @@ module TranslationIO
|
|
7
7
|
require 'translation_io/tasks'
|
8
8
|
end
|
9
9
|
|
10
|
-
initializer 'translation.
|
11
|
-
|
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
|
-
|
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.
|
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:
|
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
|
-
|
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
|