translation 1.23 → 1.24

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: 0046f449c37be1ceabd2d200b2cd017e5434e483c2accf142abd28ce13fabdab
4
- data.tar.gz: 7389645271366da1d14069303e473305138a055e952d100fea1f75198abaf1c6
3
+ metadata.gz: 8082495585677aa8e3ca187a4c4a443d3064e479010b4f7519d2ae7318ae5f66
4
+ data.tar.gz: 5e0f671d44c5aaa4436b4cff506444886a3f817f670f99eabb97b8a7534b7a5f
5
5
  SHA512:
6
- metadata.gz: bab9f0e545e1278a80ebaa8394d32529b0939f482c352b5aa2c6d82ffdc9362d73dcd36fdb5c1b42022179ad10a75e69b5f7b7018eb8e107f0a1169a74fa6816
7
- data.tar.gz: 7e2f84421230950705eaaff50248b9a23178a1d1095e1da1ee202b2c6a7d23a68cbdd4c173bb4512d7fff6ab2c7bf5386326843a90ea790fa4d8e3fdb0c41dc3
6
+ metadata.gz: 1407033d3f2b08b6429d4bbc10ce6997f2b7f72a8a24832a4b58cb018817a983059b3871cdd91d37fcaf44f9fc7127699ec4920108ac7944bce41e8a3355c62c
7
+ data.tar.gz: 71c9607dc017aeb3d3843eb462138c372636a752033216ae4211008ba013272e44f84c388ddae8dbbfb24d5679f87124d404e0b09b98262f4645fe3c9bb23b3d
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # [Translation.io](https://translation.io) client for Ruby on Rails
2
2
 
