forked from organicmaps/organicmaps
[tools] Updated Twine to 0.4.0
This commit is contained in:
parent
1fdb2e8f52
commit
367e1acf30
10 changed files with 102 additions and 19 deletions
2
tools/twine/.gitignore
vendored
Normal file
2
tools/twine/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
#Ruby gem
|
||||
*.gem
|
|
@ -157,6 +157,23 @@ It is easy to incorporate Twine right into your iOS and OS X app build processes
|
|||
|
||||
Now, whenever you build your application, Xcode will automatically invoke Twine to make sure that your `.strings` files are up-to-date.
|
||||
|
||||
## User Interface
|
||||
|
||||
* [Twine TextMate 2 Bundle](https://github.com/mobiata/twine.tmbundle) — This [TextMate 2](https://github.com/textmate/textmate) bundle will make it easier for you to work with Twine strings files. In particular, it lets you use code folding to easily collapse and expand both strings and sections.
|
||||
* [twine_ui](https://github.com/Daij-Djan/twine_ui) — A user interface for Twine written by [Dominik Pich](https://github.com/Daij-Djan/). Consider using this if you would prefer to use Twine without dropping to a command line.
|
||||
|
||||
## Contributors
|
||||
|
||||
Many thanks to all of the contributors to the Twine project, including:
|
||||
|
||||
* [Ishitoya Kentaro](https://github.com/kent013)
|
||||
* [Joseph Earl](https://github.com/JosephEarl)
|
||||
* [Kevin Everets](https://github.com/keverets)
|
||||
* [Kevin Wood](https://github.com/kwood)
|
||||
* [Mohammad Hejazi](https://github.com/MohammadHejazi)
|
||||
* [Robert Guo](http://www.robertguo.me/)
|
||||
|
||||
|
||||
[rubyzip]: http://rubygems.org/gems/rubyzip
|
||||
[git]: http://git-scm.org/
|
||||
[INI]: http://en.wikipedia.org/wiki/INI_file
|
||||
|
|
|
@ -153,9 +153,11 @@ module Twine
|
|||
|
||||
file_name = @options[:file_name] || default_file_name
|
||||
Dir.foreach(path) do |item|
|
||||
lang = determine_language_given_path(item)
|
||||
if lang
|
||||
write_file(File.join(path, item, file_name), lang)
|
||||
if File.directory?(item)
|
||||
lang = determine_language_given_path(item)
|
||||
if lang
|
||||
write_file(File.join(path, item, file_name), lang)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,25 +35,24 @@ module Twine
|
|||
value = nil
|
||||
comment = nil
|
||||
|
||||
for line in item.split(/\r?\n/)
|
||||
comment_match = comment_regex.match(line)
|
||||
if comment_match
|
||||
comment = comment_match[1]
|
||||
end
|
||||
key_match = key_regex.match(line)
|
||||
if key_match
|
||||
key = key_match[1].gsub('\\"', '"')
|
||||
end
|
||||
value_match = value_regex.match(line)
|
||||
if value_match
|
||||
value = value_match[1].gsub('\\"', '"')
|
||||
end
|
||||
comment_match = comment_regex.match(item)
|
||||
if comment_match
|
||||
comment = comment_match[1]
|
||||
end
|
||||
key_match = key_regex.match(item)
|
||||
if key_match
|
||||
key = key_match[1].gsub('\\"', '"')
|
||||
end
|
||||
value_match = value_regex.match(item)
|
||||
if value_match
|
||||
value = value_match[1].gsub(/"\n"/, '').gsub('\\"', '"')
|
||||
end
|
||||
if key and key.length > 0 and value and value.length > 0
|
||||
set_translation_for_key(key, lang, value)
|
||||
if comment and comment.length > 0
|
||||
if comment and comment.length > 0 and !comment.start_with?("SECTION:")
|
||||
set_comment_for_key(key, comment)
|
||||
end
|
||||
comment = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -68,6 +67,15 @@ module Twine
|
|||
printed_section = false
|
||||
section.rows.each do |row|
|
||||
if row.matches_tags?(@options[:tags], @options[:untagged])
|
||||
if !printed_section
|
||||
f.puts ''
|
||||
if section.name && section.name.length > 0
|
||||
section_name = section.name.gsub('--', '—')
|
||||
f.puts "# SECTION: #{section_name}"
|
||||
end
|
||||
printed_section = true
|
||||
end
|
||||
|
||||
basetrans = row.translated_string_for_lang(default_lang)
|
||||
|
||||
if basetrans
|
||||
|
|
|
@ -167,7 +167,7 @@ module Twine
|
|||
end
|
||||
@language_codes[1..-1].each do |lang|
|
||||
value = row.translations[lang]
|
||||
if value && value != row.translations[dev_lang]
|
||||
if value
|
||||
if value[0,1] == ' ' || value[-1,1] == ' ' || (value[0,1] == '`' && value[-1,1] == '`')
|
||||
value = '`' + value + '`'
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Twine
|
||||
VERSION = '0.3.2'
|
||||
VERSION = '0.4.0'
|
||||
end
|
||||
|
|
23
tools/twine/test/fixtures/en-2.po
vendored
Normal file
23
tools/twine/test/fixtures/en-2.po
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Language: en\n"
|
||||
"X-Generator: Twine\n"
|
||||
|
||||
msgctxt "key1"
|
||||
msgid "key1-english"
|
||||
msgstr "key1-english"
|
||||
|
||||
msgctxt "key3"
|
||||
msgid "key3-english"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "key4"
|
||||
msgid "key4"
|
||||
"multiline"
|
||||
msgstr "A multi"
|
||||
"line string\n"
|
||||
"can occur"
|
||||
|
||||
msgctxt "key5"
|
||||
msgid "A new string"
|
||||
msgstr "A new string"
|
2
tools/twine/test/fixtures/test-output-7.txt
vendored
2
tools/twine/test/fixtures/test-output-7.txt
vendored
|
@ -3,6 +3,8 @@ msgstr ""
|
|||
"Language: en\n"
|
||||
"X-Generator: Twine <%= Twine::VERSION %>\n"
|
||||
|
||||
|
||||
# SECTION: My Strings
|
||||
#. "This is a comment"
|
||||
msgctxt "key1"
|
||||
msgid "key1-english"
|
||||
|
|
21
tools/twine/test/fixtures/test-output-9.txt
vendored
Normal file
21
tools/twine/test/fixtures/test-output-9.txt
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
[[Uncategorized]]
|
||||
[key5]
|
||||
en = A new string
|
||||
|
||||
[[My Strings]]
|
||||
[key1]
|
||||
en = key1-english
|
||||
tags = tag1
|
||||
comment = This is a comment
|
||||
es = key1-spanish
|
||||
fr = key1-french
|
||||
[key2]
|
||||
en = key2-english
|
||||
tags = tag2
|
||||
fr = key2-french
|
||||
[key3]
|
||||
en = key3-english
|
||||
tags = tag1,tag2
|
||||
es = key3-spanish
|
||||
[key4]
|
||||
en = A multiline string\ncan occur
|
|
@ -84,6 +84,14 @@ class TwineTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_consume_string_file_5
|
||||
Dir.mktmpdir do |dir|
|
||||
output_path = File.join(dir, 'strings.txt')
|
||||
Twine::Runner.run(%W(consume-string-file test/fixtures/strings-1.txt test/fixtures/en-2.po -o #{output_path} -l en -a))
|
||||
assert_equal(File.read('test/fixtures/test-output-9.txt'), File.read(output_path))
|
||||
end
|
||||
end
|
||||
|
||||
def test_generate_report_1
|
||||
Twine::Runner.run(%w(generate-report test/fixtures/strings-1.txt))
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue