translation 1.24 → 1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +48 -22
- data/lib/translation.rb +4 -0
- data/lib/translation_io/client/base_operation/save_special_yaml_files_step.rb +3 -1
- data/lib/translation_io/client/init_operation.rb +2 -2
- data/lib/translation_io/client/sync_operation.rb +2 -2
- data/lib/translation_io/yaml_conversion.rb +8 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0d2f9ee1b57320b568bf17c4587f74a652ffe61c521d3fb1693d43d8ddbc67d
|
4
|
+
data.tar.gz: ce0293347ec5ade30b2faf5ee6d3698f7b1191895d4cdb6fb23f6c869d057ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2e07deb5a081fd8a0d8892b1f1c866db455f7194f7e3047141fccc5e76691997cf475d2a60fe20ed9c43c467f0f950fa9692bf8614ecc7fa2a49a960ef5d8fd
|
7
|
+
data.tar.gz: d53909fdc6398034776f0bb3e682b4d7b26c7edd32e6003098bda6c866249ac79e4af4be27bab7fdd507484d4d96006e6ca112a59ee4269e4d3d7fdd1f96c40c
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# [Translation.io](https://translation.io) client for Ruby on Rails
|
2
2
|
|
3
3
|
[](LICENSE)
|
4
|
-
[](https://travis-ci.com/translation/rails)
|
4
|
+
[](https://app.travis-ci.com/github/translation/rails)
|
5
5
|
[](https://codeclimate.com/github/translation/rails/test_coverage)
|
6
6
|
[](https://rubygems.org/gems/translation)
|
7
7
|
[](https://rubygems.org/gems/translation)
|
8
8
|
|
9
|
-
Add this gem to localize your Ruby on Rails application.
|
9
|
+
Add this gem to localize your **Ruby on Rails** application.
|
10
10
|
|
11
11
|
Use the official Rails syntax (with [YAML](#i18n-yaml) files) or use the [GetText](#gettext) syntax.
|
12
12
|
|
@@ -40,6 +40,8 @@ Table of contents
|
|
40
40
|
* [Globally](#globally)
|
41
41
|
* [Locally](#locally)
|
42
42
|
* [Frontend Localization](#frontend-localization)
|
43
|
+
* [Using this Gem](#using-this-gem)
|
44
|
+
* [Using our official React & JavaScript package](#using-our-official-react--javascript-package)
|
43
45
|
* [Continuous Integration](#continuous-integration)
|
44
46
|
* [Advanced Configuration Options](#advanced-configuration-options)
|
45
47
|
* [Disable GetText or YAML](#disable-gettext-or-yaml)
|
@@ -55,7 +57,7 @@ Table of contents
|
|
55
57
|
* [List of clients for Translation.io](#list-of-clients-for-translationio)
|
56
58
|
* [Ruby on Rails (Ruby)](#ruby-on-rails-ruby)
|
57
59
|
* [Laravel (PHP)](#laravel-php)
|
58
|
-
* [React and
|
60
|
+
* [React, React Native and JavaScript](#react-react-native-and-javascript)
|
59
61
|
* [Others](#others)
|
60
62
|
* [License](#license)
|
61
63
|
|
@@ -96,7 +98,7 @@ You can keep your source YAML file automatically updated using [i18n-tasks](http
|
|
96
98
|
This gem adds the GetText support to Rails. We [strongly suggest](https://translation.io/blog/gettext-is-better-than-rails-i18n)
|
97
99
|
that you use GetText to translate your application since it allows an easier and more complete syntax.
|
98
100
|
|
99
|
-
|
101
|
+
Moreover, you won't need to create and manage any YAML file since your code will be
|
100
102
|
automatically scanned for any string to translate.
|
101
103
|
|
102
104
|
```ruby
|
@@ -145,7 +147,7 @@ end
|
|
145
147
|
$ bundle exec rake translation:init
|
146
148
|
```
|
147
149
|
|
148
|
-
If you
|
150
|
+
If you need to add or remove languages in the future, please read our
|
149
151
|
[documentation](https://translation.io/blog/adding-target-languages) about that.
|
150
152
|
|
151
153
|
## Usage
|
@@ -178,7 +180,8 @@ $ bundle exec rake translation:sync_and_purge
|
|
178
180
|
|
179
181
|
As the name says, this operation will also perform a sync at the same time.
|
180
182
|
|
181
|
-
Warning: all keys that are not present in the current branch
|
183
|
+
Warning: all keys that are not present in the current local branch
|
184
|
+
will be **permanently deleted from Translation.io**.
|
182
185
|
|
183
186
|
## Manage Languages
|
184
187
|
|
@@ -222,10 +225,16 @@ Examples: `en-microsoft` or `fr-BE-custom`.
|
|
222
225
|
|
223
226
|
### Fallbacks
|
224
227
|
|
225
|
-
|
226
|
-
language
|
227
|
-
|
228
|
-
|
228
|
+
If a translation is missing for a regional (`fr-BE`) or custom (`fr-microsoft`)
|
229
|
+
language, then it will fallback to the main language (`fr`).
|
230
|
+
|
231
|
+
Locale fallbacks will work as expected with both [I18n (YAML)](#i18n-yaml)
|
232
|
+
and [GetText](#gettext) syntaxes.
|
233
|
+
|
234
|
+
A good way to leverage this feature is to ignore sentences from a regional language
|
235
|
+
that would have the same translation as the main language (usually most of them).
|
236
|
+
It's way easier to maintain the project over time if only 10% of the regional sentences
|
237
|
+
need to be adapted.
|
229
238
|
|
230
239
|
Note that fallbacks are chained, so `fr-BE-custom` will fallback to `fr-BE` that will
|
231
240
|
fallback to `fr`.
|
@@ -234,10 +243,6 @@ Just make sure to add `config.i18n.fallbacks = true` to your `config/application
|
|
234
243
|
You can find more information about this
|
235
244
|
[here](https://guides.rubyonrails.org/configuring.html#configuring-i18n).
|
236
245
|
|
237
|
-
Using [GetText](#gettext) syntax, it will only fallback to the source language.
|
238
|
-
So either you create a fallback mechanism by yourself or you avoid fallbacking
|
239
|
-
by translating everything in Translation.io for the regional or custom language.
|
240
|
-
|
241
246
|
## Change the current locale
|
242
247
|
|
243
248
|
### Globally
|
@@ -287,6 +292,8 @@ More examples here: https://translation.io/blog/rails-i18n-with-locale
|
|
287
292
|
|
288
293
|
## Frontend Localization
|
289
294
|
|
295
|
+
### Using this Gem
|
296
|
+
|
290
297
|
This gem is also able to cover frontend localization (React, Vue, ...).
|
291
298
|
|
292
299
|
There are several ways to pass the translation strings from the backend
|
@@ -299,10 +306,12 @@ Assuming that you use [reactjs/react-rails](https://github.com/reactjs/react-rai
|
|
299
306
|
it would look like this if you want to use [I18n (YAML)](#i18n-yaml) syntax:
|
300
307
|
|
301
308
|
```erb
|
302
|
-
<%=
|
309
|
+
<%=
|
310
|
+
react_component('MyComponent", {
|
303
311
|
:user_id => current_user.id,
|
304
312
|
:i18n => YAML.load_file("config/locales/#{I18n.locale}.yml")[I18n.locale.to_s]["my_component"]
|
305
|
-
})
|
313
|
+
})
|
314
|
+
%>
|
306
315
|
```
|
307
316
|
|
308
317
|
Your `en.yml` should look like this:
|
@@ -317,13 +326,15 @@ en:
|
|
317
326
|
You can also directly use the [GetText](#gettext) syntax:
|
318
327
|
|
319
328
|
```erb
|
320
|
-
<%=
|
329
|
+
<%=
|
330
|
+
react_component('MyComponent", {
|
321
331
|
:user_id => current_user.id,
|
322
332
|
:i18n => {
|
323
333
|
:your_name => _('Your name'),
|
324
334
|
:title => _('Title')
|
325
335
|
}
|
326
|
-
})
|
336
|
+
})
|
337
|
+
%>
|
327
338
|
```
|
328
339
|
|
329
340
|
In both case, in your React component, you can simply call
|
@@ -334,6 +345,18 @@ In both case, in your React component, you can simply call
|
|
334
345
|
* You can also structure the i18n props with multiple levels of depth and pass the subtree as props to each of your sub-components.
|
335
346
|
* It also works great with server-side rendering of your components (`:prerender => true`).
|
336
347
|
|
348
|
+
### Using our official React & JavaScript package
|
349
|
+
|
350
|
+
As Translation.io is directly integrated in the great
|
351
|
+
[Lingui](https://lingui.js.org/) internationalization framework,
|
352
|
+
you can also consider frontend localization as a completely different
|
353
|
+
localization project.
|
354
|
+
|
355
|
+
Please read more about this on:
|
356
|
+
|
357
|
+
* Website: [https://translation.io/lingui](https://translation.io/lingui)
|
358
|
+
* GitHub page: [https://github.com/translation/lingui](https://github.com/translation/lingui)
|
359
|
+
|
337
360
|
## Continuous Integration
|
338
361
|
|
339
362
|
If you want fresh translations in your Continuous Integration workflow, you may
|
@@ -597,12 +620,15 @@ Officially Supported on [https://translation.io/laravel](https://translation.io/
|
|
597
620
|
|
598
621
|
Credits: [@armandsar](https://github.com/armandsar), [@michaelhoste](https://github.com/michaelhoste)
|
599
622
|
|
600
|
-
### React and
|
623
|
+
### React, React Native and JavaScript
|
624
|
+
|
625
|
+
Officially Supported on [https://translation.io/lingui](https://translation.io/lingui)
|
601
626
|
|
602
|
-
|
603
|
-
|
627
|
+
Translation.io is directly integrated in the great
|
628
|
+
[Lingui](https://lingui.js.org/) internationalization project.
|
604
629
|
|
605
|
-
|
630
|
+
* GitHub: https://github.com/translation/lingui
|
631
|
+
* NPM: https://www.npmjs.com/package/@translation/lingui
|
606
632
|
|
607
633
|
### Others
|
608
634
|
|
data/lib/translation.rb
CHANGED
@@ -39,6 +39,10 @@ module TranslationIO
|
|
39
39
|
GetText::TextDomainManager.cached = false
|
40
40
|
end
|
41
41
|
|
42
|
+
# Set default GetText locale (last fallback) as config.source_locale instead of "en" (default)
|
43
|
+
gettext_locale = @config.source_locale.to_s.gsub('-', '_').to_sym
|
44
|
+
Locale.set_default(gettext_locale)
|
45
|
+
|
42
46
|
# include is private until Ruby 2.1
|
43
47
|
Proxy.send(:include, GetText)
|
44
48
|
|
@@ -35,7 +35,9 @@ module TranslationIO
|
|
35
35
|
YamlEntry.from_locale?(key, target_locale) && !YamlEntry.ignored?(key)
|
36
36
|
end
|
37
37
|
|
38
|
-
yaml_data = YAMLConversion.get_yaml_data_from_flat_translations(target_flat_special_translations
|
38
|
+
yaml_data = YAMLConversion.get_yaml_data_from_flat_translations(target_flat_special_translations, **{
|
39
|
+
:force_keep_empty_keys => true # We want to keep empty keys from localization.xx.yml files (sometimes needed for delimiters!)
|
40
|
+
})
|
39
41
|
|
40
42
|
params["yaml_data_#{target_locale}"] = yaml_data
|
41
43
|
|
@@ -13,8 +13,8 @@ module TranslationIO
|
|
13
13
|
haml_source_files = config.haml_source_files
|
14
14
|
slim_source_files = config.slim_source_files
|
15
15
|
pot_path = config.pot_path
|
16
|
-
source_locale = config.source_locale
|
17
|
-
target_locales = config.target_locales
|
16
|
+
source_locale = config.source_locale.to_s
|
17
|
+
target_locales = config.target_locales.map(&:to_s)
|
18
18
|
locales_path = config.locales_path
|
19
19
|
yaml_locales_path = config.yaml_locales_path
|
20
20
|
yaml_file_paths = config.yaml_file_paths
|
@@ -16,8 +16,8 @@ module TranslationIO
|
|
16
16
|
haml_source_files = config.haml_source_files
|
17
17
|
slim_source_files = config.slim_source_files
|
18
18
|
pot_path = config.pot_path
|
19
|
-
source_locale = config.source_locale
|
20
|
-
target_locales = config.target_locales
|
19
|
+
source_locale = config.source_locale.to_s
|
20
|
+
target_locales = config.target_locales.map(&:to_s)
|
21
21
|
locales_path = config.locales_path
|
22
22
|
yaml_locales_path = config.yaml_locales_path
|
23
23
|
yaml_file_paths = config.yaml_file_paths
|
@@ -35,9 +35,14 @@ module TranslationIO
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def get_yaml_data_from_flat_translations(flat_translations)
|
39
|
-
|
40
|
-
|
38
|
+
def get_yaml_data_from_flat_translations(flat_translations, force_keep_empty_keys: false)
|
39
|
+
if force_keep_empty_keys
|
40
|
+
remove_empty_keys = false
|
41
|
+
else
|
42
|
+
remove_empty_keys = TranslationIO.config.yaml_remove_empty_keys
|
43
|
+
end
|
44
|
+
|
45
|
+
translations = FlatHash.to_hash(flat_translations, remove_empty_keys)
|
41
46
|
|
42
47
|
if TranslationIO.config.yaml_line_width
|
43
48
|
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.29'
|
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: 2022-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gettext
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
version: 3.2.5
|
24
24
|
- - "<="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: 3.4.2
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
version: 3.2.5
|
37
37
|
- - "<="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 3.
|
39
|
+
version: 3.4.2
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|