twine 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,7 +29,7 @@ Each grouping section contains N string definitions. These string definitions st
29
29
 
30
30
  ### Tags
31
31
 
32
- Tags are used by Twine as a way to only work with a subset of your strings at any given point in time. Each string can be assigned zero or more tags which are separated by commas. When a string has no tags, that string will never be selected by Twine. You can get a list of all strings currently missing tags by executing the `generate-report` command.
32
+ Tags are used by Twine as a way to only work with a subset of your strings at any given point in time. Each string can be assigned zero or more tags which are separated by commas. Tags are optional, though highly recommended. You can get a list of all strings currently missing tags by executing the `generate-report` command.
33
33
 
34
34
  ### Whitespace
35
35
 
data/lib/twine/cli.rb CHANGED
@@ -25,7 +25,7 @@ module Twine
25
25
  opts.separator ''
26
26
  opts.separator 'consume-string-file -- Slurps all of the strings from a translated strings file into the specified STRINGS_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.'
27
27
  opts.separator ''
28
- opts.separator 'generate-loc-drop -- Generates a zip archive of strings files in any 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. This command assumes that --all has been specified on the command line.'
28
+ opts.separator 'generate-loc-drop -- Generates a zip archive of strings files in any 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. This command assumes that --include-untranslated has been specified on the command line.'
29
29
  opts.separator ''
30
30
  opts.separator 'consume-loc-drop -- Consumes an archive of translated files. This archive should be in the same format as the one created by the generate-loc-drop command.'
31
31
  opts.separator ''
@@ -36,25 +36,31 @@ module Twine
36
36
  opts.on('-l', '--lang LANGUAGES', Array, 'The language code(s) to use for the specified action.') do |langs|
37
37
  @options[:languages] = langs
38
38
  end
39
- opts.on('-t', '--tags TAGS', Array, 'The tag(s) to use for the specified action. Only strings with that tag will be processed.') do |tags|
39
+ opts.on('-t', '--tags TAGS', Array, 'The tag(s) to use for the specified action. Only strings with that tag will be processed. Do not specify any tags to match all strings in the strings data file.') do |tags|
40
40
  @options[:tags] = tags
41
41
  end
42
- opts.on('-f', '--format FORMAT', 'The file format to read or write (iOS, Android). Additional formatters can be placed in the formats/ directory.') do |format|
42
+ opts.on('-u', '--untagged', 'If you have specified tags using the --tags flag, then only those tags will be selected. If you also want to select all strings that are untagged, then you can specify this option to do so.') do |u|
43
+ @options[:untagged] = true
44
+ end
45
+ formats = []
46
+ Formatters::FORMATTERS.each do |formatter|
47
+ formats << formatter::FORMAT_NAME
48
+ end
49
+ opts.on('-f', '--format FORMAT', "The file format to read or write (#{formats.join(', ')}). Additional formatters can be placed in the formats/ directory.") do |format|
43
50
  lformat = format.downcase
44
- found_format = false
45
- Formatters::FORMATTERS.each do |formatter|
46
- if formatter::FORMAT_NAME == lformat
47
- found_format = true
48
- break
49
- end
50
- end
51
- if !found_format
51
+ if !formats.include?(lformat)
52
52
  STDERR.puts "Invalid format: #{format}"
53
53
  end
54
54
  @options[:format] = lformat
55
55
  end
56
- opts.on('-a', '--all', 'Normally, when consuming a string file, Twine will ignore any string keys that do not exist in your master file. This flag will also cause any Android string files that are generated to include strings that have not yet been translated for the current language.') do |a|
57
- @options[:consume_generate_all] = true
56
+ opts.on('-a', '--consume-all', 'Normally, when consuming a string file, Twine will ignore any string keys that do not exist in your master file.') do |a|
57
+ @options[:consume_all] = true
58
+ end
59
+ opts.on('-s', '--include-untranslated', 'This flag will cause any Android string files that are generated to include strings that have not yet been translated for the current language.') do |s|
60
+ @options[:include_untranslated] = true
61
+ end
62
+ 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|
63
+ @options[:output_path] = o
58
64
  end
59
65
  opts.on('-e', '--encoding ENCODING', 'Twine defaults to encoding all output files in UTF-8. This flag will tell Twine to use an alternate encoding for these files. For example, you could use this to write Apple .strings files in UTF-16. This flag currently only works with Apple .strings files and is currently only supported in Ruby 1.9.3 or greater.') do |e|
60
66
  if !"".respond_to?(:encode)
@@ -62,9 +68,6 @@ module Twine
62
68
  end
63
69
  @options[:output_encoding] = e
64
70
  end
65
- 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|
66
- @options[:output_path] = o
67
- end
68
71
  opts.on('-h', '--help', 'Show this message.') do |h|
