translation 1.32 → 1.34
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61a215cc27f4bfd0954d910e4d76f956e4b6fe54d9cb9caf74ba40cf665dcf83
|
4
|
+
data.tar.gz: e708d5f92493b6085d6062ce1588fa39927795e21805b0413cdcb0723b61ff94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e0e61144155c587eb7d031691d906bafd3611df7566b35adfce44b390b903e6a9c20a0bb8d37f71349c2a8f12731f834bfcc96ed1ffadeed44520197bdfab54
|
7
|
+
data.tar.gz: 6ac7e7b30dea348362b067fcf1a5a12240b60366941431ff5a4b25dcdad47574e33c428b4728dd49bf06ad1fe4b3785fd1238a2ae01a8d4b9a5149cda7675a17
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Use the official Rails syntax (with [YAML](#i18n-yaml) files) or use the [GetTex
|
|
12
12
|
|
13
13
|
Write only the source text, and keep it synchronized with your translators on [Translation.io](https://translation.io).
|
14
14
|
|
15
|
-
<a href="https://translation.io">
|
15
|
+
<a href="https://translation.io/rails">
|
16
16
|
<img width="720px" alt="Translation.io interface" src="https://translation.io/gifs/translation.gif">
|
17
17
|
</a>
|
18
18
|
|
@@ -20,10 +20,9 @@ Write only the source text, and keep it synchronized with your translators on [T
|
|
20
20
|
|
21
21
|
Need help? [contact@translation.io](mailto:contact@translation.io)
|
22
22
|
|
23
|
-
Table of contents
|
24
|
-
=================
|
23
|
+
## Table of contents
|
25
24
|
|
26
|
-
* [
|
25
|
+
* [Localization syntaxes](#localization-syntaxes)
|
27
26
|
* [I18n (YAML)](#i18n-yaml)
|
28
27
|
* [GetText](#gettext)
|
29
28
|
* [Installation](#installation)
|
@@ -52,23 +51,23 @@ Table of contents
|
|
52
51
|
* [Paths where locales are stored (not recommended)](#paths-where-locales-are-stored-not-recommended)
|
53
52
|
* [GetText Object Class Monkey-Patching](#gettext-object-class-monkey-patching)
|
54
53
|
* [Pure Ruby (without Rails)](#pure-ruby-without-rails)
|
55
|
-
* [Limitations](#limitations)
|
56
54
|
* [Testing](#testing)
|
57
55
|
* [Contributing](#contributing)
|
58
56
|
* [List of clients for Translation.io](#list-of-clients-for-translationio)
|
59
57
|
* [Ruby on Rails (Ruby)](#ruby-on-rails-ruby)
|
60
58
|
* [Laravel (PHP)](#laravel-php)
|
61
59
|
* [React, React Native and JavaScript](#react-react-native-and-javascript)
|
60
|
+
* [Angular](#angular)
|
62
61
|
* [Others](#others)
|
63
62
|
* [License](#license)
|
64
63
|
|
65
|
-
##
|
64
|
+
## Localization syntaxes
|
66
65
|
|
67
66
|
### I18n (YAML)
|
68
67
|
|
69
68
|
The default [Rails Internationalization API](http://guides.rubyonrails.org/i18n.html).
|
70
69
|
|
71
|
-
|
70
|
+
~~~ruby
|
72
71
|
# Regular
|
73
72
|
t('inbox.title')
|
74
73
|
|
@@ -77,11 +76,11 @@ t('inbox.message', count: n)
|
|
77
76
|
|
78
77
|
# Interpolation
|
79
78
|
t('inbox.hello', name: @user.name)
|
80
|
-
|
79
|
+
~~~
|
81
80
|
|
82
81
|
With the source YAML file:
|
83
82
|
|
84
|
-
|
83
|
+
~~~yaml
|
85
84
|
en:
|
86
85
|
inbox:
|
87
86
|
title: 'Title to be translated'
|
@@ -90,7 +89,7 @@ en:
|
|
90
89
|
one: 'one message'
|
91
90
|
other: '%{count} messages'
|
92
91
|
hello: 'Hello %{name}'
|
93
|
-
|
92
|
+
~~~
|
94
93
|
|
95
94
|
You can keep your source YAML file automatically updated using [i18n-tasks](https://github.com/glebm/i18n-tasks).
|
96
95
|
|
@@ -102,7 +101,7 @@ that you use GetText to translate your application since it allows an easier and
|
|
102
101
|
Moreover, you won't need to create and manage any YAML file since your code will be
|
103
102
|
automatically scanned for any string to translate.
|
104
103
|
|
105
|
-
|
104
|
+
~~~ruby
|
106
105
|
# Regular
|
107
106
|
_("Text to be translated")
|
108
107
|
|
@@ -117,7 +116,7 @@ np_("context", "Singular text", "Plural text", number)
|
|
117
116
|
|
118
117
|
# Interpolations
|
119
118
|
_('%{city1} is bigger than %{city2}') % { city1: "NYC", city2: "BXL" }
|
120
|
-
|
119
|
+
~~~
|
121
120
|
|
122
121
|
More information about GetText syntax [here](https://github.com/ruby-gettext/gettext#usage).
|
123
122
|
|
@@ -125,28 +124,28 @@ More information about GetText syntax [here](https://github.com/ruby-gettext/get
|
|
125
124
|
|
126
125
|
1. Add the gem to your project's Gemfile:
|
127
126
|
|
128
|
-
|
127
|
+
~~~ruby
|
129
128
|
gem 'translation'
|
130
|
-
|
129
|
+
~~~
|
131
130
|
|
132
131
|
2. Create a new translation project [from the UI](https://translation.io).
|
133
132
|
3. Copy the initializer into your Rails app (`config/initializers/translation.rb`)
|
134
133
|
|
135
134
|
The initializer looks like this:
|
136
135
|
|
137
|
-
|
136
|
+
~~~ruby
|
138
137
|
TranslationIO.configure do |config|
|
139
138
|
config.api_key = 'abcdefghijklmnopqrstuvwxyz012345'
|
140
139
|
config.source_locale = 'en'
|
141
140
|
config.target_locales = ['fr', 'nl', 'de', 'es']
|
142
141
|
end
|
143
|
-
|
142
|
+
~~~
|
144
143
|
|
145
144
|
4. Initialize your project and push existing translations to Translation.io with:
|
146
145
|
|
147
|
-
|
146
|
+
~~~bash
|
148
147
|
$ bundle exec rake translation:init
|
149
|
-
|
148
|
+
~~~
|
150
149
|
|
151
150
|
If you need to add or remove languages in the future, please read our
|
152
151
|
[documentation](https://translation.io/blog/adding-target-languages) about that.
|
@@ -157,17 +156,17 @@ If you need to add or remove languages in the future, please read our
|
|
157
156
|
|
158
157
|
To send new translatable keys/strings and get new translations from Translation.io, simply run:
|
159
158
|
|
160
|
-
|
159
|
+
~~~bash
|
161
160
|
$ bundle exec rake translation:sync
|
162
|
-
|
161
|
+
~~~
|
163
162
|
|
164
163
|
### Sync and Show Purgeable
|
165
164
|
|
166
165
|
If you need to find out what are the unused keys/strings from Translation.io, using the current branch as reference:
|
167
166
|
|
168
|
-
|
167
|
+
~~~bash
|
169
168
|
$ bundle exec rake translation:sync_and_show_purgeable
|
170
|
-
|
169
|
+
~~~
|
171
170
|
|
172
171
|
As the name says, this operation will also perform a sync at the same time.
|
173
172
|
|
@@ -175,9 +174,9 @@ As the name says, this operation will also perform a sync at the same time.
|
|
175
174
|
|
176
175
|
If you need to remove unused keys/strings from Translation.io, using the current branch as reference:
|
177
176
|
|
178
|
-
|
177
|
+
~~~bash
|
179
178
|
$ bundle exec rake translation:sync_and_purge
|
180
|
-
|
179
|
+
~~~
|
181
180
|
|
182
181
|
As the name says, this operation will also perform a sync at the same time.
|
183
182
|
|
@@ -216,9 +215,9 @@ or another instance of your application.
|
|
216
215
|
A custom language is always be derived from an [existing language](https://translation.io/docs/languages).
|
217
216
|
Its structure should be like:
|
218
217
|
|
219
|
-
|
218
|
+
~~~ruby
|
220
219
|
"#{existing_language_code}-#{custom_text}"
|
221
|
-
|
220
|
+
~~~
|
222
221
|
|
223
222
|
where `custom_text` can only contain alphabetic characters and `-`.
|
224
223
|
|
@@ -250,13 +249,13 @@ You can find more information about this
|
|
250
249
|
|
251
250
|
The easiest way to change the current locale is with `set_locale`.
|
252
251
|
|
253
|
-
|
252
|
+
~~~ruby
|
254
253
|
class ApplicationController < ActionController::Base
|
255
254
|
before_action :set_locale
|
256
255
|
|
257
256
|
[...]
|
258
257
|
end
|
259
|
-
|
258
|
+
~~~
|
260
259
|
|
261
260
|
First time the user will connect, it will automatically set the locale extracted
|
262
261
|
from the user's browser `HTTP_ACCEPT_LANGUAGE` value, and keep it in the session between
|
@@ -265,11 +264,11 @@ requests.
|
|
265
264
|
Update the current locale by redirecting the user to https://yourdomain.com?locale=fr
|
266
265
|
or even https://yourdomain.com/fr if you scoped your routes like this:
|
267
266
|
|
268
|
-
|
267
|
+
~~~ruby
|
269
268
|
scope "/:locale", :constraints => { locale: /[a-z]{2}/ } do
|
270
269
|
resources :pages
|
271
270
|
end
|
272
|
-
|
271
|
+
~~~
|
273
272
|
|
274
273
|
The `set_locale` code is [here](https://github.com/translation/rails/blob/master/lib/translation_io/controller.rb#L3),
|
275
274
|
feel free to override it with your own locale management.
|
@@ -283,9 +282,9 @@ More examples here: https://translation.io/blog/set-current-locale-in-your-rails
|
|
283
282
|
|
284
283
|
This command will change the locale for both [I18n (YAML)](#i18n-yaml) and [GetText](#gettext):
|
285
284
|
|
286
|
-
|
285
|
+
~~~ruby
|
287
286
|
I18n.locale = 'fr'
|
288
|
-
|
287
|
+
~~~
|
289
288
|
|
290
289
|
You can call it several times in the same page if you want to switch between languages.
|
291
290
|
|
@@ -306,29 +305,29 @@ translations as props when mounting the components.
|
|
306
305
|
Assuming that you use [reactjs/react-rails](https://github.com/reactjs/react-rails),
|
307
306
|
it would look like this if you want to use [I18n (YAML)](#i18n-yaml) syntax:
|
308
307
|
|
309
|
-
|
308
|
+
~~~erb
|
310
309
|
<%=
|
311
|
-
react_component(
|
310
|
+
react_component("MyComponent", {
|
312
311
|
:user_id => current_user.id,
|
313
312
|
:i18n => YAML.load_file("config/locales/#{I18n.locale}.yml")[I18n.locale.to_s]["my_component"]
|
314
313
|
})
|
315
314
|
%>
|
316
|
-
|
315
|
+
~~~
|
317
316
|
|
318
317
|
Your `en.yml` should look like this:
|
319
318
|
|
320
|
-
|
319
|
+
~~~yaml
|
321
320
|
en:
|
322
321
|
my_component:
|
323
322
|
your_name: Your name
|
324
323
|
title: Title
|
325
|
-
|
324
|
+
~~~
|
326
325
|
|
327
326
|
You can also directly use the [GetText](#gettext) syntax:
|
328
327
|
|
329
|
-
|
328
|
+
~~~erb
|
330
329
|
<%=
|
331
|
-
react_component(
|
330
|
+
react_component("MyComponent", {
|
332
331
|
:user_id => current_user.id,
|
333
332
|
:i18n => {
|
334
333
|
:your_name => _('Your name'),
|
@@ -336,7 +335,7 @@ react_component('MyComponent", {
|
|
336
335
|
}
|
337
336
|
})
|
338
337
|
%>
|
339
|
-
|
338
|
+
~~~
|
340
339
|
|
341
340
|
In both case, in your React component, you can simply call
|
342
341
|
`this.props.i18n.yourName` and your text will be localized with the current locale.
|
@@ -368,11 +367,11 @@ Since this task can't be concurrently executed
|
|
368
367
|
a queue but it returns an error under heavy load), we implemented this
|
369
368
|
threadsafe readonly task:
|
370
369
|
|
371
|
-
|
370
|
+
~~~bash
|
372
371
|
$ bundle exec rake translation:sync_readonly
|
373
|
-
|
372
|
+
~~~
|
374
373
|
|
375
|
-
This task will prevent your CI
|
374
|
+
This task will prevent your CI from failing and still provide new translations. But
|
376
375
|
be aware that it won't send new keys from your code to Translation.io so you
|
377
376
|
still need to call `bundle exec rake translation:sync` at some point during
|
378
377
|
development.
|
@@ -387,24 +386,24 @@ Some options are described below but for an exhaustive list, please refer to [co
|
|
387
386
|
|
388
387
|
If you want to only use YAML files and totally ignore GetText syntax, use:
|
389
388
|
|
390
|
-
|
389
|
+
~~~ruby
|
391
390
|
TranslationIO.configure do |config|
|
392
391
|
...
|
393
392
|
config.disable_gettext = true
|
394
393
|
...
|
395
394
|
end
|
396
|
-
|
395
|
+
~~~
|
397
396
|
|
398
397
|
In contrast, if you only want to synchronize GetText files and leave the YAML
|
399
398
|
files unchanged, use:
|
400
399
|
|
401
|
-
|
400
|
+
~~~ruby
|
402
401
|
TranslationIO.configure do |config|
|
403
402
|
...
|
404
403
|
config.disable_yaml = true
|
405
404
|
...
|
406
405
|
end
|
407
|
-
|
406
|
+
~~~
|
408
407
|
|
409
408
|
### Ignored YAML keys
|
410
409
|
|
@@ -413,7 +412,7 @@ You can use the `ignored_key_prefixes` for that.
|
|
413
412
|
|
414
413
|
For example:
|
415
414
|
|
416
|
-
|
415
|
+
~~~ruby
|
417
416
|
TranslationIO.configure do |config|
|
418
417
|
...
|
419
418
|
config.ignored_key_prefixes = [
|
@@ -428,7 +427,7 @@ TranslationIO.configure do |config|
|
|
428
427
|
]
|
429
428
|
...
|
430
429
|
end
|
431
|
-
|
430
|
+
~~~
|
432
431
|
|
433
432
|
### Custom localization key prefixes
|
434
433
|
|
@@ -448,13 +447,13 @@ to add some more, use the `localization_key_prefixes` option.
|
|
448
447
|
|
449
448
|
For example:
|
450
449
|
|
451
|
-
|
450
|
+
~~~ruby
|
452
451
|
TranslationIO.configure do |config|
|
453
452
|
...
|
454
453
|
config.localization_key_prefixes = ['my_gem.date.formats']
|
455
454
|
...
|
456
455
|
end
|
457
|
-
|
456
|
+
~~~
|
458
457
|
|
459
458
|
### Source file formats (for GetText)
|
460
459
|
|
@@ -467,7 +466,7 @@ If you are using GetText and you want to manage other file formats than:
|
|
467
466
|
|
468
467
|
Just add them in your configuration file like this:
|
469
468
|
|
470
|
-
|
469
|
+
~~~ruby
|
471
470
|
TranslationIO.configure do |config|
|
472
471
|
...
|
473
472
|
config.source_formats << 'rb2'
|
@@ -476,33 +475,33 @@ TranslationIO.configure do |config|
|
|
476
475
|
config.slim_source_formats << 'slim2'
|
477
476
|
...
|
478
477
|
end
|
479
|
-
|
478
|
+
~~~
|
480
479
|
|
481
480
|
### Gems with GetText strings
|
482
481
|
|
483
482
|
Public gems usually don't make use of GetText strings, but if you created and localized your own gems
|
484
483
|
with the GetText syntax, you'll want to be able to synchronize them:
|
485
484
|
|
486
|
-
|
485
|
+
~~~ruby
|
487
486
|
TranslationIO.configure do |config|
|
488
487
|
...
|
489
488
|
config.parsed_gems = ['your_gem_name']
|
490
489
|
...
|
491
490
|
end
|
492
|
-
|
491
|
+
~~~
|
493
492
|
|
494
493
|
### Paths where locales are stored (not recommended)
|
495
494
|
|
496
495
|
You can specify where your GetText and YAML files are on disk:
|
497
496
|
|
498
|
-
|
497
|
+
~~~ruby
|
499
498
|
TranslationIO.configure do |config|
|
500
499
|
...
|
501
500
|
config.locales_path = 'some/path' # defaults to config/locales/gettext
|
502
501
|
config.yaml_locales_path = 'some/path' # defaults to config/locales
|
503
502
|
...
|
504
503
|
end
|
505
|
-
|
504
|
+
~~~
|
506
505
|
|
507
506
|
### GetText Object Class Monkey-Patching
|
508
507
|
|
@@ -512,27 +511,27 @@ This is made by extending the global `Object` class.
|
|
512
511
|
You can disable the built-in `Object` monkey-patching if you
|
513
512
|
prefer a more granular approach:
|
514
513
|
|
515
|
-
|
514
|
+
~~~ruby
|
516
515
|
TranslationIO.configure do |config|
|
517
516
|
...
|
518
517
|
config.gettext_object_delegate = false
|
519
518
|
...
|
520
519
|
end
|
521
|
-
|
520
|
+
~~~
|
522
521
|
|
523
522
|
Don't forget to manually include the GetText methods where needed:
|
524
523
|
|
525
|
-
|
524
|
+
~~~ruby
|
526
525
|
class Contact < ApplicationRecord
|
527
526
|
extend TranslationIO::Proxy
|
528
527
|
end
|
529
|
-
|
528
|
+
~~~
|
530
529
|
|
531
530
|
## Pure Ruby (without Rails)
|
532
531
|
|
533
532
|
This gem was created specifically for Rails, but you can also use it in a pure Ruby project by making some arrangements:
|
534
533
|
|
535
|
-
|
534
|
+
~~~ruby
|
536
535
|
require 'rubygems'
|
537
536
|
require 'active_support/all'
|
538
537
|
require 'yaml'
|
@@ -579,44 +578,17 @@ This gem was created specifically for Rails, but you can also use it in a pure R
|
|
579
578
|
config.target_locales = ['nl', 'de']
|
580
579
|
config.metadata_path = 'i18n/.translation_io'
|
581
580
|
end
|
582
|
-
|
581
|
+
~~~
|
583
582
|
|
584
583
|
(Thanks [@kubaw](https://github.com/kubaw) for this snippet!)
|
585
584
|
|
586
|
-
## Limitations
|
587
|
-
|
588
|
-
If you localize `.erb` files with the [GetText syntax](#gettext), please avoid
|
589
|
-
the use of `case` and `when` that are not correctly parsed by ERB.
|
590
|
-
|
591
|
-
This syntax will break and your file will be ignored:
|
592
|
-
|
593
|
-
```erb
|
594
|
-
<% case @state %>
|
595
|
-
<% when 'received' %>
|
596
|
-
```
|
597
|
-
|
598
|
-
Instead, use `if`/`elsif` or this `case` syntax:
|
599
|
-
|
600
|
-
```erb
|
601
|
-
<%
|
602
|
-
case @state
|
603
|
-
when 'received'
|
604
|
-
%>
|
605
|
-
```
|
606
|
-
|
607
|
-
These are the related discussions: [ruby/erb#4](https://github.com/ruby/erb/issues/4) and [translation/rails#44](https://github.com/translation/rails/issues/44).
|
608
|
-
|
609
|
-
There is currently an open PR ([ruby-gettext/gettext#91](https://github.com/ruby-gettext/gettext/pull/91)), switching ERB for [Erubi](https://github.com/jeremyevans/erubi),
|
610
|
-
that is waiting to be merged into GetText, but it may have unknown undesirable
|
611
|
-
side effects.
|
612
|
-
|
613
585
|
## Testing
|
614
586
|
|
615
587
|
To run the specs:
|
616
588
|
|
617
|
-
|
589
|
+
~~~bash
|
618
590
|
$ bundle exec rspec
|
619
|
-
|
591
|
+
~~~
|
620
592
|
|
621
593
|
## Contributing
|
622
594
|
|
@@ -624,15 +596,16 @@ Please read the [CONTRIBUTING](CONTRIBUTING.md) file.
|
|
624
596
|
|
625
597
|
## List of clients for Translation.io
|
626
598
|
|
627
|
-
|
628
|
-
|
629
|
-
and some are not yet supported. However, they are quite well documented.
|
599
|
+
The following clients are officially supported by [Translation.io](https://translation.io)
|
600
|
+
and are well documented.
|
630
601
|
|
631
|
-
|
602
|
+
Some of these implementations (and other non-officially supported ones)
|
603
|
+
were started by contributors for their own translation projects.
|
604
|
+
We are thankful to all contributors for their hard work!
|
632
605
|
|
633
606
|
### Ruby on Rails (Ruby)
|
634
607
|
|
635
|
-
Officially
|
608
|
+
Officially supported on [https://translation.io/rails](https://translation.io/rails)
|
636
609
|
|
637
610
|
* GitHub: https://github.com/translation/rails
|
638
611
|
* RubyGems: https://rubygems.org/gems/translation/
|
@@ -641,7 +614,7 @@ Credits: [@aurels](https://github.com/aurels), [@michaelhoste](https://github.co
|
|
641
614
|
|
642
615
|
### Laravel (PHP)
|
643
616
|
|
644
|
-
Officially
|
617
|
+
Officially supported on [https://translation.io/laravel](https://translation.io/laravel)
|
645
618
|
|
646
619
|
* GitHub: https://github.com/translation/laravel
|
647
620
|
* Packagist: https://packagist.org/packages/tio/laravel
|
@@ -650,7 +623,7 @@ Credits: [@armandsar](https://github.com/armandsar), [@michaelhoste](https://git
|
|
650
623
|
|
651
624
|
### React, React Native and JavaScript
|
652
625
|
|
653
|
-
Officially
|
626
|
+
Officially supported on [https://translation.io/lingui](https://translation.io/lingui)
|
654
627
|
|
655
628
|
Translation.io is directly integrated in the great
|
656
629
|
[Lingui](https://lingui.js.org/) internationalization project.
|
@@ -658,6 +631,15 @@ Translation.io is directly integrated in the great
|
|
658
631
|
* GitHub: https://github.com/translation/lingui
|
659
632
|
* NPM: https://www.npmjs.com/package/@translation/lingui
|
660
633
|
|
634
|
+
### Angular
|
635
|
+
|
636
|
+
Officially supported on [https://translation.io/angular](https://translation.io/angular)
|
637
|
+
|
638
|
+
* GitHub: https://github.com/translation/angular
|
639
|
+
* NPM: https://www.npmjs.com/package/@translation/angular
|
640
|
+
|
641
|
+
Credits: [@SimonCorellia](https://github.com/SimonCorellia), [@didier-84](https://github.com/didier-84), [@michaelhoste](https://github.com/michaelhoste)
|
642
|
+
|
661
643
|
### Others
|
662
644
|
|
663
645
|
If you want to create a new client for your favorite language or framework, please read our
|
@@ -668,8 +650,8 @@ guide and use the special
|
|
668
650
|
|
669
651
|
You can also use the more [traditional API](https://translation.io/docs/api).
|
670
652
|
|
671
|
-
Feel free to contact us on [contact@translation.io](mailto:contact@translation.io)
|
672
|
-
you need some help or if you want to share your library.
|
653
|
+
Feel free to contact us on [contact@translation.io](mailto:contact@translation.io)
|
654
|
+
if you need some help or if you want to share your library.
|
673
655
|
|
674
656
|
## License
|
675
657
|
|
@@ -2,7 +2,8 @@ module TranslationIO
|
|
2
2
|
class Client
|
3
3
|
class BaseOperation
|
4
4
|
class SaveNewPoFilesStep
|
5
|
-
def initialize(target_locales, locales_path, parsed_response)
|
5
|
+
def initialize(source_locale, target_locales, locales_path, parsed_response)
|
6
|
+
@source_locale = source_locale
|
6
7
|
@target_locales = target_locales
|
7
8
|
@locales_path = locales_path
|
8
9
|
@parsed_response = parsed_response
|
@@ -25,8 +26,46 @@ module TranslationIO
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
create_source_po(text_domain)
|
30
|
+
|
28
31
|
return self
|
29
32
|
end
|
33
|
+
|
34
|
+
# Create source locale PO file, with identical source and target
|
35
|
+
# => Useful for correct fallbacks (cf. discussion https://github.com/translation/rails/issues/48)
|
36
|
+
def create_source_po(text_domain)
|
37
|
+
source_locale = Locale::Tag.parse(@source_locale)
|
38
|
+
|
39
|
+
pot_path = File.join(@locales_path, "#{text_domain}.pot")
|
40
|
+
po_path = File.join(@locales_path, source_locale.to_s, "#{text_domain}.po")
|
41
|
+
|
42
|
+
FileUtils.mkdir_p(File.dirname(po_path))
|
43
|
+
FileUtils.rm(po_path) if File.exist?(po_path)
|
44
|
+
|
45
|
+
# Generate source PO from POT and parse it
|
46
|
+
GetText::Tools::MsgInit.run('-i', pot_path, '-o', po_path, '-l', source_locale.to_s, '--no-translator')
|
47
|
+
po_entries = GetText::PO.new
|
48
|
+
GetText::POParser.new.parse(File.read(po_path), po_entries)
|
49
|
+
|
50
|
+
# With GetText after 3.3.9 and the introduction of optional `red-datasets` dependency, we need to complete the plural forms manually
|
51
|
+
# Source languages must have only 2 plural forms, and only 2 different pluralization rules exist for these languages
|
52
|
+
if %w(ak am as bn fa fr gu hi hy kn ln mg nso pa si ti zu).include?(source_locale.language)
|
53
|
+
po_entries[''].msgstr.gsub!('Plural-Forms: nplurals=; plural=;', 'Plural-Forms: nplurals=2; plural=n > 1;') # 0 and 1 are singular
|
54
|
+
else
|
55
|
+
po_entries[''].msgstr.gsub!('Plural-Forms: nplurals=; plural=;', 'Plural-Forms: nplurals=2; plural=n != 1;') # only 1 is singular
|
56
|
+
end
|
57
|
+
|
58
|
+
# Fill with same target as source and save it
|
59
|
+
po_entries.each do |po_entry|
|
60
|
+
if po_entry.msgid != '' # header
|
61
|
+
po_entry.msgstr = [po_entry.msgid, po_entry.msgid_plural].compact.join("\000")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
File.open(po_path, 'wb') do |file|
|
66
|
+
file.write(po_entries.to_s)
|
67
|
+
end
|
68
|
+
end
|
30
69
|
end
|
31
70
|
end
|
32
71
|
end
|
@@ -46,7 +46,7 @@ module TranslationIO
|
|
46
46
|
|
47
47
|
if !parsed_response.nil?
|
48
48
|
if !config.disable_gettext
|
49
|
-
BaseOperation::SaveNewPoFilesStep.new(target_locales, locales_path, parsed_response).run
|
49
|
+
BaseOperation::SaveNewPoFilesStep.new(source_locale, target_locales, locales_path, parsed_response).run
|
50
50
|
BaseOperation::CreateNewMoFilesStep.new(locales_path).run
|
51
51
|
end
|
52
52
|
|
@@ -54,7 +54,7 @@ module TranslationIO
|
|
54
54
|
|
55
55
|
if !parsed_response.nil?
|
56
56
|
if !config.disable_gettext
|
57
|
-
BaseOperation::SaveNewPoFilesStep.new(target_locales, locales_path, parsed_response).run
|
57
|
+
BaseOperation::SaveNewPoFilesStep.new(source_locale, target_locales, locales_path, parsed_response).run
|
58
58
|
BaseOperation::CreateNewMoFilesStep.new(locales_path).run
|
59
59
|
end
|
60
60
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'i18n'
|
2
2
|
require 'i18n/config'
|
3
|
+
require "i18n/backend/fallbacks"
|
3
4
|
|
4
5
|
module TranslationIO
|
5
6
|
class Railtie < Rails::Railtie
|
@@ -20,20 +21,32 @@ module TranslationIO
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
###
|
25
|
+
# Set GetText/Locale current locale based on I18n.locale
|
26
|
+
###
|
27
|
+
module I18nConfigExtension
|
28
|
+
def locale=(*args)
|
29
|
+
super
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
if defined? Locale
|
32
|
+
# GetText/Locale already uses default fallbacks ("en-us-custom" => "en-us" => "en-custom" => "en")
|
33
|
+
# But we want to add them custom fallbacks from I18n (ex: "fr" => "nl" => "en")
|
34
|
+
# cf. https://github.com/translation/rails/issues/48
|
35
|
+
fallback_locales = I18n.fallbacks[I18n.locale].collect { |l| l.to_s.gsub('-', '_').to_sym }
|
36
|
+
|
37
|
+
Locale.set_current(*fallback_locales)
|
32
38
|
end
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
|
-
|
42
|
+
I18n::Config.prepend I18nConfigExtension
|
43
|
+
|
44
|
+
###
|
45
|
+
# Monkey-Patch GetText to :
|
46
|
+
# * Ignore GetText warnings
|
47
|
+
# * Don't stop code parsing if a file is badly formatted + message
|
48
|
+
###
|
49
|
+
if defined? GetText
|
37
50
|
module GetText
|
38
51
|
class POParser < Racc::Parser
|
39
52
|
def initialize
|
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.34'
|
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: 2022-
|
12
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gettext
|