i18n_csv 0.1.2 → 0.1.3

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: 8130fdb7daca841d2d863e861a0811500fb43cf1
4
- data.tar.gz: 0026398ed693ae1ebac7ae36b7979c96ab6aca6b
3
+ metadata.gz: 9fd247b725ef51da78c7892151f975099bbdc215
4
+ data.tar.gz: b51a480ce2588979d7d4cf34c01d744c9184c5e3
5
5
  SHA512:
6
- metadata.gz: d85831f7f8f4253c2d6db208207fc058109d51d1a1ec226b8d7c9795c9ac1e3e0fa966a8f52cc03592e4b03f1e3778af57cf16bf9c408542cd92d2300276cf7f
7
- data.tar.gz: 27f35615069b065a95bc22f7c91aa68657e12fe775926af560f950784555bed98f5febf710899f963ce21f4f13130f968cc0506a38f83eeb802220a5361f5e60
6
+ metadata.gz: 48e07f947671fa68e79d1310d2a2a3412120d9de4c8f5ccd90a31a19cf5370d13c4514df23a4eff71ebd57635fd51bc4c68a7598704232604b253ec837171677
7
+ data.tar.gz: 065ca3572a915c126efe1ecd2e02b74800341d7159a9a4e621e0afc6b4e467e978be7fd0d43cc95c05e288638cfc486ec72e9329df5310c379c63025105c8d8a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # I18nCsv
2
2
 
3
- One extends standard I18n so that you could store your translations in a Comma-Separated Value files (*CSV*) in a **key-value** manner, where the **key** is a word or a phrase or even a poem if you wish. No limits here (except be aware to escape symbols so the CSV format is kept). And the **value** is the same text as the key but translated to a language, specified by a file name you are using. For example, you could write one line to a `sp.csv` file: `"hello!","hola!"` and use `t 'hello!'` with a *spanish locale* to get the `"hola!"` text.
3
+ One extends standard I18n so that you could store your translations in a Comma-Separated Value files ( _CSV_ ) in a **key-value** manner, where the **key** is a word or a phrase or even a poem if you wish. No limits here (except be aware to escape symbols so the CSV format is kept). And the **value** is the same text as the key but translated to a language, specified by a file name you are using. For example, you could write one line to a `sp.csv` file: `"hello!","hola!"` and use `t 'hello!'` with a *spanish locale* to get the `"hola!"` text.
4
4
 
5
5
  ## A brief of history
6
6
 
@@ -8,7 +8,7 @@ See, I used to be a Magento developer for some time. And I really liked their lo
8
8
 
9
9
  If Magento did not find the translated key' value - it just put the key itself. And if you try to keep all your keys in English, you did not face huge trouble when you did not set the translation for some text. But with the default Rails configuration, you get the HTML saying *I could not find the translation for moo.foo.bar string!*. And that's horrible, I think.
10
10
 
11
- So from my point of view, this approach (*CSV one*) is more flexible and user-friendly. So even customer could customize your locales.
11
+ So from my point of view, this approach ( _CSV one_ ) is more flexible and user-friendly. So even customer could customize your locales.
12
12
 
13
13
  ## Installation
14
14
 
@@ -2,42 +2,19 @@ require 'csv'
2
2
 
3
3
  module I18n
4
4
  module Backend
5
- module CSV18n
6
- def get_translations
7
- tmp_translations = translations()
8
-
9
- def yaml_to_key_string(hash, prefix = nil)
10
- prefix = prefix.to_s
11
-
12
- if hash.is_a? Hash then
13
- hash.collect do |k, v|
14
- k = k.to_s
15
-
16
- yaml_to_key_string(v, (prefix.blank? ? k : prefix + '.' + k)).flatten(1)
17
- end
18
- elsif hash.is_a? Array
19
- [ prefix, [ hash.reject { |e| e.blank? } ] ]
20
- else
21
- [ prefix, hash ]
22
- end
23
- end
24
-
25
- reload!
26
-
27
- tmp = tmp_translations.collect do |locale, values|
28
- [locale, Hash[*yaml_to_key_string(values).flatten(1)]]
29
- end
30
-
31
- Hash[[*tmp]]
32
- end
33
-
5
+ module Base
34
6
  protected
35
7
 
36
8
  def load_csv(filename)
37
9
  begin
38
10
  lines = CSV.read(filename)
39
11
  locale = ::File.basename(filename, '.csv').to_sym
40
- { locale => Hash[ lines.map { |l| l if l.size == 2 } ] }
12
+ values = Hash[ lines.map { |l| l if l.size == 2 } ]
13
+
14
+ @translations ||= {}
15
+ @translations[locale].merge! values
16
+
17
+ { locale => values }
41
18
  rescue Exception => e
42
19
  Rails.logger.error "I18n CSV error: #{e.message} :: #{e.backtrace}"
43
20
  nil
@@ -48,8 +25,12 @@ module I18n
48
25
 
49
26
  class MissingTranslation
50
27
  module Base
28
+ def message
29
+ keys.last.to_s
30
+ end
31
+
51
32
  def html_message
52
- key
33
+ keys.last.to_s
53
34
  end
54
35
  end
55
36
  end
@@ -3,7 +3,6 @@ require 'i18n_csv/i18n_csv'
3
3
  module I18n_CSV
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "i18n_csv.configure_rails_initialization" do
6
- I18n::Backend::Simple.include(I18n::Backend::CSV18n)
7
6
  I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.csv')]
8
7
  end
9
8
  end
@@ -1,3 +1,3 @@
1
1
  module I18nCsv
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Shoobovych
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-04 00:00:00.000000000 Z
11
+ date: 2013-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project: i18n_csv
99
- rubygems_version: 2.0.0
99
+ rubygems_version: 2.0.0.rc.2
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: Extends I18n to use Magento-style CSV translation storage.