i18n_screwdriver 6.0 → 7.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.rdoc +2 -0
- data/lib/i18n_screwdriver/translation.rb +1 -1
- data/lib/i18n_screwdriver/version.rb +1 -1
- data/lib/i18n_screwdriver.rb +12 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7797459c92084f08967a9f8a3f0cc77595ab3cd6
|
4
|
+
data.tar.gz: 468500d604d04697ae70dfe7bd7055b83f149a10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aea5b4f61054641698e466644cfb5d504e88929791c068528643c2b857b009bda12cd35ccddae164ab2bc377f23f4d2a9982ee45f5d3588d0ad06741fddfca78
|
7
|
+
data.tar.gz: 979fed750a96ab6dcbe408c8bc9346bc98d27ff4fcbbc8deeec6f1b28f1fd02108c8a3ced26ef6c85ba6246e1eea65e92b88ebce8526c72b13b945e96d3b2228
|
data/Gemfile.lock
CHANGED
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 :
|
6
|
+
translation = super(options[:raw] ? text : I18nScrewdriver.translate(text, options))
|
7
7
|
translation.text = text
|
8
8
|
translation.options = options
|
9
9
|
|
data/lib/i18n_screwdriver.rb
CHANGED
@@ -8,7 +8,7 @@ module I18nScrewdriver
|
|
8
8
|
File.join("config", "locales", "application.#{locale}.yml")
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
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| [
|
94
|
-
translations.merge(Hash[symbols.uniq.map{ |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: '
|
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-
|
12
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|