Merge pull request #109 from sebastianludwig/use_set_translation_in_formatters
Use set_translation in formatters
This commit is contained in:
commit
00000ba9c9
3 changed files with 22 additions and 11 deletions
|
@ -45,6 +45,15 @@ module Twine
|
|||
return
|
||||
end
|
||||
|
||||
def set_translation_for_key(key, lang, value)
|
||||
value = CGI.unescapeHTML(value)
|
||||
value.gsub!('\\\'', '\'')
|
||||
value.gsub!('\\"', '"')
|
||||
value = iosify_substitutions(value)
|
||||
value.gsub!(/(\\u0020)*|(\\u0020)*\z/) { |spaces| ' ' * (spaces.length / 6) }
|
||||
super(key, lang, value)
|
||||
end
|
||||
|
||||
def read_file(path, lang)
|
||||
resources_regex = /<resources(?:[^>]*)>(.*)<\/resources>/m
|
||||
key_regex = /<string name="(\w+)">/
|
||||
|
@ -62,16 +71,8 @@ module Twine
|
|||
if key_match
|
||||
key = key_match[1]
|
||||
value_match = value_regex.match(line)
|
||||
if value_match
|
||||
value = value_match[1]
|
||||
value = CGI.unescapeHTML(value)
|
||||
value.gsub!('\\\'', '\'')
|
||||
value.gsub!('\\"', '"')
|
||||
value = iosify_substitutions(value)
|
||||
value.gsub!(/(\\u0020)*|(\\u0020)*\z/) { |spaces| ' ' * (spaces.length / 6) }
|
||||
else
|
||||
value = ""
|
||||
end
|
||||
value = value_match ? value_match[1] : ""
|
||||
|
||||
set_translation_for_key(key, lang, value)
|
||||
if comment and comment.length > 0 and !comment.start_with?("SECTION:")
|
||||
set_comment_for_key(key, comment)
|
||||
|
|
|
@ -25,6 +25,11 @@ module Twine
|
|||
return
|
||||
end
|
||||
|
||||
def set_translation_for_key(key, lang, value)
|
||||
value = value.gsub("\n","\\n")
|
||||
super(key, lang, value)
|
||||
end
|
||||
|
||||
def read_file(path, lang)
|
||||
begin
|
||||
require "json"
|
||||
|
@ -35,7 +40,6 @@ module Twine
|
|||
open(path) do |io|
|
||||
json = JSON.load(io)
|
||||
json.each do |key, value|
|
||||
value = value.gsub("\n","\\n")
|
||||
set_translation_for_key(key, lang, value)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -132,6 +132,12 @@ class TestJQueryFormatter < FormatterTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_set_translation_escapes_newlines
|
||||
@formatter.set_translation_for_key 'key1', 'en', "new\nline"
|
||||
|
||||
assert_equal 'new\nline', @strings.strings_map['key1'].translations['en']
|
||||
end
|
||||
|
||||
def test_write_file_output_format
|
||||
formatter = Twine::Formatters::JQuery.new @twine_file, {}
|
||||
formatter.write_file @output_path, 'en'
|
||||
|
|
Reference in a new issue