stringex 1.5.1 → 2.0.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 +15 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +74 -0
- data/README.rdoc +22 -1
- data/Rakefile +46 -223
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/stringex.rb +11 -3
- data/lib/stringex/acts_as_url.rb +49 -97
- data/lib/stringex/acts_as_url/adapter.rb +26 -0
- data/lib/stringex/acts_as_url/adapter/active_record.rb +23 -0
- data/lib/stringex/acts_as_url/adapter/base.rb +188 -0
- data/lib/stringex/acts_as_url/adapter/data_mapper.rb +67 -0
- data/lib/stringex/acts_as_url/adapter/mongoid.rb +36 -0
- data/lib/stringex/configuration.rb +4 -0
- data/lib/stringex/configuration/acts_as_url.rb +44 -0
- data/lib/stringex/configuration/base.rb +58 -0
- data/lib/stringex/configuration/configurator.rb +25 -0
- data/lib/stringex/configuration/string_extensions.rb +19 -0
- data/lib/stringex/localization.rb +98 -0
- data/lib/stringex/localization/backend/i18n.rb +53 -0
- data/lib/stringex/localization/backend/internal.rb +51 -0
- data/lib/stringex/localization/conversion_expressions.rb +148 -0
- data/lib/stringex/localization/converter.rb +121 -0
- data/lib/stringex/localization/default_conversions.rb +88 -0
- data/lib/stringex/rails/railtie.rb +10 -0
- data/lib/stringex/string_extensions.rb +153 -208
- data/lib/stringex/unidecoder.rb +6 -101
- data/lib/stringex/unidecoder_data/x00.yml +1 -1
- data/lib/stringex/unidecoder_data/x02.yml +5 -5
- data/lib/stringex/unidecoder_data/x05.yml +1 -1
- data/lib/stringex/unidecoder_data/x06.yml +1 -1
- data/lib/stringex/unidecoder_data/x07.yml +3 -3
- data/lib/stringex/unidecoder_data/x09.yml +1 -1
- data/lib/stringex/unidecoder_data/x0e.yml +2 -2
- data/lib/stringex/unidecoder_data/x1f.yml +2 -2
- data/lib/stringex/unidecoder_data/x20.yml +1 -1
- data/lib/stringex/unidecoder_data/xfb.yml +1 -1
- data/lib/stringex/unidecoder_data/xff.yml +1 -1
- data/lib/stringex/version.rb +8 -0
- data/locales/da.yml +73 -0
- data/locales/en.yml +66 -0
- data/stringex.gemspec +77 -18
- data/test/acts_as_url/adapter/active_record.rb +72 -0
- data/test/acts_as_url/adapter/data_mapper.rb +82 -0
- data/test/acts_as_url/adapter/mongoid.rb +73 -0
- data/test/acts_as_url_configuration_test.rb +51 -0
- data/test/acts_as_url_integration_test.rb +271 -0
- data/test/localization/da_test.rb +117 -0
- data/test/localization/default_test.rb +113 -0
- data/test/localization/en_test.rb +117 -0
- data/test/localization_test.rb +123 -0
- data/test/redcloth_to_html_test.rb +37 -0
- data/test/string_extensions_test.rb +59 -91
- data/test/test_helper.rb +2 -0
- data/test/unicode_point_suite/basic_greek_test.rb +113 -0
- data/test/unicode_point_suite/basic_latin_test.rb +142 -0
- data/test/unicode_point_suite/codepoint_test_helper.rb +32 -0
- data/test/unidecoder/bad_localization.yml +1 -0
- data/test/unidecoder/localization.yml +4 -0
- data/test/unidecoder_test.rb +3 -5
- metadata +145 -37
- data/test/acts_as_url_test.rb +0 -272
@@ -0,0 +1,117 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'i18n'
|
5
|
+
require 'stringex'
|
6
|
+
|
7
|
+
class DanishYAMLLocalizationTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
Stringex::Localization.reset!
|
10
|
+
Stringex::Localization.backend = :i18n
|
11
|
+
Stringex::Localization.backend.load_translations :da
|
12
|
+
Stringex::Localization.locale = :da
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
"foo & bar" => "foo og bar",
|
17
|
+
"AT&T" => "AT og T",
|
18
|
+
"99° is normal" => "99 grader is normal",
|
19
|
+
"4 ÷ 2 is 2" => "4 divideret med 2 is 2",
|
20
|
+
"webcrawler.com" => "webcrawler punktum com",
|
21
|
+
"Well..." => "Well prik prik prik",
|
22
|
+
"x=1" => "x lig med 1",
|
23
|
+
"a #2 pencil" => "a nummer 2 pencil",
|
24
|
+
"100%" => "100 procent",
|
25
|
+
"cost+tax" => "cost plus tax",
|
26
|
+
"batman/robin fan fiction" => "batman skråstreg robin fan fiction",
|
27
|
+
"dial *69" => "dial stjerne 69",
|
28
|
+
# " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
29
|
+
}.each do |original, converted|
|
30
|
+
define_method "test_character_conversion: '#{original}'" do
|
31
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
{
|
36
|
+
"$100" => "100 dollars",
|
37
|
+
"$19.99" => "19 dollars 99 cents",
|
38
|
+
"£100" => "100 pund",
|
39
|
+
"£19.99" => "19 pund 99 pence",
|
40
|
+
"€100" => "100 euro",
|
41
|
+
"€19.99" => "19 euro 99 cent",
|
42
|
+
"¥1000" => "1000 yen"
|
43
|
+
}.each do |original, converted|
|
44
|
+
define_method "test_currency_conversion: '#{original}'" do
|
45
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
{
|
50
|
+
"Tea & Sympathy" => "Tea and Sympathy",
|
51
|
+
"10¢" => "10 cents",
|
52
|
+
"©2000" => "(c)2000",
|
53
|
+
"98° is fine" => "98 grader is fine",
|
54
|
+
"10÷5" => "10 divideret med 5",
|
55
|
+
""quoted"" => '"quoted"',
|
56
|
+
"to be continued…" => "to be continued...",
|
57
|
+
"2000–2004" => "2000-2004",
|
58
|
+
"I wish—oh, never mind" => "I wish--oh, never mind",
|
59
|
+
"½ ounce of gold" => "halv ounce of gold",
|
60
|
+
"1 and ¼ ounces of silver" => "1 and en fjerdedel ounces of silver",
|
61
|
+
"9 and ¾ ounces of platinum" => "9 and tre fjerdedele ounces of platinum",
|
62
|
+
"3>2" => "3>2",
|
63
|
+
"2<3" => "2<3",
|
64
|
+
"two words" => "two words",
|
65
|
+
"£100" => "pund 100",
|
66
|
+
"Walmart®" => "Walmart(r)",
|
67
|
+
"'single quoted'" => "'single quoted'",
|
68
|
+
"2×4" => "2x4",
|
69
|
+
"Programming™" => "Programming(tm)",
|
70
|
+
"¥20000" => "yen 20000",
|
71
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
72
|
+
}.each do |original, converted|
|
73
|
+
define_method "test_html_entity_conversion: '#{original}'" do
|
74
|
+
assert_equal converted, original.convert_miscellaneous_html_entities
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
{
|
79
|
+
"½" => "halv",
|
80
|
+
"½" => "halv",
|
81
|
+
"½" => "halv",
|
82
|
+
"⅓" => "en tredjedel",
|
83
|
+
"⅓" => "en tredjedel",
|
84
|
+
"⅔" => "to tredjedele",
|
85
|
+
"⅔" => "to tredjedele",
|
86
|
+
"¼" => "en fjerdedel",
|
87
|
+
"¼" => "en fjerdedel",
|
88
|
+
"¼" => "en fjerdedel",
|
89
|
+
"¾" => "tre fjerdedele",
|
90
|
+
"¾" => "tre fjerdedele",
|
91
|
+
"¾" => "tre fjerdedele",
|
92
|
+
"⅕" => "en femtedel",
|
93
|
+
"⅕" => "en femtedel",
|
94
|
+
"⅖" => "to femtedele",
|
95
|
+
"⅖" => "to femtedele",
|
96
|
+
"⅗" => "tre femtedele",
|
97
|
+
"⅗" => "tre femtedele",
|
98
|
+
"⅘" => "fire femtedele",
|
99
|
+
"⅘" => "fire femtedele",
|
100
|
+
"⅙" => "en sjettedel",
|
101
|
+
"⅙" => "en sjettedel",
|
102
|
+
"⅚" => "fem sjettedele",
|
103
|
+
"⅚" => "fem sjettedele",
|
104
|
+
"⅛" => "en ottendedel",
|
105
|
+
"⅛" => "en ottendedel",
|
106
|
+
"⅜" => "tre ottendedele",
|
107
|
+
"⅜" => "tre ottendedele",
|
108
|
+
"⅝" => "fem ottendedele",
|
109
|
+
"⅝" => "fem ottendedele",
|
110
|
+
"⅞" => "syv ottendedele",
|
111
|
+
"⅞" => "syv ottendedele"
|
112
|
+
}.each do |original, converted|
|
113
|
+
define_method "test_vulgar_fractions_conversion: #{original}" do
|
114
|
+
assert_equal converted, original.convert_vulgar_fractions
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'stringex'
|
5
|
+
|
6
|
+
class DefaultLocalizationTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
Stringex::Localization.reset!
|
9
|
+
Stringex::Localization.backend = :internal
|
10
|
+
end
|
11
|
+
{
|
12
|
+
"foo & bar" => "foo and bar",
|
13
|
+
"AT&T" => "AT and T",
|
14
|
+
"99° is normal" => "99 degrees is normal",
|
15
|
+
"4 ÷ 2 is 2" => "4 divided by 2 is 2",
|
16
|
+
"webcrawler.com" => "webcrawler dot com",
|
17
|
+
"Well..." => "Well dot dot dot",
|
18
|
+
"x=1" => "x equals 1",
|
19
|
+
"a #2 pencil" => "a number 2 pencil",
|
20
|
+
"100%" => "100 percent",
|
21
|
+
"cost+tax" => "cost plus tax",
|
22
|
+
"batman/robin fan fiction" => "batman slash robin fan fiction",
|
23
|
+
"dial *69" => "dial star 69",
|
24
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
25
|
+
}.each do |original, converted|
|
26
|
+
define_method "test_character_conversion: '#{original}'" do
|
27
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
{
|
32
|
+
"$100" => "100 dollars",
|
33
|
+
"$19.99" => "19 dollars 99 cents",
|
34
|
+
"£100" => "100 pounds",
|
35
|
+
"£19.99" => "19 pounds 99 pence",
|
36
|
+
"€100" => "100 euros",
|
37
|
+
"€19.99" => "19 euros 99 cents",
|
38
|
+
"¥1000" => "1000 yen"
|
39
|
+
}.each do |original, converted|
|
40
|
+
define_method "test_currency_conversion: '#{original}'" do
|
41
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
{
|
46
|
+
"Tea & Sympathy" => "Tea and Sympathy",
|
47
|
+
"10¢" => "10 cents",
|
48
|
+
"©2000" => "(c)2000",
|
49
|
+
"98° is fine" => "98 degrees is fine",
|
50
|
+
"10÷5" => "10 divided by 5",
|
51
|
+
""quoted"" => '"quoted"',
|
52
|
+
"to be continued…" => "to be continued...",
|
53
|
+
"2000–2004" => "2000-2004",
|
54
|
+
"I wish—oh, never mind" => "I wish--oh, never mind",
|
55
|
+
"½ ounce of gold" => "half ounce of gold",
|
56
|
+
"1 and ¼ ounces of silver" => "1 and one fourth ounces of silver",
|
57
|
+
"9 and ¾ ounces of platinum" => "9 and three fourths ounces of platinum",
|
58
|
+
"3>2" => "3>2",
|
59
|
+
"2<3" => "2<3",
|
60
|
+
"two words" => "two words",
|
61
|
+
"£100" => "pounds 100",
|
62
|
+
"Walmart®" => "Walmart(r)",
|
63
|
+
"'single quoted'" => "'single quoted'",
|
64
|
+
"2×4" => "2x4",
|
65
|
+
"Programming™" => "Programming(tm)",
|
66
|
+
"¥20000" => "yen 20000",
|
67
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
68
|
+
}.each do |original, converted|
|
69
|
+
define_method "test_html_entity_conversion: '#{original}'" do
|
70
|
+
assert_equal converted, original.convert_miscellaneous_html_entities
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
{
|
75
|
+
"½" => "half",
|
76
|
+
"½" => "half",
|
77
|
+
"½" => "half",
|
78
|
+
"⅓" => "one third",
|
79
|
+
"⅓" => "one third",
|
80
|
+
"⅔" => "two thirds",
|
81
|
+
"⅔" => "two thirds",
|
82
|
+
"¼" => "one fourth",
|
83
|
+
"¼" => "one fourth",
|
84
|
+
"¼" => "one fourth",
|
85
|
+
"¾" => "three fourths",
|
86
|
+
"¾" => "three fourths",
|
87
|
+
"¾" => "three fourths",
|
88
|
+
"⅕" => "one fifth",
|
89
|
+
"⅕" => "one fifth",
|
90
|
+
"⅖" => "two fifths",
|
91
|
+
"⅖" => "two fifths",
|
92
|
+
"⅗" => "three fifths",
|
93
|
+
"⅗" => "three fifths",
|
94
|
+
"⅘" => "four fifths",
|
95
|
+
"⅘" => "four fifths",
|
96
|
+
"⅙" => "one sixth",
|
97
|
+
"⅙" => "one sixth",
|
98
|
+
"⅚" => "five sixths",
|
99
|
+
"⅚" => "five sixths",
|
100
|
+
"⅛" => "one eighth",
|
101
|
+
"⅛" => "one eighth",
|
102
|
+
"⅜" => "three eighths",
|
103
|
+
"⅜" => "three eighths",
|
104
|
+
"⅝" => "five eighths",
|
105
|
+
"⅝" => "five eighths",
|
106
|
+
"⅞" => "seven eighths",
|
107
|
+
"⅞" => "seven eighths"
|
108
|
+
}.each do |original, converted|
|
109
|
+
define_method "test_vulgar_fractions_conversion: #{original}" do
|
110
|
+
assert_equal converted, original.convert_vulgar_fractions
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'i18n'
|
5
|
+
require 'stringex'
|
6
|
+
|
7
|
+
class EnglishYAMLLocalizationTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
Stringex::Localization.reset!
|
10
|
+
Stringex::Localization.backend = :i18n
|
11
|
+
Stringex::Localization.backend.load_translations :en
|
12
|
+
Stringex::Localization.locale = :en
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
"foo & bar" => "foo and bar",
|
17
|
+
"AT&T" => "AT and T",
|
18
|
+
"99° is normal" => "99 degrees is normal",
|
19
|
+
"4 ÷ 2 is 2" => "4 divided by 2 is 2",
|
20
|
+
"webcrawler.com" => "webcrawler dot com",
|
21
|
+
"Well..." => "Well dot dot dot",
|
22
|
+
"x=1" => "x equals 1",
|
23
|
+
"a #2 pencil" => "a number 2 pencil",
|
24
|
+
"100%" => "100 percent",
|
25
|
+
"cost+tax" => "cost plus tax",
|
26
|
+
"batman/robin fan fiction" => "batman slash robin fan fiction",
|
27
|
+
"dial *69" => "dial star 69",
|
28
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
29
|
+
}.each do |original, converted|
|
30
|
+
define_method "test_character_conversion: '#{original}'" do
|
31
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
{
|
36
|
+
"$100" => "100 dollars",
|
37
|
+
"$19.99" => "19 dollars 99 cents",
|
38
|
+
"£100" => "100 pounds",
|
39
|
+
"£19.99" => "19 pounds 99 pence",
|
40
|
+
"€100" => "100 euros",
|
41
|
+
"€19.99" => "19 euros 99 cents",
|
42
|
+
"¥1000" => "1000 yen"
|
43
|
+
}.each do |original, converted|
|
44
|
+
define_method "test_currency_conversion: '#{original}'" do
|
45
|
+
assert_equal converted, original.convert_miscellaneous_characters
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
{
|
50
|
+
"Tea & Sympathy" => "Tea and Sympathy",
|
51
|
+
"10¢" => "10 cents",
|
52
|
+
"©2000" => "(c)2000",
|
53
|
+
"98° is fine" => "98 degrees is fine",
|
54
|
+
"10÷5" => "10 divided by 5",
|
55
|
+
""quoted"" => '"quoted"',
|
56
|
+
"to be continued…" => "to be continued...",
|
57
|
+
"2000–2004" => "2000-2004",
|
58
|
+
"I wish—oh, never mind" => "I wish--oh, never mind",
|
59
|
+
"½ ounce of gold" => "half ounce of gold",
|
60
|
+
"1 and ¼ ounces of silver" => "1 and one fourth ounces of silver",
|
61
|
+
"9 and ¾ ounces of platinum" => "9 and three fourths ounces of platinum",
|
62
|
+
"3>2" => "3>2",
|
63
|
+
"2<3" => "2<3",
|
64
|
+
"two words" => "two words",
|
65
|
+
"£100" => "pounds 100",
|
66
|
+
"Walmart®" => "Walmart(r)",
|
67
|
+
"'single quoted'" => "'single quoted'",
|
68
|
+
"2×4" => "2x4",
|
69
|
+
"Programming™" => "Programming(tm)",
|
70
|
+
"¥20000" => "yen 20000",
|
71
|
+
" i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
72
|
+
}.each do |original, converted|
|
73
|
+
define_method "test_html_entity_conversion: '#{original}'" do
|
74
|
+
assert_equal converted, original.convert_miscellaneous_html_entities
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
{
|
79
|
+
"½" => "half",
|
80
|
+
"½" => "half",
|
81
|
+
"½" => "half",
|
82
|
+
"⅓" => "one third",
|
83
|
+
"⅓" => "one third",
|
84
|
+
"⅔" => "two thirds",
|
85
|
+
"⅔" => "two thirds",
|
86
|
+
"¼" => "one fourth",
|
87
|
+
"¼" => "one fourth",
|
88
|
+
"¼" => "one fourth",
|
89
|
+
"¾" => "three fourths",
|
90
|
+
"¾" => "three fourths",
|
91
|
+
"¾" => "three fourths",
|
92
|
+
"⅕" => "one fifth",
|
93
|
+
"⅕" => "one fifth",
|
94
|
+
"⅖" => "two fifths",
|
95
|
+
"⅖" => "two fifths",
|
96
|
+
"⅗" => "three fifths",
|
97
|
+
"⅗" => "three fifths",
|
98
|
+
"⅘" => "four fifths",
|
99
|
+
"⅘" => "four fifths",
|
100
|
+
"⅙" => "one sixth",
|
101
|
+
"⅙" => "one sixth",
|
102
|
+
"⅚" => "five sixths",
|
103
|
+
"⅚" => "five sixths",
|
104
|
+
"⅛" => "one eighth",
|
105
|
+
"⅛" => "one eighth",
|
106
|
+
"⅜" => "three eighths",
|
107
|
+
"⅜" => "three eighths",
|
108
|
+
"⅝" => "five eighths",
|
109
|
+
"⅝" => "five eighths",
|
110
|
+
"⅞" => "seven eighths",
|
111
|
+
"⅞" => "seven eighths"
|
112
|
+
}.each do |original, converted|
|
113
|
+
define_method "test_vulgar_fractions_conversion: #{original}" do
|
114
|
+
assert_equal converted, original.convert_vulgar_fractions
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require 'stringex'
|
3
|
+
require 'i18n'
|
4
|
+
|
5
|
+
class LocalizationTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Stringex::Localization.reset!
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_stores_translations
|
11
|
+
Stringex::Localization.backend = :internal
|
12
|
+
|
13
|
+
data = { :one => "number one", :two => "number two" }
|
14
|
+
Stringex::Localization.store_translations :en, :test_store, data
|
15
|
+
|
16
|
+
data.each do |key, value|
|
17
|
+
assert_equal value, Stringex::Localization.translate(:test_store, key)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_converts_translation_keys_to_symbols
|
22
|
+
Stringex::Localization.backend = :internal
|
23
|
+
|
24
|
+
data = { "one" => "number one", "two" => "number two" }
|
25
|
+
Stringex::Localization.store_translations :en, :test_convert, data
|
26
|
+
|
27
|
+
data.each do |key, value|
|
28
|
+
assert_equal value, Stringex::Localization.translate(:test_convert, key)
|
29
|
+
assert_equal value, Stringex::Localization.translate(:test_convert, key.to_sym)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_can_translate
|
34
|
+
Stringex::Localization.backend = :internal
|
35
|
+
|
36
|
+
data = { :one => "number one", :two => "number two" }
|
37
|
+
Stringex::Localization.store_translations :en, :test_translate, data
|
38
|
+
|
39
|
+
data.each do |key, value|
|
40
|
+
assert_equal value, Stringex::Localization.translate(:test_translate, key)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_can_translate_when_given_string_as_key
|
45
|
+
Stringex::Localization.backend = :internal
|
46
|
+
|
47
|
+
data = { :one => "number one", :two => "number two" }
|
48
|
+
Stringex::Localization.store_translations :en, :test_translate, data
|
49
|
+
|
50
|
+
data.each do |key, value|
|
51
|
+
assert_equal value, Stringex::Localization.translate(:test_translate, key.to_s)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_returns_default_if_none_found
|
56
|
+
Stringex::Localization.backend = :internal
|
57
|
+
assert_equal "my default", Stringex::Localization.translate(:test_default, :nonexistent, :default => "my default")
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_returns_nil_if_no_default
|
61
|
+
Stringex::Localization.backend = :internal
|
62
|
+
assert_nil Stringex::Localization.translate(:test_no_default, :nonexistent)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_falls_back_to_default_locale
|
66
|
+
Stringex::Localization.backend = :internal
|
67
|
+
Stringex::Localization.default_locale = :es
|
68
|
+
Stringex::Localization.locale = :da
|
69
|
+
|
70
|
+
data = { "one" => "number one", "two" => "number two" }
|
71
|
+
Stringex::Localization.store_translations :es, :test_default_locale, data
|
72
|
+
|
73
|
+
data.each do |key, value|
|
74
|
+
assert_equal value, Stringex::Localization.translate(:test_default_locale, key)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_with_locale
|
79
|
+
Stringex::Localization.backend = :internal
|
80
|
+
Stringex::Localization.locale = :fr
|
81
|
+
assert_equal :fr, Stringex::Localization.locale
|
82
|
+
locale_set_in_block = nil
|
83
|
+
Stringex::Localization.with_locale :da do
|
84
|
+
locale_set_in_block = Stringex::Localization.locale
|
85
|
+
end
|
86
|
+
assert_equal :da, locale_set_in_block
|
87
|
+
assert_equal :fr, Stringex::Localization.locale
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_stores_translations_in_i18n
|
91
|
+
Stringex::Localization.backend = :i18n
|
92
|
+
|
93
|
+
data = { :one => "number one", :two => "number two" }
|
94
|
+
Stringex::Localization.store_translations :en, :test_i18n_store, data
|
95
|
+
|
96
|
+
data.each do |key, value|
|
97
|
+
assert_equal value, I18n.translate("stringex.test_i18n_store.#{key}")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_can_translate_using_i18n
|
102
|
+
Stringex::Localization.backend = :i18n
|
103
|
+
|
104
|
+
data = { :one => "number one", :two => "number two" }
|
105
|
+
|
106
|
+
I18n.backend.store_translations :en, { :stringex => { :test_i18n_translation => data } }
|
107
|
+
|
108
|
+
data.each do |key, value|
|
109
|
+
assert_equal value, Stringex::Localization.translate(:test_i18n_translation, key)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_allows_blank_translations
|
114
|
+
[:internal, :i18n].each do |backend|
|
115
|
+
Stringex::Localization.backend = backend
|
116
|
+
|
117
|
+
assert_equal "Test blank", "Test blank".convert_miscellaneous_html_entities
|
118
|
+
|
119
|
+
Stringex::Localization.store_translations :en, :html_entities, { :nbsp => "" }
|
120
|
+
assert_equal "Testblank", "Test blank".convert_miscellaneous_html_entities
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|