69
72
  puts opts.help
70
73
  exit
@@ -134,7 +137,7 @@ module Twine
134
137
  raise Twine::Error.new 'Please only specify a single language for the consume-string-file command.'
135
138
  end
136
139
  when 'generate-loc-drop'
137
- @options[:consume_generate_all] = true
140
+ @options[:include_untranslated] = true
138
141
  if @args.length == 3
139
142
  @options[:output_path] = @args[2]
140
143
  elsif @args.length > 3
@@ -16,7 +16,7 @@ module Twine
16
16
  def set_translation_for_key(key, lang, value)
17
17
  if @strings.strings_map.include?(key)
18
18
  @strings.strings_map[key].translations[lang] = value
19
- elsif @options[:consume_generate_all]
19
+ elsif @options[:consume_all]
20
20
  STDERR.puts "Adding new string '#{key}' to strings data file."
21
21
  arr = @strings.sections.select { |s| s.name == 'Uncategorized' }
22
22
  current_section = arr ? arr[0] : nil
@@ -77,7 +77,7 @@ module Twine
77
77
  @strings.sections.each do |section|
78
78
  printed_section = false
79
79
  section.rows.each do |row|
80
- if row.matches_tags?(@options[:tags])
80
+ if row.matches_tags?(@options[:tags], @options[:untagged])
81
81
  if !printed_section
82
82
  f.puts ''
83
83
  if section.name && section.name.length > 0
@@ -90,7 +90,7 @@ module Twine
90
90
  key = row.key
91
91
 
92
92
  value = row.translated_string_for_lang(lang, default_lang)
93
- if !value && @options[:consume_generate_all]
93
+ if !value && @options[:include_untranslated]
94
94
  value = row.translated_string_for_lang(@strings.language_codes[0])
95
95
  end
96
96
 
@@ -75,7 +75,7 @@ module Twine
75
75
  @strings.sections.each do |section|
76
76
  printed_section = false
77
77
  section.rows.each do |row|
78
- if row.matches_tags?(@options[:tags])
78
+ if row.matches_tags?(@options[:tags], @options[:untagged])
79
79
  if !printed_section
80
80
  f.puts ''
81
81
  if section.name && section.name.length > 0
data/lib/twine/runner.rb CHANGED
@@ -216,7 +216,9 @@ module Twine
216
216
  end
217
217
  end
218
218
 
219
- if keys_without_tags.length > 0
219
+ if keys_without_tags.length == total_strings
220
+ puts "\nNone of your strings have tags."
221
+ elsif keys_without_tags.length > 0
220
222
  puts "\nStrings without tags:"
221
223
  keys_without_tags.each do |key|
222
224
  puts key
@@ -22,13 +22,13 @@ module Twine
22
22
  @translations = {}
23
23
  end
24
24
 
25
- def matches_tags?(tags)
26
- if @tags == nil || @tags.length == 0
27
- # This row has no tags. Never match
28
- return false
29
- elsif tags == nil || tags.length == 0
25
+ def matches_tags?(tags, include_untagged)
26
+ if tags == nil || tags.length == 0
30
27
  # The user did not specify any tags. Everything passes.
31
28
  return true
29
+ elsif @tags == nil || @tags.length == 0
30
+ # This row has no tags.
31
+ return (include_untagged) ? true : false
32
32
  else
33
33
  tags.each do |tag|
34
34
  if @tags.include? tag
data/lib/twine/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Twine
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -7,4 +7,5 @@
7
7
  <string name="key1">key1-french</string>
8
8
  <string name="key2">key2-french</string>
9
9
  <string name="key3">key3-english</string>
10
+ <string name="key4">key4-english</string>
10
11
  </resources>
data/test/twine_test.rb CHANGED
@@ -5,7 +5,7 @@ class TwineTest < Test::Unit::TestCase
5
5
  def test_generate_string_file_1
6
6
  Dir.mktmpdir do |dir|
7
7
  output_path = File.join(dir, 'fr.xml')
8
- Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} --all))
8
+ Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} --include-untranslated))
9
9
  assert_equal(File.read('test/fixtures/test-output-1.txt'), File.read(output_path))
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-27 00:00:00.000000000 Z
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip
16
- requirement: &70216088301260 !ruby/object:Gem::Requirement
16
+ requirement: &70104222129900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70216088301260
24
+ version_requirements: *70104222129900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70216088300680 !ruby/object:Gem::Requirement
27
+ requirement: &70104222128800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.9.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70216088300680
35
+ version_requirements: *70104222128800
36
36
  description: ! " Twine is a command line tool for managing your strings and their
37
37
  translations.\n \n It is geared toward Mac OS X, iOS, and Android developers.\n"
38
38
  email: twine@mobiata.com