translation 1.31 → 1.33

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: 186fe35e21fca5df7945cce6f444396496bfafeafacad620c9f3ddfc4870f238
4
- data.tar.gz: 63f7e4ffd3ff3634ca1601d5aafd9f9ca6e029b78a60ffcc4cc1ca164056661d
3
+ metadata.gz: 12f034c3516c755d4e16fba0c8da4d25156107274d632369bc5fa2c8b85d1197
4
+ data.tar.gz: a6411bb6fa5ec979ed5d1677ec097bddba656c51354a4e212963bf581965213d
5
5
  SHA512:
6
- metadata.gz: 95d72a1cf231462570c6e9fd8fa67055b6245b4b76f733b2398ebfc484c7885199c57651973a85af47c2d413eaae8eed43762ee0aed7b72d1909c0fe7268e0a2
7
- data.tar.gz: 142b2e7206fff2e3eafc2d3581396aaa37ad6c6acf64869d99a2e83f7ac12a3286d048e1b26250de25a1f96f631c058398a66c1e0eb7d9c3db0fe2cbfe868333
6
+ metadata.gz: 0afec24d64ce82af45eb9d5abec7d60f1fde605dab0db823477a8a5c68690ad98301ca888388b17bc42a323fdd2be34e5646cce83c24f99037a3592c6946478f
7
+ data.tar.gz: e992ce43fef4c41ccc53294224ba6cbba154e481bed5e2410964c7daad6a99a22ef8d070b849c652214c68a660d701af2a6615a1b297b2be8e6d043d7faac3a6
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
- * [Translation syntaxes](#translation-syntaxes)
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
- ## Translation syntaxes
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
- ```ruby
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
- ```yaml
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```bash
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
- ```bash
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
- ```bash
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
- ```bash
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```erb
308
+ ~~~erb
310
309
  <%=
311
- react_component('MyComponent", {
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
- ```yaml
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
- ```erb
328
+ ~~~erb
330
329
  <%=
331
- react_component('MyComponent", {
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
- ```bash
370
+ ~~~bash
372
371
  $ bundle exec rake translation:sync_readonly
373
- ```
372
+ ~~~
374
373
 
375
- This task will prevent your CI to fail and still provide new translations. But
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```ruby
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
- ```bash
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
- These implementations were usually started by contributors for their own projects.
628
- Some of them are officially supported by [Translation.io](https://translation.io)
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
- Thanks a lot to these contributors for their hard work!
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 Supported on [https://translation.io/rails](https://translation.io/rails)
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 Supported on [https://translation.io/laravel](https://translation.io/laravel)
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 Supported on [https://translation.io/lingui](https://translation.io/lingui)
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) if
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
 
data/lib/translation.rb CHANGED
@@ -72,13 +72,20 @@ module TranslationIO
72
72
  require 'gettext/tools'
73
73
  require 'gettext/text_domain_manager'
74
74
  require 'gettext/tools/xgettext'
75
+ require "gettext/tools/parser/erubi" if Gem::Version.new(GetText::VERSION) >= Gem::Version.new('3.4.3')
75
76
  end
76
77
 
77
78
  def add_parser_for_erb_source_formats(new_erb_formats)
78
- existing_extensions = GetText::ErbParser.instance_variable_get("@config")[:extnames]
79
79
  new_extensions = new_erb_formats.collect { |ext| ".#{ext}" }
80
80
 
81
+ existing_extensions = GetText::ErbParser.instance_variable_get("@config")[:extnames]
81
82
  GetText::ErbParser.instance_variable_get("@config")[:extnames] = (existing_extensions + new_extensions).uniq
83
+
84
+ # for gettext >= 3.4.3 (erubi compatibility)
85
+ if defined?(GetText::ErubiParser)
86
+ existing_extensions = GetText::ErubiParser.instance_variable_get("@config")[:extnames]
87
+ GetText::ErubiParser.instance_variable_get("@config")[:extnames] = (existing_extensions + new_extensions).uniq
88
+ end
82
89
  end
83
90
 
84
91
  def info(message, level = 0, verbose_level = 0)
@@ -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,38 @@ 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).to_s
38
+
39
+ pot_path = File.join(@locales_path, "#{text_domain}.pot")
40
+ po_path = File.join(@locales_path, source_locale, "#{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, '--no-translator')
47
+ po_entries = GetText::PO.new
48
+ GetText::POParser.new.parse(File.read(po_path), po_entries)
49
+
50
+ # Fill with same target as source and save it
51
+ po_entries.each do |po_entry|
52
+ if po_entry.msgid != '' # header
53
+ po_entry.msgstr = [po_entry.msgid, po_entry.msgid_plural].compact.join("\000")
54
+ end
55
+ end
56
+
57
+ File.open(po_path, 'wb') do |file|
58
+ file.write(po_entries.to_s)
59
+ end
60
+ end
30
61
  end
31
62
  end
32
63
  end
@@ -16,12 +16,29 @@ module TranslationIO
16
16
  TranslationIO.info "Updating POT file."
17
17
 
18
18
  FileUtils.mkdir_p(File.dirname(@pot_path))
19
- GetText::Tools::XGetText.run(*@source_files, '-o', @pot_path,
20
- '--msgid-bugs-address', TranslationIO.config.pot_msgid_bugs_address,
21
- '--package-name', TranslationIO.config.pot_package_name,
22
- '--package-version', TranslationIO.config.pot_package_version,
23
- '--copyright-holder', TranslationIO.config.pot_copyright_holder,
24
- '--copyright-year', TranslationIO.config.pot_copyright_year.to_s)
19
+
20
+ # for gettext >= 3.4.3 (erubi compatibility)
21
+ if defined?(GetText::ErubiParser)
22
+ GetText::Tools::XGetText.run(
23
+ *@source_files, '-o', @pot_path,
24
+ '--msgid-bugs-address', TranslationIO.config.pot_msgid_bugs_address,
25
+ '--package-name', TranslationIO.config.pot_package_name,
26
+ '--package-version', TranslationIO.config.pot_package_version,
27
+ '--copyright-holder', TranslationIO.config.pot_copyright_holder,
28
+ '--copyright-year', TranslationIO.config.pot_copyright_year.to_s,
29
+ '--require', 'gettext/tools/parser/erubi', # Cf. (1) https://github.com/ruby-gettext/gettext/pull/91
30
+ '--parser', 'GetText::ErubiParser' # (2) https://github.com/ruby-gettext/gettext/commit/0eb06a88323a5cc16065680ffe228d978fb87c88
31
+ )
32
+ else
33
+ GetText::Tools::XGetText.run(
34
+ *@source_files, '-o', @pot_path,
35
+ '--msgid-bugs-address', TranslationIO.config.pot_msgid_bugs_address,
36
+ '--package-name', TranslationIO.config.pot_package_name,
37
+ '--package-version', TranslationIO.config.pot_package_version,
38
+ '--copyright-holder', TranslationIO.config.pot_copyright_holder,
39
+ '--copyright-year', TranslationIO.config.pot_copyright_year.to_s
40
+ )
41
+ end
25
42
 
26
43
  FileUtils.rm_f(@tmp_empty_file) if @tmp_empty_file.present?
27
44
 
@@ -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
- module I18n
24
- class Config
25
- def locale=(locale)
26
- I18n.enforce_available_locales!(locale) if I18n.respond_to?(:enforce_available_locales!)
27
- @locale = locale.to_sym rescue nil
24
+ ###
25
+ # Set GetText/Locale current locale based on I18n.locale
26
+ ###
27
+ module I18nConfigExtension
28
+ def locale=(*args)
29
+ super
28
30
 
29
- if defined?(GetText)
30
- GetText.set_current_locale(locale.to_s.gsub('-', '_').to_sym)
31
- end
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
- if defined?(GetText)
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.31'
4
+ version: '1.33'
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-04-04 00:00:00.000000000 Z
12
+ date: 2022-11-07 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.4.2
26
+ version: 3.4.3
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.4.2
39
+ version: 3.4.3
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rake
42
42
  requirement: !ruby/object:Gem::Requirement