dry_i18n 1.0.0 → 1.0.1

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
  SHA1:
3
- metadata.gz: 263e01040f7128266abfcb48fcdd1de095e3b318
4
- data.tar.gz: 647d72d0ed3fb7537148bc66b742798678b8e3e4
3
+ metadata.gz: 90852497bd40badcdab82478e563cb84ccd3ea54
4
+ data.tar.gz: df1aecd0821dc3edfbfc21cf611809c5adebe9de
5
5
  SHA512:
6
- metadata.gz: cfcf5e5596169fd5a1a46875cf3a127478a6a5f814154fa1169a6531b881ae2f99d6ac91c046f0ab5d4c11d2cbee4b31fcb5bcc44040ee20499f37557b4a3b30
7
- data.tar.gz: 0ee980fab1d019731f5de4158674882d515ca17f9250fae83ff17517a864c52fb3f8943fb30133948ec6930f04e2041f349a22e095e045d221101e65bba3a8a2
6
+ metadata.gz: 984f5c7339a70553fb449d594635d4bc13a14fb298086fa762a31994d1e2a6ff0953fb033b37d7f10db17111325b80a7e694fc5fe2c6c287e3de4ccc88ac7e80
7
+ data.tar.gz: f3d9f483f9ee783505ef042d42ac8adf5c20a076a7592dcb1bfe6dc25d606b1db75c334d68328fdf08d06d850d948372e3b41af9bdefaf6c7b38e22976c52533
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+
3
+ ## [v1.0.1](https://github.com/stympy/dry_i18n/tree/v1.0.1) (30-4-2018)
4
+ [Full Changelog](https://github.com/stympy/dry_i18n/compare/v1.0.0...v1.0.1)
5
+
6
+ **Fixes**
7
+
8
+ - Error in 'scan' method when used gem Faker [\#3](https://github.com/NachoPal/dry_i18n/issues/3)
9
+ - Error when use I18n.transliterate [\#1](https://github.com/NachoPal/dry_i18n/issues/1)
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # DryI18n
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dry_i18n`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
@@ -24,38 +20,44 @@ Or install it yourself as:
24
20
 
25
21
  With this Gem you'll be able tu reuse i18n key translations, avoiding in this way to repeat yourself.
26
22
 
27
- ###Some examples of use:
23
+ Basically you just need to wrap the key you want to reuse with the markup **@[key]**
24
+
25
+ If the key you are reusing has interpolations, you just need to add a coma and pass a hash with the interpolation values **@[key,{foo: 'foo', bar: 'bar'}]**
26
+
27
+ You don't have to worry about the order you declare the keys on the yml files
28
+
29
+ ###Some examples of usage:
28
30
 
29
31
  1.- Basic reuse
30
32
  ```
31
33
  en:
32
34
  secondary_key: "secondary key"
33
- main_key: "I am a main key which reuse a @[secondary_hey]"
35
+ main_key: "I am a main key which reuse a @[secondary_key]"
34
36
  ```
35
37
  ```
36
- I18n.t("main_key") = "I am a main key which reuse a secondary_key"
38
+ I18n.t("main_key") = "I am a main key which reuse a secondary key"
37
39
  ```
38
40
 
39
41
  2.- Reusing with interpolation
40
42
  ```
41
43
  en:
42
44
  secondary_key: "secondary key with %{interpolation}"
43
- main_key: "I am a main key which reuse a @[secondary_hey,{interpolation: 'interpolation'}]"
45
+ main_key: "I am a main key which reuse a @[secondary_key,{interpolation: 'interpolation'}]"
44
46
  ```
45
47
  ```
46
- I18n.t("main_key") = "I am a main key which reuse a secondary_key with interpolation"
48
+ I18n.t("main_key") = "I am a main key which reuse a secondary key with interpolation"
47
49
  ```
48
50
 
49
51
  3.- Reusing with nested keys with or without interpolation
50
52
  ```
51
53
  en:
52
54
  nth_key: "nested key with %{interpolation}"
53
- secondary_key: "secondary key with %{interpolation} and a @[nth_key,{interpolation: 'interpolation']"
54
- main_key: "I am a main key which reuse a @[secondary_hey,{interpolation: 'interpolation'}], and it's own %{interpolation}"
55
+ secondary_key: "secondary key with %{interpolation} and a @[nth_key,{interpolation: 'interpolation'}]"
56
+ main_key: "I am a main key which reuse a @[secondary_key,{interpolation: 'interpolation'}], and it's own %{interpolation}"
55
57
  ```
56
58
  ```
57
59
  I18n.t("main_key",{interpolation: 'interpolation'}) =
58
- "I am a main key which reuse a secondary_key with interpolation and a nested key with interpolaton, and it's own interpolation"
60
+ "I am a main key which reuse a secondary key with interpolation and a nested key with interpolation, and its own interpolation"
59
61
  ```
60
62
 
61
63
  ## Contributing
@@ -7,21 +7,37 @@ module DryI18n
7
7
 
8
8
  def translate(locale, key, options = {})
9
9
  translation = original_translate(locale, key, options)
10
+
11
+ if translation.is_a? Array
12
+ translation.each_with_index do |translation_subpart, i|
13
+ translation[i] = replace_variable_in_translation(translation_subpart) if translation_subpart.is_a? String
14
+ end
15
+ elsif translation.is_a? String
16
+ translation = replace_variable_in_translation(translation)
17
+ end
18
+
19
+ translation
20
+ end
21
+
22
+ def replace_variable_in_translation(translation)
10
23
  variables = variables?(translation)
11
24
 
12
25
  if variables
13
26
  variables.each do |variable|
14
27
  key = variable[/@\[(.*?)\]/m, 1]
15
28
  options = key.scan(/\{.*?\}/)
29
+
16
30
  if options.any?
17
31
  options = eval(options.first)
18
32
  key = key.split(',').first
19
33
  else
20
34
  options = {}
21
35
  end
36
+
22
37
  translation = translation.sub(variable, I18n.translate(key, options))
23
38
  end
24
39
  end
40
+
25
41
  translation
26
42
  end
27
43
 
@@ -1,3 +1,3 @@
1
1
  module DryI18n
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry_i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nacho
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-12 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,6 +78,7 @@ files:
78
78
  - ".gitignore"
79
79
  - ".rspec"
80
80
  - ".travis.yml"
81
+ - CHANGELOG.md
81
82
  - Gemfile
82
83
  - LICENSE.txt
83
84
  - README.md
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  requirements: []
110
111
  rubyforge_project:
111
- rubygems_version: 2.5.1
112
+ rubygems_version: 2.6.12
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: Avoid repeating word translations for I18n ruby gem