Fixed #182: Renamed command generate-loc-drop to generate-localization-archive and consume-loc-drop to consume-localization-archive.

This commit is contained in:
Sebastian Ludwig 2017-01-16 23:32:02 +01:00
parent c473ff6b9e
commit 2f81399a7c
7 changed files with 69 additions and 39 deletions

View file

@ -131,18 +131,18 @@ This command reads in a folder containing many localization files. These files s
$ twine consume-all-localization-files twine.txt Resources/Locales --developer-language en --consume-all --consume-comments
#### `generate-loc-drop`
#### `generate-localization-archive`
This command is a convenient way to generate a zip file containing files created by the [`generate-localization-file`](#generate-localization-file) command. If a file would not contain any translated strings, it is skipped and a warning is logged to `stderr`. This command can be used to create a single zip containing a large number of translations in all languages which you can then hand off to your translation team.
$ twine generate-loc-drop /path/to/twine.txt LocDrop1.zip
$ twine generate-loc-drop /path/to/twine.txt LocDrop2.zip --lang en,fr,ja,ko --tags common,app1
$ twine generate-localization-archive /path/to/twine.txt LocDrop1.zip
$ twine generate-localization-archive /path/to/twine.txt LocDrop2.zip --lang en,fr,ja,ko --tags common,app1
#### `consume-loc-drop`
#### `consume-localization-archive`
This command is a convenient way of taking a zip file and executing the [`consume-localization-file`](#consume-localization-file) command on each file within the archive. It is most often used to incorporate all of the changes made by the translation team after they have completed work on a localization drop.
This command is a convenient way of taking a zip file and executing the [`consume-localization-file`](#consume-localization-file) command on each file within the archive. It is most often used to incorporate all of the changes made by the translation team after they have completed work on a localization archive.
$ twine consume-loc-drop /path/to/twine.txt LocDrop2.zip
$ twine consume-localization-archive /path/to/twine.txt LocDrop2.zip
#### `validate-twine-file`

View file

@ -137,8 +137,8 @@ module Twine
],
example: 'twine generate-all-localization-files twine.txt Resources/Locales/ --tags FT,FB'
},
'generate-loc-drop' => {
description: 'Generates a zip archive of localization files in a given format. The purpose of this command is to create a very simple archive that can be handed off to a translation team. The translation team can unzip the archive, translate all of the strings in the archived files, zip everything back up, and then hand that final archive back to be consumed by the consume-loc-drop command.',
'generate-localization-archive' => {
description: 'Generates a zip archive of localization files in a given format. The purpose of this command is to create a very simple archive that can be handed off to a translation team. The translation team can unzip the archive, translate all of the strings in the archived files, zip everything back up, and then hand that final archive back to be consumed by the consume-localization-archive command.',
arguments: [:twine_file, :output_path],
required_options: [
:format
@ -151,7 +151,7 @@ module Twine
:untagged,
:validate
],
example: 'twine generate-loc-drop twine.txt LocDrop5.zip --tags FT,FB --format android --lang de,en,en-GB,ja,ko'
example: 'twine generate-localization-archive twine.txt LocDrop5.zip --tags FT,FB --format android --lang de,en,en-GB,ja,ko'
},
'consume-localization-file' => {
description: 'Slurps all of the translations from a localization file into the specified TWINE_FILE. If you have some files returned to you by your translators you can use this command to incorporate all of their changes. This script will attempt to guess both the language and the format given the filename and extension. For example, "ja.strings" will assume that the file is a Japanese iOS strings file.',
@ -187,8 +187,8 @@ module Twine
],
example: 'twine consume-all-localization-files twine.txt Resources/Locales/ --developer-language en --tags DefaultTag1,DefaultTag2'
},
'consume-loc-drop' => {
description: 'Consumes an archive of translated files. This archive should be in the same format as the one created by the generate-loc-drop command.',
'consume-localization-archive' => {
description: 'Consumes an archive of translated files. This archive should be in the same format as the one created by the generate-localization-archive command.',
arguments: [:twine_file, :input_path],
optional_options: [
:consume_all,
@ -199,7 +199,7 @@ module Twine
:output_path,
:tags
],
example: 'twine consume-loc-drop twine.txt LocDrop5.zip'
example: 'twine consume-localization-archive twine.txt LocDrop5.zip'
},
'validate-twine-file' => {
description: 'Validates that the given Twine file is parseable, contains no duplicates, and that no key contains invalid characters. Exits with a non-zero exit code if those criteria are not met.',
@ -211,9 +211,20 @@ module Twine
example: 'twine validate-twine-file twine.txt'
}
}
DEPRECATED_COMMAND_MAPPINGS = {
'generate-loc-drop' => 'generate-localization-archive', # added on 17.01.2017 - version 0.10
'consume-loc-drop' => 'consume-localization-archive' # added on 17.01.2017 - version 0.10
}
def self.parse(args)
command = args.select { |a| a[0] != '-' }[0]
args = args.reject { |a| a == command }
mapped_command = DEPRECATED_COMMAND_MAPPINGS[command]
if mapped_command
Twine::stderr.puts "WARNING: Twine commands names have changed. `#{command}` is now `#{mapped_command}`. The old command is deprecated will soon stop working. For more information please check the documentation at https://github.com/mobiata/twine"
command = mapped_command
end
unless COMMANDS.keys.include? command
Twine::stderr.puts "Invalid command: #{command}" unless command.nil?
@ -311,7 +322,6 @@ module Twine
end
def self.parse_command_options(command_name, args)
args.delete(command_name)
command = COMMANDS[command_name]
result = {

View file

@ -21,10 +21,10 @@ module Twine
runner.consume_localization_file
when 'consume-all-localization-files'
runner.consume_all_localization_files
when 'generate-loc-drop'
runner.generate_loc_drop
when 'consume-loc-drop'
runner.consume_loc_drop
when 'generate-localization-archive'
runner.generate_localization_archive
when 'consume-localization-archive'
runner.consume_localization_archive
when 'validate-twine-file'
runner.validate_twine_file
end
@ -121,7 +121,7 @@ module Twine
end
def generate_loc_drop
def generate_localization_archive
validate_twine_file if @options[:validate]
require_rubyzip
@ -185,7 +185,7 @@ module Twine
write_twine_data(output_path)
end
def consume_loc_drop
def consume_localization_archive
require_rubyzip
if !File.file?(@options[:input_path])
@ -268,7 +268,7 @@ module Twine
begin
require 'zip'
rescue LoadError
raise Twine::Error.new "You must run 'gem install rubyzip' in order to create or consume localization drops."
raise Twine::Error.new "You must run 'gem install rubyzip' in order to create or consume localization archives."
end
end

View file

@ -192,22 +192,22 @@ class TestGenerateAllLocalizationFilesCLI < CLITest
end
end
class TestGenerateLocDropCLI < CLITest
class TestGenerateLocalizationArchiveCLI < CLITest
def parse_with(parameters)
parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple " + parameters
parse "generate-localization-archive #{@twine_file_path} #{@output_path} --format apple " + parameters
end
def test_command
parse_with ""
assert_equal 'generate-loc-drop', @options[:command]
assert_equal 'generate-localization-archive', @options[:command]
assert_equal @twine_file_path, @options[:twine_file]
assert_equal @output_path, @options[:output_path]
end
def test_missing_argument
assert_raises Twine::Error do
parse "generate-loc-drop twine_file --format apple"
parse "generate-localization-archive twine_file --format apple"
end
end
@ -228,9 +228,19 @@ class TestGenerateLocDropCLI < CLITest
def test_option_format_required
assert_raises Twine::Error do
parse "generate-loc-drop twine_file output"
parse "generate-localization-archive twine_file output"
end
end
def test_supports_deprecated_command
parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple"
assert_equal 'generate-localization-archive', @options[:command]
end
def test_deprecated_command_prints_warning
parse "generate-loc-drop #{@twine_file_path} #{@output_path} --format apple"
assert_match "WARNING: Twine commands names have changed.", Twine::stderr.string
end
end
class TestConsumeLocalizationFileCLI < CLITest
@ -307,22 +317,22 @@ class TestConsumeAllLocalizationFilesCLI < CLITest
end
end
class TestConsumeLocDropCLI < CLITest
class TestConsumeLocalizationArchiveCLI < CLITest
def parse_with(parameters)
parse "consume-loc-drop #{@twine_file_path} #{@input_path} " + parameters
parse "consume-localization-archive #{@twine_file_path} #{@input_path} " + parameters
end
def test_command
parse_with ""
assert_equal 'consume-loc-drop', @options[:command]
assert_equal 'consume-localization-archive', @options[:command]
assert_equal @twine_file_path, @options[:twine_file]
assert_equal @input_path, @options[:input_path]
end
def test_missing_argument
assert_raises Twine::Error do
parse "consume-loc-drop twine_file"
parse "consume-localization-archive twine_file"
end
end
@ -341,6 +351,16 @@ class TestConsumeLocDropCLI < CLITest
assert_option_output_path
assert_option_tags
end
def test_supports_deprecated_command
parse "consume-loc-drop #{@twine_file_path} #{@input_path}"
assert_equal 'consume-localization-archive', @options[:command]
end
def test_deprecated_command_prints_warning
parse "consume-loc-drop #{@twine_file_path} #{@input_path}"
assert_match "WARNING: Twine commands names have changed.", Twine::stderr.string
end
end
class TestValidateTwineFileCLI < CLITest

View file

@ -1,11 +1,11 @@
require 'command_test'
class TestConsumeLocDrop < CommandTest
class TestConsumeLocalizationArchive < CommandTest
def setup
super
options = {}
options[:input_path] = fixture_path 'consume_loc_drop.zip'
options[:input_path] = fixture_path 'consume_localization_archive.zip'
options[:output_path] = @output_path
options[:format] = 'apple'
@ -19,7 +19,7 @@ class TestConsumeLocDrop < CommandTest
end
def test_consumes_zip_file
@runner.consume_loc_drop
@runner.consume_localization_archive
assert @twine_file.definitions_by_key['key1'].translations['en'], 'value1-english'
assert @twine_file.definitions_by_key['key1'].translations['es'], 'value1-spanish'

View file

@ -1,6 +1,6 @@
require 'command_test'
class TestGenerateLocDrop < CommandTest
class TestGenerateLocalizationArchive < CommandTest
def new_runner(twine_file = nil)
options = {}
options[:output_path] = @output_path
@ -18,13 +18,13 @@ class TestGenerateLocDrop < CommandTest
end
def test_generates_zip_file
new_runner.generate_loc_drop
new_runner.generate_localization_archive
assert File.exists?(@output_path), "zip file should exist"
end
def test_zip_file_structure
new_runner.generate_loc_drop
new_runner.generate_localization_archive
names = []
Zip::File.open(@output_path) do |zipfile|
@ -39,12 +39,12 @@ class TestGenerateLocDrop < CommandTest
formatter = prepare_mock_formatter Twine::Formatters::Apple
formatter.expects(:format_file).twice
new_runner.generate_loc_drop
new_runner.generate_localization_archive
end
def test_prints_empty_file_warnings
empty_twine_file = build_twine_file('en') {}
new_runner(empty_twine_file).generate_loc_drop
new_runner(empty_twine_file).generate_localization_archive
assert_match "Skipping file", Twine::stderr.string
end
@ -68,12 +68,12 @@ class TestGenerateLocDrop < CommandTest
def test_does_not_validate_twine_file
prepare_mock_formatter Twine::Formatters::Android
new_runner(false).generate_loc_drop
new_runner(false).generate_localization_archive
end
def test_validates_twine_file_if_validate
assert_raises Twine::Error do
new_runner(true).generate_loc_drop
new_runner(true).generate_localization_archive
end
end
end