i18n_screwdriver 6.0 → 7.0

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: 3fb8ed962112d953a9faf5f4150d3f213710179d
4
- data.tar.gz: 6d3e1a2a3f0258d4a5c49796ab800c002fbf60a5
3
+ metadata.gz: 7797459c92084f08967a9f8a3f0cc77595ab3cd6
4
+ data.tar.gz: 468500d604d04697ae70dfe7bd7055b83f149a10
5
5
  SHA512:
6
- metadata.gz: 434aef9acfceefb716e73afe39ce90ab2e78c24a3a56c17ab6aa25756419eec475ef3117d8d9adddb280f405c20cb53daace89337c17312c84f2b8f88d4d05c4
7
- data.tar.gz: a417c66dc9ef6213436057c82fb7e639233c2cde4e9e6242e12446359916eac80fd3489ae5457f2cc0fb02bd0f246bdc023e8c61322154fd81c8e528dea864d1
6
+ metadata.gz: aea5b4f61054641698e466644cfb5d504e88929791c068528643c2b857b009bda12cd35ccddae164ab2bc377f23f4d2a9982ee45f5d3588d0ad06741fddfca78
7
+ data.tar.gz: 979fed750a96ab6dcbe408c8bc9346bc98d27ff4fcbbc8deeec6f1b28f1fd02108c8a3ced26ef6c85ba6246e1eea65e92b88ebce8526c72b13b945e96d3b2228
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_screwdriver (6.0)
4
+ i18n_screwdriver (7.0)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -30,6 +30,8 @@ Starting with version 6.0 you can also use symbols as keys
30
30
 
31
31
  _(:my_long_text)
32
32
 
33
+ Starting with version 7.0 we added namespaces. A translation in the form of _("User|Name") will use the full string as a key but only display the part after the pipe, so "Name". This is useful if you want to have text translated differently according to the context in some languages but have it the same in the source language. For example "User|Name" (in German "Benutzername") and "Account|Name" (in German "Accountname").
34
+
33
35
  Variable interpolation works as for normal strings
34
36
 
35
37
  _("Hello %{name}!") % {name: "Liah"}
@@ -3,7 +3,7 @@ module I18nScrewdriver
3
3
  attr_accessor :text, :options
4
4
 
5
5
  def self.new(text, options = {}, &block)
6
- translation = super(options[:raw] ? text : I18n.translate(I18nScrewdriver.for_key(text), options))
6
+ translation = super(options[:raw] ? text : I18nScrewdriver.translate(text, options))
7
7
  translation.text = text
8
8
  translation.options = options
9
9
 
@@ -1,3 +1,3 @@
1
1
  module I18nScrewdriver
2
- VERSION = "6.0"
2
+ VERSION = "7.0"
3
3
  end
@@ -8,7 +8,7 @@ module I18nScrewdriver
8
8
  File.join("config", "locales", "application.#{locale}.yml")
9
9
  end
10
10
 
11
- def self.for_key(string)
11
+ def self.generate_key(string)
12
12
  string = string.strip
13
13
  (string =~ /^:[a-z][a-z0-9_]*$/) ? string : Digest::MD5.hexdigest(string)
14
14
  end
@@ -90,8 +90,8 @@ module I18nScrewdriver
90
90
  texts.concat(grab_texts_to_be_translated(input))
91
91
  symbols.concat(grab_symbols_to_be_translated(input))
92
92
  end
93
- translations = Hash[texts.uniq.map{ |text| [for_key(text), text] }]
94
- translations.merge(Hash[symbols.uniq.map{ |symbol| [for_key(symbol), ""] }])
93
+ translations = Hash[texts.uniq.map{ |text| [generate_key(text), extract_text(text)] }]
94
+ translations.merge(Hash[symbols.uniq.map{ |symbol| [generate_key(symbol), ""] }])
95
95
  end
96
96
 
97
97
  def self.default_locale
@@ -129,4 +129,13 @@ module I18nScrewdriver
129
129
  hash.each{ |k, v| new_hash[k.to_s] = v.to_s }
130
130
  end
131
131
  end
132
+
133
+ def self.translate(string, options = {})
134
+ I18n.translate(generate_key(string), options)
135
+ end
136
+
137
+ def self.extract_text(string)
138
+ namespace, text = string.split("|", 2)
139
+ text ? text : namespace
140
+ end
132
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_screwdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: '6.0'
4
+ version: '7.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Miesel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-07 00:00:00.000000000 Z
12
+ date: 2014-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec