diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2013-03-19 21:07:16 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:51:49 +0300 |
commit | 02c50ea457c9c2684b074ee06076bb82f56cbbd6 (patch) | |
tree | 4a2ab76f212c1ac23347f692320c7c3010f8040c | |
parent | d5eff151f7e7209e4c83d5e51cd86a647c8e9df2 (diff) |
[tools][twine] Updated twine strings translation tool
-rw-r--r-- | tools/twine/README.md | 4 | ||||
-rw-r--r-- | tools/twine/lib/twine/cli.rb | 5 | ||||
-rw-r--r-- | tools/twine/lib/twine/formatters.rb | 4 | ||||
-rw-r--r-- | tools/twine/lib/twine/formatters/abstract.rb | 6 | ||||
-rw-r--r-- | tools/twine/lib/twine/formatters/android.rb | 5 | ||||
-rw-r--r-- | tools/twine/test/twine_test.rb | 26 |
6 files changed, 41 insertions, 9 deletions
diff --git a/tools/twine/README.md b/tools/twine/README.md index 036c1ddb80..0c92049caf 100644 --- a/tools/twine/README.md +++ b/tools/twine/README.md @@ -1,6 +1,6 @@ # Twine -Twine is a command line tool for managing your strings and their translations. These strings are all stored in a master text file and then Twine uses this file to import and export strings in a variety of file types, including iOS and Mac OS X `.strings` files, Android `.xml` files, and [jquery-localize][jquerylocalize] `.json` files. This allows individuals and companies to easily share strings across multiple projects, as well as export strings in any format the user wants. +Twine is a command line tool for managing your strings and their translations. These strings are all stored in a master text file and then Twine uses this file to import and export strings in a variety of file types, including iOS and Mac OS X `.strings` files, Android `.xml` files, gettext `.po` files, and [jquery-localize][jquerylocalize] `.json` files. This allows individuals and companies to easily share strings across multiple projects, as well as export strings in any format the user wants. ## Install @@ -74,6 +74,7 @@ Twine currently supports the following formats for outputting strings: * [iOS and OS X String Resources][applestrings] (format: apple) * [Android String Resources][androidstrings] (format: android) +* [Gettext PO Files][gettextpo] (format: gettext) * [jquery-localize Language Files][jquerylocalize] (format: jquery) If you would like to enable twine to create language files in another format, create an appropriate formatter in `lib/twine/formatters`. @@ -161,4 +162,5 @@ Now, whenever you build your application, Xcode will automatically invoke Twine [INI]: http://en.wikipedia.org/wiki/INI_file [applestrings]: http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html [androidstrings]: http://developer.android.com/guide/topics/resources/string-resource.html +[gettextpo]: http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/PO-Files.html [jquerylocalize]: https://github.com/coderifous/jquery-localize diff --git a/tools/twine/lib/twine/cli.rb b/tools/twine/lib/twine/cli.rb index d83b85da2b..d824359cdc 100644 --- a/tools/twine/lib/twine/cli.rb +++ b/tools/twine/lib/twine/cli.rb @@ -15,7 +15,7 @@ module Twine parser = OptionParser.new do |opts| opts.banner = 'Usage: twine COMMAND STRINGS_FILE [INPUT_OR_OUTPUT_PATH] [--lang LANG1,LANG2...] [--tags TAG1,TAG2,TAG3...] [--format FORMAT]' opts.separator '' - opts.separator 'The purpose of this script is to convert back and forth between multiple data formats, allowing us to treat our strings (and translations) as data stored in a text file. We can then use the data file to create drops for the localization team, consume similar drops returned by the localization team, generate reports on the strings, as well as create formatted string files to ship with your products. Twine currently supports iOS, OS X, Android, and jquery-localize string files.' + opts.separator 'The purpose of this script is to convert back and forth between multiple data formats, allowing us to treat our strings (and translations) as data stored in a text file. We can then use the data file to create drops for the localization team, consume similar drops returned by the localization team, generate reports on the strings, as well as create formatted string files to ship with your products. Twine currently supports iOS, OS X, Android, gettext, and jquery-localize string files.' opts.separator '' opts.separator 'Commands:' opts.separator '' @@ -64,6 +64,9 @@ module Twine opts.on('-o', '--output-file OUTPUT_FILE', 'Write the new strings database to this file instead of replacing the original file. This flag is only useful when running the consume-string-file or consume-loc-drop commands.') do |o| @options[:output_path] = o end + opts.on('-n', '--file-name FILE_NAME', 'When running the generate-all-string-files command, this flag may be used to overwrite the default file name of the format.') do |n| + @options[:file_name] = n + end opts.on('-d', '--developer-language LANG', 'When writing the strings data file, set the specified language as the "developer language". In practice, this just means that this language will appear first in the strings data file.') do |d| @options[:developer_language] = d end diff --git a/tools/twine/lib/twine/formatters.rb b/tools/twine/lib/twine/formatters.rb index c2358d7926..756df4e86d 100644 --- a/tools/twine/lib/twine/formatters.rb +++ b/tools/twine/lib/twine/formatters.rb @@ -1,10 +1,12 @@ require 'twine/formatters/abstract' require 'twine/formatters/android' require 'twine/formatters/apple' +require 'twine/formatters/flash' +require 'twine/formatters/gettext' require 'twine/formatters/jquery' module Twine module Formatters - FORMATTERS = [Formatters::Apple, Formatters::Android, Formatters::JQuery] + FORMATTERS = [Formatters::Apple, Formatters::Android, Formatters::Gettext, Formatters::JQuery, Formatters::Flash] end end diff --git a/tools/twine/lib/twine/formatters/abstract.rb b/tools/twine/lib/twine/formatters/abstract.rb index 0eb73e8bbc..4dd8400dee 100644 --- a/tools/twine/lib/twine/formatters/abstract.rb +++ b/tools/twine/lib/twine/formatters/abstract.rb @@ -57,6 +57,9 @@ module Twine # 1) use "s" instead of "@" for substituting strings str.gsub!(/%([0-9\$]*)@/, '%\1s') + # 1a) escape strings that begin with a lone "@" + str.sub!(/^@ /, '\\@ ') + # 2) if there is more than one substitution in a string, make sure they are numbered substituteCount = 0 startFound = false @@ -148,10 +151,11 @@ module Twine raise Twine::Error.new("Directory does not exist: #{path}") end + 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, default_file_name), lang) + write_file(File.join(path, item, file_name), lang) end end end diff --git a/tools/twine/lib/twine/formatters/android.rb b/tools/twine/lib/twine/formatters/android.rb index 68332707ee..4737350513 100644 --- a/tools/twine/lib/twine/formatters/android.rb +++ b/tools/twine/lib/twine/formatters/android.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require 'CGI' +require 'cgi' require 'rexml/document' module Twine @@ -74,9 +74,6 @@ module Twine else value = "" end - if @options[:tags] - set_tags_for_key(key, @options[:tags]) - end set_translation_for_key(key, lang, value) if comment and comment.length > 0 and !comment.start_with?("SECTION:") set_comment_for_key(key, comment) diff --git a/tools/twine/test/twine_test.rb b/tools/twine/test/twine_test.rb index 9c5ac3469d..8dde933fde 100644 --- a/tools/twine/test/twine_test.rb +++ b/tools/twine/test/twine_test.rb @@ -1,4 +1,4 @@ -require 'ERB' +require 'erb' require 'rubygems' require 'test/unit' require 'twine' @@ -36,6 +36,22 @@ class TwineTest < Test::Unit::TestCase end end + def test_generate_string_file_5 + Dir.mktmpdir do |dir| + output_path = File.join(dir, 'en.po') + Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} -t tag1)) + assert_equal(ERB.new(File.read('test/fixtures/test-output-7.txt')).result, File.read(output_path)) + end + end + + def test_generate_string_file_6 + Dir.mktmpdir do |dir| + output_path = File.join(dir, 'en.xml') + Twine::Runner.run(%W(generate-string-file test/fixtures/strings-3.txt #{output_path})) + assert_equal(ERB.new(File.read('test/fixtures/test-output-8.txt')).result, File.read(output_path)) + end + end + def test_consume_string_file_1 Dir.mktmpdir do |dir| output_path = File.join(dir, 'strings.txt') @@ -60,6 +76,14 @@ class TwineTest < Test::Unit::TestCase end end + def test_consume_string_file_4 + 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-1.po -o #{output_path} -l en -a)) + assert_equal(File.read('test/fixtures/test-output-4.txt'), File.read(output_path)) + end + end + def test_generate_report_1 Twine::Runner.run(%w(generate-report test/fixtures/strings-1.txt)) end |