air18n 0.4.7 → 0.4.8
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.
@@ -707,9 +707,16 @@ module Air18n
|
|
707
707
|
|
708
708
|
def self.detect_variables(search_in)
|
709
709
|
case search_in
|
710
|
-
when String
|
711
|
-
|
712
|
-
|
710
|
+
when String
|
711
|
+
search_in.scan(/\{\{(\w+)\}\}/).flatten +
|
712
|
+
search_in.scan(/\%\{(\w+)\}/).flatten +
|
713
|
+
search_in.scan(/\%(?:\d\$)?(?:[0\.]\d)?[dfsu@]/).flatten
|
714
|
+
|
715
|
+
when Array
|
716
|
+
search_in.inject(Set[]) { |carry, item| carry + detect_variables(item) }
|
717
|
+
|
718
|
+
when Hash
|
719
|
+
search_in.values.inject(Set[]) { |carry, item| carry + detect_variables(item) }
|
713
720
|
else []
|
714
721
|
end
|
715
722
|
end
|
data/lib/air18n/version.rb
CHANGED
@@ -69,6 +69,28 @@ describe Air18n::PhraseTranslation do
|
|
69
69
|
third_translation.previous_translation.value.should == "second translation"
|
70
70
|
end
|
71
71
|
|
72
|
+
context 'detect_variables' do
|
73
|
+
it 'should detect ruby variables' do
|
74
|
+
Air18n::PhraseTranslation.detect_variables('This is a %{variable} %{yo}.').
|
75
|
+
should == ['variable', 'yo']
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should detect Android variables' do
|
79
|
+
Air18n::PhraseTranslation.detect_variables('hi %s %1$s %2$s %3$d %4$02d there').
|
80
|
+
should == ['%s', '%1$s', '%2$s', '%3$d', '%4$02d']
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should detect iPhone variables' do
|
84
|
+
Air18n::PhraseTranslation.detect_variables('hi %@ %u %d %.2f %1$@ %2$u there').
|
85
|
+
should == ['%@', '%u', '%d', '%.2f', '%1$@', '%2$u']
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should not detect non-variables' do
|
89
|
+
Air18n::PhraseTranslation.detect_variables('I am 45% sorry .for that.').
|
90
|
+
should be_empty
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
72
94
|
context 'validations' do
|
73
95
|
it 'Should check maximum length' do
|
74
96
|
translation = FactoryGirl.create(:phrase_translation, :key => 'facebook description maxlength:10', :value => 'short')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: air18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-
|
16
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: i18n
|