lib/i18n_screwdriver.rb in i18n_screwdriver-8.1 vs lib/i18n_screwdriver.rb in i18n_screwdriver-9.0
- old
+ new
@@ -43,10 +43,17 @@
def self.grab_symbols_to_be_translated(string)
string.scan(/_\((:[a-z][a-z0-9_]*)\)/).flatten
end
+ def self.grab_js_texts_to_be_translated(string)
+ [].tap do |texts|
+ texts.concat(string.scan(/\bI18n\.screw\(?\s*(?<!\\)"(.*?)(?<!\\)"/).map{ |v| unescape_string(v[0]) })
+ texts.concat(string.scan(/\bI18n\.screw\(?\s*(?<!\\)'(.*?)(?<!\\)'/).map{ |v| unescape_string(v[0]) })
+ end
+ end
+
def self.in_utf8(hash)
{}.tap do |result|
hash.sort.each do |k, v|
result[k.encode('UTF-8')] = (v || "").encode('UTF-8')
end
@@ -85,14 +92,21 @@
end
def self.gather_translations
texts = []
symbols = []
+
Dir.glob("**/*.{haml,erb,slim,rb}").each do |file|
input = File.read(file)
texts.concat(grab_texts_to_be_translated(input))
symbols.concat(grab_symbols_to_be_translated(input))
end
+
+ Dir.glob("**/*.{js,coffee,hamlc,ejs,erb}").each do |file|
+ input = File.read(file)
+ texts.concat(grab_js_texts_to_be_translated(input))
+ end
+
translations = Hash[texts.uniq.map{ |text| [generate_key(text), extract_text(text)] }]
translations.merge(Hash[symbols.uniq.map{ |symbol| [generate_key(symbol), ""] }])
end
def self.default_locale