i18n-js 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/i18n-js.rb +2 -18
- data/lib/i18n-js/version.rb +1 -1
- data/test/i18n_js_test.rb +0 -12
- metadata +1 -1
data/lib/i18n-js.rb
CHANGED
@@ -48,7 +48,7 @@ module SimplesIdeias
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# Copy configuration and JavaScript library files to
|
51
|
-
# <tt>
|
51
|
+
# <tt>config/i18n-js.yml</tt> and <tt>public/javascripts/i18n.js</tt>.
|
52
52
|
def setup!
|
53
53
|
FileUtils.cp File.dirname(__FILE__) + "/../source/i18n.js", javascript_file
|
54
54
|
FileUtils.cp(File.dirname(__FILE__) + "/../source/i18n-js.yml", config_file) unless config?
|
@@ -69,7 +69,7 @@ module SimplesIdeias
|
|
69
69
|
File.open(file, "w+") do |f|
|
70
70
|
f << %(var I18n = I18n || {};\n)
|
71
71
|
f << %(I18n.translations = );
|
72
|
-
f <<
|
72
|
+
f << translations.to_json
|
73
73
|
f << %(;)
|
74
74
|
end
|
75
75
|
end
|
@@ -118,21 +118,5 @@ module SimplesIdeias
|
|
118
118
|
def deep_merge!(target, hash) # :nodoc:
|
119
119
|
target.merge!(hash, &MERGER)
|
120
120
|
end
|
121
|
-
|
122
|
-
# Taken from http://seb.box.re/2010/1/15/deep-hash-ordering-with-ruby-1-8/
|
123
|
-
def sorted_hash(object, deep = false) # :nodoc:
|
124
|
-
if object.is_a?(Hash)
|
125
|
-
res = ActiveSupport::OrderedHash.new.tap do |map|
|
126
|
-
object.each {|k, v| map[k] = deep ? sorted_hash(v, deep) : v }
|
127
|
-
end
|
128
|
-
return res.class[res.sort {|a, b| a[0].to_s <=> b[0].to_s } ]
|
129
|
-
elsif deep && object.is_a?(Array)
|
130
|
-
array = Array.new
|
131
|
-
object.each_with_index {|v, i| array[i] = sorted_hash(v, deep) }
|
132
|
-
return array
|
133
|
-
else
|
134
|
-
return object
|
135
|
-
end
|
136
|
-
end
|
137
121
|
end
|
138
122
|
end
|
data/lib/i18n-js/version.rb
CHANGED
data/test/i18n_js_test.rb
CHANGED
@@ -131,18 +131,6 @@ class I18nJSTest < ActiveSupport::TestCase
|
|
131
131
|
assert_equal target[:a], {:b => 1, :c => 2}
|
132
132
|
end
|
133
133
|
|
134
|
-
test "sorted hash" do
|
135
|
-
assert_equal [:a, :b, :c], SimplesIdeias::I18n.sorted_hash(:b => 1, :a => 2, :c => 3).keys
|
136
|
-
end
|
137
|
-
|
138
|
-
test "sorted multi-levels hash" do
|
139
|
-
hash = {
|
140
|
-
:foo => {:b => 1, :a => 2, :c => 3}
|
141
|
-
}
|
142
|
-
|
143
|
-
assert_equal [:a, :b, :c], SimplesIdeias::I18n.sorted_hash(hash[:foo]).keys
|
144
|
-
end
|
145
|
-
|
146
134
|
test "update javascript library" do
|
147
135
|
FakeWeb.register_uri(:get, "http://github.com/fnando/i18n-js/raw/master/lib/i18n.js", :body => "UPDATED")
|
148
136
|
|