3
3
  [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
4
- [![Build Status](https://travis-ci.org/translation/rails.svg?branch=master)](https://travis-ci.org/translation/rails)
4
+ [![Build Status](https://travis-ci.com/translation/rails.svg?branch=master)](https://travis-ci.com/translation/rails)
5
5
  [![Test Coverage](https://codeclimate.com/github/translation/rails/badges/coverage.svg)](https://codeclimate.com/github/translation/rails/test_coverage)
6
6
  [![Gem Version](https://badgen.net/rubygems/v/translation)](https://rubygems.org/gems/translation)
7
7
  [![Downloads](https://img.shields.io/gem/dt/translation.svg)](https://rubygems.org/gems/translation)
@@ -39,6 +39,7 @@ Table of contents
39
39
  * [Change the current locale](#change-the-current-locale)
40
40
  * [Globally](#globally)
41
41
  * [Locally](#locally)
42
+ * [Frontend Localization](#frontend-localization)
42
43
  * [Continuous Integration](#continuous-integration)
43
44
  * [Advanced Configuration Options](#advanced-configuration-options)
44
45
  * [Disable GetText or YAML](#disable-gettext-or-yaml)
@@ -215,7 +216,7 @@ Its structure should be like:
215
216
  "#{existing_language_code}-#{custom_text}"
216
217
  ```
217
218
 
218
- where `custom_text` can only contain alphanumeric characters and `-`.
219
+ where `custom_text` can only contain alphabetic characters and `-`.
219
220
 
220
221
  Examples: `en-microsoft` or `fr-BE-custom`.
221
222
 
@@ -267,7 +268,8 @@ end
267
268
  The `set_locale` code is [here](https://github.com/translation/rails/blob/master/lib/translation_io/controller.rb#L3),
268
269
  feel free to override it with your own locale management.
269
270
 
270
- Don't forget to define your available locales with [I18n.available_locales](http://guides.rubyonrails.org/i18n.html#setup-the-rails-application-for-internationalization).
271
+ Don't forget to define your available locales with
272
+ [I18n.available_locales](http://guides.rubyonrails.org/i18n.html#setup-the-rails-application-for-internationalization).
271
273
 
272
274
  More examples here: https://translation.io/blog/set-current-locale-in-your-rails-app
273
275
 
@@ -283,17 +285,73 @@ You can call it several times in the same page if you want to switch between lan
283
285
 
284
286
  More examples here: https://translation.io/blog/rails-i18n-with-locale
285
287
 
288
+ ## Frontend Localization
289
+
290
+ This gem is also able to cover frontend localization (React, Vue, ...).
291
+
292
+ There are several ways to pass the translation strings from the backend
293
+ to the frontend: JavaScript serialization, `data-` HTML attributes, JSON files etc.
294
+
295
+ The easiest strategy when dealing with React/Vue would be to pass the corresponding
296
+ translations as props when mounting the components.
297
+
298
+ Assuming that you use [reactjs/react-rails](https://github.com/reactjs/react-rails),
299
+ it would look like this if you want to use [I18n (YAML)](#i18n-yaml) syntax:
300
+
301
+ ```erb
302
+ <%= react_component('MyComponent", {
303
+ :user_id => current_user.id,
304
+ :i18n => YAML.load_file("config/locales/#{I18n.locale}.yml")[I18n.locale.to_s]["my_component"]
305
+ }) %>
306
+ ```
307
+
308
+ Your `en.yml` should look like this:
309
+
310
+ ```yaml
311
+ en:
312
+ my_component:
313
+ your_name: Your name
314
+ title: Title
315
+ ```
316
+
317
+ You can also directly use the [GetText](#gettext) syntax:
318
+
319
+ ```erb
320
+ <%= react_component('MyComponent", {
321
+ :user_id => current_user.id,
322
+ :i18n => {
323
+ :your_name => _('Your name'),
324
+ :title => _('Title')
325
+ }
326
+ }) %>
327
+ ```
328
+
329
+ In both case, in your React component, you can simply call
330
+ `this.props.i18n.yourName` and your text will be localized with the current locale.
331
+
332
+ **Notes:**
333
+
334
+ * 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
+ * It also works great with server-side rendering of your components (`:prerender => true`).
336
+
286
337
  ## Continuous Integration
287
338
 
288
- If you want fresh translations in your Continuous Integration workflow, you may find yourself calling `bundle exec rake translation:sync` very frequently.
339
+ If you want fresh translations in your Continuous Integration workflow, you may
340
+ find yourself calling `bundle exec rake translation:sync` very frequently.
289
341
 
290
- Since this task can't be concurrently executed (we have a [mutex](https://en.wikipedia.org/wiki/Mutual_exclusion) strategy with a queue but it returns an error under heavy load), we implemented this threadsafe readonly task:
342
+ Since this task can't be concurrently executed
343
+ (we have a [mutex](https://en.wikipedia.org/wiki/Mutual_exclusion) strategy with
344
+ a queue but it returns an error under heavy load), we implemented this
345
+ threadsafe readonly task:
291
346
 
292
347
  ```bash
293
348
  $ bundle exec rake translation:sync_readonly
294
349
  ```
295
350
 
296
- This task will prevent your CI to fail and still provide new translations. But be aware that it won't send new keys from your code to Translation.io so you still need to call `bundle exec rake translation:sync` at some point during development.
351
+ This task will prevent your CI to fail and still provide new translations. But
352
+ be aware that it won't send new keys from your code to Translation.io so you
353
+ still need to call `bundle exec rake translation:sync` at some point during
354
+ development.
297
355
 
298
356
  ## Advanced Configuration Options
299
357
 
data/lib/translation.rb CHANGED
@@ -33,7 +33,6 @@ module TranslationIO
33
33
 
34
34
  if !@config.disable_gettext
35
35
  require_gettext_dependencies
36
- add_missing_locales
37
36
  add_parser_for_erb_source_formats(@config.erb_source_formats)
38
37
 
39
38
  if Rails.env.development?
@@ -71,12 +70,6 @@ module TranslationIO
71
70
  require 'gettext/tools/xgettext'
72
71
  end
73
72
 
74
- # Missing languages from Locale that are in Translation.io
75
- def add_missing_locales
76
- Locale::Info.three_languages['wee'] = Locale::Info::Language.new('', 'wee', 'I', 'L', 'Lower Sorbian')
77
- Locale::Info.three_languages['wen'] = Locale::Info::Language.new('', 'wen', 'I', 'L', 'Upper Sorbian')
78
- end
79
-
80
73
  def add_parser_for_erb_source_formats(new_erb_formats)
81
74
  existing_extensions = GetText::ErbParser.instance_variable_get("@config")[:extnames]
82
75
  new_extensions = new_erb_formats.collect { |ext| ".#{ext}" }
@@ -17,6 +17,38 @@ module TranslationIO
17
17
 
18
18
  private
19
19
 
20
+ def warn_wrong_locales(source_locale, target_locales)
21
+ if target_locales.uniq != target_locales
22
+ duplicate_locale = target_locales.detect { |locale| target_locales.count(locale) > 1 }
23
+
24
+ puts
25
+ puts "----------"
26
+ puts "Your `config.target_locales` has a duplicate locale (#{duplicate_locale})."
27
+ puts "Please clean your configuration file and execute this command again."
28
+ puts "----------"
29
+ exit(true)
30
+ end
31
+
32
+ if target_locales.include?(source_locale)
33
+ puts
34
+ puts "----------"
35
+ puts "The `config.source_locale` (#{source_locale}) can't be included in the `config.target_locales`."
36
+ puts "If you want to customize your source locale, check this link: https://github.com/translation/rails#custom-languages"
37
+ puts "Please clean your configuration file and execute this command again."
38
+ puts "----------"
39
+ exit(true)
40
+ end
41
+
42
+ if target_locales.empty?
43
+ puts
44
+ puts "----------"
45
+ puts "Your `config.target_locales` is empty."
46
+ puts "Please clean your configuration file and execute this command again."
47
+ puts "----------"
48
+ exit(true)
49
+ end
50
+ end
51
+
20
52
  def self.perform_request(uri, params)
21
53
  begin
22
54
  params.merge!({
@@ -19,6 +19,8 @@ module TranslationIO
19
19
  yaml_locales_path = config.yaml_locales_path
20
20
  yaml_file_paths = config.yaml_file_paths
21
21
 
22
+ warn_wrong_locales(source_locale, target_locales)
23
+
22
24
  if !config.disable_gettext
23
25
  BaseOperation::DumpMarkupGettextKeysStep.new(haml_source_files, :haml).run
24
26
  BaseOperation::DumpMarkupGettextKeysStep.new(slim_source_files, :slim).run
@@ -22,6 +22,8 @@ module TranslationIO
22
22
  yaml_locales_path = config.yaml_locales_path
23
23
  yaml_file_paths = config.yaml_file_paths
24
24
 
25
+ warn_wrong_locales(source_locale, target_locales)
26
+
25
27
  if !config.disable_yaml
26
28
  ApplyYamlSourceEditsStep.new(yaml_file_paths, source_locale).run(params)
27
29
  end
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.23'
4
+ version: '1.24'
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: 2021-01-17 00:00:00.000000000 Z
12
+ date: 2021-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gettext
@@ -21,6 +21,9 @@ dependencies:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 3.2.5
24
+ - - "<="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.3.7
24
27
  type: :runtime
25
28
  prerelease: false
26
29
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,6 +34,9 @@ dependencies:
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
36
  version: 3.2.5
37
+ - - "<="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.3.7
34
40
  - !ruby/object:Gem::Dependency
35
41
  name: rake
36
42
  requirement: !ruby/object:Gem::Requirement
@@ -65,14 +71,14 @@ dependencies:
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '2.14'
74
+ version: '3.0'
69
75
  type: :development
70
76
  prerelease: false
71
77
  version_requirements: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '2.14'
81
+ version: '3.0'
76
82
  - !ruby/object:Gem::Dependency
77
83
  name: rails
78
84
  requirement: !ruby/object:Gem::Requirement