diff options
author | Alex Zolotarev <alex@mapswithme.com> | 2013-09-23 13:31:15 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:02:12 +0300 |
commit | 367e1acf30441080e2316d2086941518851ad15d (patch) | |
tree | a9eb01be4f9a2ca02d05a1d8594692c46ee260db | |
parent | 1fdb2e8f525eed2b36f668e0e77d06b86495976a (diff) |
[tools] Updated Twine to 0.4.0
-rw-r--r-- | tools/twine/.gitignore | 2 | ||||
-rw-r--r-- | tools/twine/README.md | 17 | ||||
-rw-r--r-- | tools/twine/lib/twine/formatters/abstract.rb | 8 | ||||
-rw-r--r-- | tools/twine/lib/twine/formatters/gettext.rb | 36 | ||||
-rw-r--r-- | tools/twine/lib/twine/stringsfile.rb | 2 | ||||
-rw-r--r-- | tools/twine/lib/twine/version.rb | 2 | ||||
-rw-r--r-- | tools/twine/test/fixtures/en-2.po | 23 | ||||
-rw-r--r-- | tools/twine/test/fixtures/test-output-7.txt | 2 | ||||
-rw-r--r-- | tools/twine/test/fixtures/test-output-9.txt | 21 | ||||
-rw-r--r-- | tools/twine/test/twine_test.rb | 8 |
10 files changed, 102 insertions, 19 deletions
diff --git a/tools/twine/.gitignore b/tools/twine/.gitignore new file mode 100644 index 0000000000..7f27d7f1ea --- /dev/null +++ b/tools/twine/.gitignore @@ -0,0 +1,2 @@ +#Ruby gem +*.gem diff --git a/tools/twine/README.md b/tools/twine/README.md index 0c92049caf..9f307f0747 100644 --- a/tools/twine/README.md +++ b/tools/twine/README.md @@ -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 diff --git a/tools/twine/lib/twine/formatters/abstract.rb b/tools/twine/lib/twine/formatters/abstract.rb index 4dd8400dee..64dc36bcf0 100644 --- a/tools/twine/lib/twine/formatters/abstract.rb +++ b/tools/twine/lib/twine/formatters/abstract.rb @@ -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 diff --git a/tools/twine/lib/twine/formatters/gettext.rb b/tools/twine/lib/twine/formatters/gettext.rb index 8dab8db91e..10ba5e44bf 100644 --- a/tools/twine/lib/twine/formatters/gettext.rb +++ b/tools/twine/lib/twine/formatters/gettext.rb @@ -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 diff --git a/tools/twine/lib/twine/stringsfile.rb b/tools/twine/lib/twine/stringsfile.rb index 6be485c28e..9de932c228 100644 --- a/tools/twine/lib/twine/stringsfile.rb +++ b/tools/twine/lib/twine/stringsfile.rb @@ -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 diff --git a/tools/twine/lib/twine/version.rb b/tools/twine/lib/twine/version.rb index 30ccb50b15..ab2af43847 100644 --- a/tools/twine/lib/twine/version.rb +++ b/tools/twine/lib/twine/version.rb @@ -1,3 +1,3 @@ module Twine - VERSION = '0.3.2' + VERSION = '0.4.0' end diff --git a/tools/twine/test/fixtures/en-2.po b/tools/twine/test/fixtures/en-2.po new file mode 100644 index 0000000000..81ce2cef0d --- /dev/null +++ b/tools/twine/test/fixtures/en-2.po @@ -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" diff --git a/tools/twine/test/fixtures/test-output-7.txt b/tools/twine/test/fixtures/test-output-7.txt index 999be8be51..c2991bb599 100644 --- a/tools/twine/test/fixtures/test-output-7.txt +++ b/tools/twine/test/fixtures/test-output-7.txt @@ -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" diff --git a/tools/twine/test/fixtures/test-output-9.txt b/tools/twine/test/fixtures/test-output-9.txt new file mode 100644 index 0000000000..c351f434f9 --- /dev/null +++ b/tools/twine/test/fixtures/test-output-9.txt @@ -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 diff --git a/tools/twine/test/twine_test.rb b/tools/twine/test/twine_test.rb index 8dde933fde..8f61e51408 100644 --- a/tools/twine/test/twine_test.rb +++ b/tools/twine/test/twine_test.rb @@ -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 |