translation 1.14 → 1.15

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
  SHA1:
3
- metadata.gz: 23364df129fca187e3e946e7e9630262c688095d
4
- data.tar.gz: 879857716430eac90526ba693bbcb5a2610a8959
3
+ metadata.gz: 934c23560bd3bdc6415760fc3ba9d73b277ab308
4
+ data.tar.gz: 4b0877a129c080dcd85e2c2941590733280e59b5
5
5
  SHA512:
6
- metadata.gz: 47bebb33125a5f88741b3e073968fa457ac94ebfe6780e38949b97cd64ad455cdc7df103fe7e95b74b5c9a934180d6b8ee2161f797f95c321fcedd223c53affc
7
- data.tar.gz: 4d17d4bca46162e0835129a293c9e80f69fa9df5239ca5b56dcb3b06a8de9ae479c3df9085599c4b2f5a9a56dd2deb8eb3bc421d9e96d32069ff6cc1b318ebe7
6
+ metadata.gz: bd902636f402c04540bff588f873ecdb64ca3de86a97031cff66c659a9e30039104dc37e5153b8655495678bbf6c9be2d810497f97f892ea46c46d996d13e246
7
+ data.tar.gz: 7ce437178c97a21e5d75377e76078ec1619db2c0771afa3a4ff3dd17bcd043e1cfa1e47ef0f1feafaa3dc59ec34fe111da403d7888dd75574fc5afa703741b1c
data/README.md CHANGED
@@ -1,15 +1,22 @@
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.md)
4
- [![Codeship Status](https://app.codeship.com/projects/f7cd4ac0-b73c-0131-51ea-522dcd2196ed/status?branch=master)](https://app.codeship.com/projects/20528)
5
- [![Test Coverage](https://codeclimate.com/github/aurels/translation-gem/badges/coverage.svg)](https://codeclimate.com/github/aurels/translation-gem/coverage)
4
+ [![Build Status](https://img.shields.io/travis/translation/rails/master.svg?style=flat-square)](https://travis-ci.org/translation/rails)
5
+ [![Test Coverage](https://codeclimate.com/github/translation/rails/badges/coverage.svg)](https://codeclimate.com/github/translation/rails/coverage)
6
+ [![Gem Version](https://badge.fury.io/rb/translation.svg)](https://badge.fury.io/rb/translation)
7
+ [![Downloads](https://img.shields.io/gem/dt/translation.svg)](https://rubygems.org/gems/translation)
6
8
 
7
- Add this gem to translate your application with [I18n (YAML)](#i18n-yaml) or
8
- [GetText](#gettext) syntaxes.
9
+ Add this gem to localize your Ruby on Rails application.
9
10
 
10
- Keep it synchronized with your translators on [Translation.io](https://translation.io).
11
+ Use the official Rails syntax (with [YAML](#i18n-yaml) files) or use the [GetText](#gettext) syntax.
11
12
 
12
- [![Image](https://translation.io/interface.png)](https://translation.io)
13
+ Write only the source text, and keep it synchronized with your translators on [Translation.io](https://translation.io).
14
+
15
+ <a href="https://translation.io">
16
+ <img width="720px" alt="Translation.io interface" src="https://translation.io/gifs/translation.gif">
17
+ </a>
18
+
19
+ [Technical Demo](https://translation.io/videos/rails.mp4) (2.5min)
13
20
 
14
21
  Need help? [contact@translation.io](mailto:contact@translation.io)
15
22
 
@@ -24,6 +31,13 @@ Table of contents
24
31
  * [Sync](#sync)
25
32
  * [Sync and Show Purgeable](#sync-and-show-purgeable)
26
33
  * [Sync and Purge](#sync-and-purge)
34
+ * [Manage Languages](#manage-languages)
35
+ * [Add or Remove Language](#add-or-remove-language)
36
+ * [Edit Language](#edit-language)
37
+ * [Custom Languages](#custom-languages)
38
+ * [Change the current locale](#change-the-current-locale)
39
+ * [Globally](#globally)
40
+ * [Locally](#locally)
27
41
  * [Advanced Configuration Options](#advanced-configuration-options)
28
42
  * [Disable GetText](#disable-gettext)
29
43
  * [Ignored YAML keys](#ignored-yaml-keys)
@@ -31,17 +45,18 @@ Table of contents
31
45
  * [Custom localization key prefixes](#custom-localization-key-prefixes)
32
46
  * [Paths where locales are stored (not recommended)](#paths-where-locales-are-stored-not-recommended)
33
47
  * [Pure Ruby (without Rails)](#pure-ruby-without-rails)
48
+ * [Testing](#testing)
49
+ * [Contributing](#contributing)
34
50
  * [List of clients for Translation.io](#list-of-clients-for-translationio)
35
51
  * [Ruby on Rails (Ruby)](#ruby-on-rails-ruby)
36
52
  * [Laravel (PHP)](#laravel-php)
37
53
  * [React and React-Intl (JavaScript)](#react-and-react-intl-javascript)
38
- * [Testing](#testing)
39
- * [Contributing](#contributing)
40
- * [Credits](#credits)
54
+ * [Others](#others)
55
+ * [License](#license)
41
56
 
42
57
  ## Translation syntaxes
43
58
 
44
- #### I18n (YAML)
59
+ ### I18n (YAML)
45
60
 
46
61
  The default [Rails Internationalization API](http://guides.rubyonrails.org/i18n.html).
47
62
 
@@ -71,10 +86,13 @@ en:
71
86
 
72
87
  You can keep your source YAML file automatically updated using [i18n-tasks](https://github.com/glebm/i18n-tasks).
73
88
 
74
- #### GetText
89
+ ### GetText
75
90
 
76
91
  This gem adds the GetText support to Rails. We [strongly suggest](https://translation.io/blog/gettext-is-better-than-rails-i18n)
77
- that you use GetText to translate your applications since it allows a simpler and more maintainable syntax.
92
+ that you use GetText to translate your application since it allows an easier and more complete syntax.
93
+
94
+ Also, you won't need to create and manage any YAML file since your code will be
95
+ automatically scanned for any string to translate.
78
96
 
79
97
  ```ruby
80
98
  # Regular
@@ -93,9 +111,6 @@ np_("context", "Singular text", "Plural text", number)
93
111
  _('%{city1} is bigger than %{city2}') % { city1: "NYC", city2: "BXL" }
94
112
  ```
95
113
 
96
- You don't need another file with source text or translations, everything will
97
- be synchronized from Translation.io, and stored on PO/MO files.
98
-
99
114
  More information about GetText syntax [here](https://github.com/ruby-gettext/gettext#usage).
100
115
 
101
116
  ## Installation
@@ -130,7 +145,7 @@ If you later need to add/remove target languages, please read our
130
145
 
131
146
  ## Usage
132
147
 
133
- #### Sync
148
+ ### Sync
134
149
 
135
150
  To send new translatable keys/strings and get new translations from Translation.io, simply run:
136
151
 
@@ -138,7 +153,7 @@ To send new translatable keys/strings and get new translations from Translation.
138
153
  $ bundle exec rake translation:sync
139
154
  ```
140
155
 
141
- #### Sync and Show Purgeable
156
+ ### Sync and Show Purgeable
142
157
 
143
158
  If you need to find out what are the unused keys/strings from Translation.io, using the current branch as reference:
144
159
 
@@ -148,7 +163,7 @@ $ bundle exec rake translation:sync_and_show_purgeable
148
163
 
149
164
  As the name says, this operation will also perform a sync at the same time.
150
165
 
151
- #### Sync and Purge
166
+ ### Sync and Purge
152
167
 
153
168
  If you need to remove unused keys/strings from Translation.io, using the current branch as reference:
154
169
 
@@ -160,13 +175,100 @@ As the name says, this operation will also perform a sync at the same time.
160
175
 
161
176
  Warning: all keys that are not present in the current branch will be **permanently deleted from Translation.io**.
162
177
 
178
+ ## Manage Languages
179
+
180
+ ### Add or Remove Language
181
+
182
+ You can add or remove a language by updating `config.target_locales = []` in your
183
+ `config/initializers/translation.rb` file, and executing `rake translation:sync`.
184
+
185
+ If you want to add a new language with existing translations (ex. if you already have
186
+ a translated YAML file in your project), you will need to create a new project on
187
+ Translation.io and run `rake translation:init` for them to appear.
188
+
189
+ ### Edit Language
190
+
191
+ To edit existing languages while keeping their translations (e.g. changing from `en` to `en-US`).
192
+
193
+ 1. Create a new project on Translation.io with the correct languages.
194
+ 2. Adapt `config/initializers/translation.rb` (new API key and languages)
195
+ 3. Adapt language names and root keys of the YAML files in your project (optional: adapt GetText directories and `.po` headers)
196
+ 4. Execute `rake translation:init` and check that everything went fine.
197
+ 5. Invite your collaborators in the new project.
198
+ 6. Remove the old project.
199
+
200
+ Since you created a new project, the translation history and tags will unfortunately be lost.
201
+
202
+ ### Custom Languages
203
+
204
+ You may want to add a custom language that is derived from an existing language.
205
+ It's useful if you want to change some translations for another instance of the
206
+ application or for a specific customer.
207
+
208
+ The structure of a custom language is : existing language code + "-" + custom text.
209
+
210
+ Examples: `en-microsoft` or `fr-BE-custom`.
211
+
212
+ Custom languages can be added like any other language and fallbacks work as expected.
213
+ It means that if the `en-microsoft.some_key` is missing, then it will fallback to
214
+ `en.some_key`. So you only need to translate keys that should be customized.
215
+
216
+ Note that fallback are chained, so `fr-be-custom` will fallback to `fr-be` that will
217
+ itself fallback to `fr`.
218
+
219
+ Using GetText syntax, it will only fallback to the source language. So either you
220
+ create a fallback mechanism by yourself or you avoid fallbacking
221
+ by translating everything in Translation.io for that custom language.
222
+
223
+ ## Change the current locale
224
+
225
+ ### Globally
226
+
227
+ The easiest way to change the current locale is with `set_locale`.
228
+
229
+ ```ruby
230
+ class ApplicationController < ActionController::Base
231
+ before_action :set_locale
232
+
233
+ [...]
234
+ end
235
+ ```
236
+
237
+ It will automatically set the locale extracted from the user's browser `HTTP_ACCEPT_LANGUAGE` value, and keep it in the session between requests.
238
+
239
+ Update the current locale by redirecting the user to https://yourdomain.com?locale=fr or even https://yourdomain.com/fr if you scoped your routes like this:
240
+
241
+ ```ruby
242
+ scope "/:locale", :constraints => { locale: /[a-z]{2}/ } do
243
+ resources :pages
244
+ end
245
+ ```
246
+
247
+ The `set_locale` code is [here](https://github.com/translation/rails/blob/master/lib/translation_io/controller.rb#L3), feel free to override it with your own locale management.
248
+
249
+ Don't forget to define your available locales with [I18n.available_locales](http://guides.rubyonrails.org/i18n.html#setup-the-rails-application-for-internationalization).
250
+
251
+ More examples here: https://translation.io/blog/set-current-locale-in-your-rails-app
252
+
253
+ ### Locally
254
+
255
+ This command will change the locale for both [I18n (YAML)](#i18n-yaml) and [GetText](#gettext):
256
+
257
+ ```ruby
258
+ I18n.locale = 'fr'
259
+ ```
260
+
261
+ You can call it several times in the same page if you want to switch between languages.
262
+
263
+ More examples here: https://translation.io/blog/rails-i18n-with-locale
264
+
163
265
  ## Advanced Configuration Options
164
266
 
165
267
  The `TranslationIO.configure` block in `config/initializers/translation.rb` can take several optional configuration options.
166
268
 
167
- Some options are described below but for an exhaustive list, please refer to [config.rb](https://github.com/aurels/translation-gem/blob/master/lib/translation_io/config.rb).
269
+ Some options are described below but for an exhaustive list, please refer to [config.rb](https://github.com/translation/rails/blob/master/lib/translation_io/config.rb).
168
270
 
169
- #### Disable GetText
271
+ ### Disable GetText
170
272
 
171
273
  Sometimes, you only want to use YAML and don't want to be bothered by GetText at all.
172
274
  For these cases, you just have to add `disable_gettext` in the config file.
@@ -181,7 +283,7 @@ TranslationIO.configure do |config|
181
283
  end
182
284
  ```
183
285
 
184
- #### Ignored YAML keys
286
+ ### Ignored YAML keys
185
287
 
186
288
  Sometimes you would like to ignore some YAML keys coming from gems or so.
187
289
  You can use the `ignored_key_prefixes` for that.
@@ -205,7 +307,7 @@ TranslationIO.configure do |config|
205
307
  end
206
308
  ```
207
309
 
208
- #### Source file formats (for GetText)
310
+ ### Source file formats (for GetText)
209
311
 
210
312
  If you are using GetText and you want to manage other file formats than:
211
313
 
@@ -225,7 +327,7 @@ TranslationIO.configure do |config|
225
327
  end
226
328
  ```
227
329
 
228
- #### Custom localization key prefixes
330
+ ### Custom localization key prefixes
229
331
 
230
332
  Rails YAML files contain not only translation strings but also localization values (integers, arrays, booleans)
231
333
  in the same place and that's bad. For example: date formats, number separators, default
@@ -251,7 +353,7 @@ TranslationIO.configure do |config|
251
353
  end
252
354
  ```
253
355
 
254
- #### Paths where locales are stored (not recommended)
356
+ ### Paths where locales are stored (not recommended)
255
357
 
256
358
  You can specify where your GetText and YAML files are on disk:
257
359
 
@@ -319,6 +421,18 @@ This gem was created specifically for Rails, but you can also use it in a pure R
319
421
 
320
422
  (Thanks [@kubaw](https://github.com/kubaw) for this snippet!)
321
423
 
424
+ ## Testing
425
+
426
+ To run the specs:
427
+
428
+ ```bash
429
+ $ bundle exec rspec
430
+ ```
431
+
432
+ ## Contributing
433
+
434
+ Please read the [CONTRIBUTING](CONTRIBUTING.md) file.
435
+
322
436
  ## List of clients for Translation.io
323
437
 
324
438
  These implementations were usually started by contributors for their own projects.
@@ -327,20 +441,16 @@ and some are not yet supported. However, they are quite well documented.
327
441
 
328
442
  Thanks a lot to these contributors for their hard work!
329
443
 
330
- If you want to create a new client for your favorite language or framework, feel
331
- free to reach us on [contact@translation.io](mailto:contact@translation.io) and
332
- we'll assist you with the workflow logic and send you API docs.
333
-
334
- #### Ruby on Rails (Ruby)
444
+ ### Ruby on Rails (Ruby)
335
445
 
336
446
  Officially Supported on [https://translation.io/rails](https://translation.io/rails)
337
447
 
338
- * GitHub: https://github.com/aurels/translation-gem
448
+ * GitHub: https://github.com/translation/rails
339
449
  * RubyGems: https://rubygems.org/gems/translation/
340
450
 
341
451
  Credits: [@aurels](https://github.com/aurels), [@michaelhoste](https://github.com/michaelhoste)
342
452
 
343
- #### Laravel (PHP)
453
+ ### Laravel (PHP)
344
454
 
345
455
  Officially Supported on [https://translation.io/laravel](https://translation.io/laravel)
346
456
 
@@ -349,26 +459,20 @@ Officially Supported on [https://translation.io/laravel](https://translation.io/
349
459
 
350
460
  Credits: [@armandsar](https://github.com/armandsar), [@michaelhoste](https://github.com/michaelhoste)
351
461
 
352
- #### React and React-Intl (JavaScript)
462
+ ### React and React-Intl (JavaScript)
353
463
 
354
464
  * GitHub: https://github.com/deecewan/translation-io
355
465
  * NPM: https://www.npmjs.com/package/translation-io
356
466
 
357
467
  Credits: [@deecewan](https://github.com/deecewan)
358
468
 
359
- ## Testing
469
+ ### Others
360
470
 
361
- To run the specs:
362
-
363
- ```bash
364
- $ bundle exec rspec
365
- ```
366
-
367
- ## Contributing
368
-
369
- Please read the [CONTRIBUTING](CONTRIBUTING.md) file.
471
+ If you want to create a new client for your favorite language or framework, feel
472
+ free to reach us on [contact@translation.io](mailto:contact@translation.io) and
473
+ we'll assist you with the workflow logic and send you API docs.
370
474
 
371
- ## Credits
475
+ ## License
372
476
 
373
477
  The [translation gem](https://rubygems.org/gems/translation) in released under MIT license by
374
478
  [Aurélien Malisart](http://aurelien.malisart.be) and [Michaël Hoste](https://80limit.com) (see [LICENSE](LICENSE) file).
@@ -77,7 +77,7 @@ module TranslationIO
77
77
  # You can edit and/or add new localization keys here, they won't be touched by Translation.io.
78
78
  #
79
79
  # If you want to add a new localization key prefix, use the option described here:
80
- # https://github.com/aurels/translation-gem#custom-localization-key-prefixes
80
+ # https://github.com/translation/rails#custom-localization-key-prefixes
81
81
  #
82
82
  EOS
83
83
  end
@@ -33,7 +33,7 @@ module TranslationIO
33
33
  key_string = '[' + key_string
34
34
  end
35
35
 
36
- while key_string != ''
36
+ while key_string != '' && !current_object.is_a?(String) && !current_object.nil?
37
37
  # Next is array
38
38
  if key_string[0] == '['
39
39
  array_pos = key_string.split(']', 2)[0]
@@ -54,7 +54,7 @@ module TranslationIO
54
54
  current_object[array_pos] = value if current_object.is_a?(Array)
55
55
  end
56
56
  # next is hash
57
- elsif key_string[0] != '[' && (key_string.include?('.') or key_string.include?('['))
57
+ elsif key_string[0] != '[' && (key_string.include?('.') || key_string.include?('['))
58
58
  splitted = key_string.split(/\.|\[/, 2)
59
59
  new_key = splitted[0]
60
60
  key_string = splitted[1]
@@ -86,7 +86,10 @@ module TranslationIO
86
86
  end
87
87
 
88
88
  def no_key?(array_or_hash, key)
89
- (array_or_hash.is_a?(Hash) && !array_or_hash.has_key?(key)) || !array_or_hash[key]
89
+ is_a_hash_without_key = array_or_hash.is_a?(Hash) && (!array_or_hash.has_key?(key) || array_or_hash[key] == nil)
90
+ is_an_array_without_key = array_or_hash.is_a?(Array) && array_or_hash[key] == nil
91
+
92
+ is_a_hash_without_key || is_an_array_without_key
90
93
  end
91
94
 
92
95
  def get_flat_hash_for_level(value, parent_key = nil)
metadata CHANGED
@@ -1,20 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translation
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.14'
4
+ version: '1.15'
5
5
  platform: ruby
6
6
  authors:
7
- - Aurelien Malisart
8
7
  - Michael Hoste
8
+ - Aurelien Malisart
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-03-23 00:00:00.000000000 Z
12
+ date: 2018-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gettext
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.2'
18
21
  - - ">="
19
22
  - !ruby/object:Gem::Version
20
23
  version: 3.2.5
@@ -22,6 +25,9 @@ dependencies:
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '3.2'
25
31
  - - ">="
26
32
  - !ruby/object:Gem::Version
27
33
  version: 3.2.5
@@ -29,72 +35,58 @@ dependencies:
29
35
  name: rake
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
- - - "~>"
38
+ - - ">="
33
39
  - !ruby/object:Gem::Version
34
- version: '10.3'
40
+ version: '0'
35
41
  type: :development
36
42
  prerelease: false
37
43
  version_requirements: !ruby/object:Gem::Requirement
38
44
  requirements:
39
- - - "~>"
45
+ - - ">="
40
46
  - !ruby/object:Gem::Version
41
- version: '10.3'
47
+ version: '0'
42
48
  - !ruby/object:Gem::Dependency
43
- name: rspec
49
+ name: simplecov
44
50
  requirement: !ruby/object:Gem::Requirement
45
51
  requirements:
46
52
  - - ">="
47
53
  - !ruby/object:Gem::Version
48
- version: 2.14.1
54
+ version: '0'
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
55
- version: 2.14.1
61
+ version: '0'
56
62
  - !ruby/object:Gem::Dependency
57
- name: rails
63
+ name: rspec
58
64
  requirement: !ruby/object:Gem::Requirement
59
65
  requirements:
60
66
  - - "~>"
61
67
  - !ruby/object:Gem::Version
62
- version: '4.1'
68
+ version: '2.14'
63
69
  type: :development
64
70
  prerelease: false
65
71
  version_requirements: !ruby/object:Gem::Requirement
66
72
  requirements:
67
73
  - - "~>"
68
74
  - !ruby/object:Gem::Version
69
- version: '4.1'
75
+ version: '2.14'
70
76
  - !ruby/object:Gem::Dependency
71
- name: simplecov
77
+ name: rails
72
78
  requirement: !ruby/object:Gem::Requirement
73
79
  requirements:
74
80
  - - ">="
75
81
  - !ruby/object:Gem::Version
76
- version: '0'
82
+ version: '4.1'
77
83
  type: :development
78
84
  prerelease: false
79
85
  version_requirements: !ruby/object:Gem::Requirement
80
86
  requirements:
81
87
  - - ">="
82
88
  - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: codeclimate-test-reporter
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: 1.0.0
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: 1.0.0
89
+ version: '4.1'
98
90
  description: Localize your app using either t(".keys") or _("source text") and type
99
91
  "rake translation:sync" to synchronize with your translators on Translation.io.
100
92
  email: contact@translation.io
@@ -130,7 +122,12 @@ files:
130
122
  homepage: https://translation.io
131
123
  licenses:
132
124
  - MIT
133
- metadata: {}
125
+ metadata:
126
+ bug_tracker_uri: https://github.com/translation/rails/issues
127
+ changelog_uri: https://github.com/translation/rails/blob/master/CHANGELOG.md
128
+ documentation_uri: https://translation.io/usage
129
+ homepage_uri: https://translation.io
130
+ source_code_uri: https://github.com/translation/rails
134
131
  post_install_message:
135
132
  rdoc_options: []
136
133
  require_paths:
@@ -147,8 +144,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
144
  version: '0'
148
145
  requirements: []
149
146
  rubyforge_project:
150
- rubygems_version: 2.4.5
147
+ rubygems_version: 2.5.1
151
148
  signing_key:
152
149
  specification_version: 4
153
- summary: Rails translation made _("simple") with YAML and GetText using Translation.io.
150
+ summary: Localize your app with YAML or GetText. Synchronize with your translators
151
+ on Translation.io.
154
152
  test_files: []
153
+ has_rdoc: false