babelish 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +15 -0
  2. data/.babelish.sample +26 -0
  3. data/.gitignore +30 -0
  4. data/.hound.yml +4 -0
  5. data/.travis.yml +13 -0
  6. data/Gemfile +8 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +43 -0
  9. data/Rakefile +17 -0
  10. data/babelish.gemspec +41 -0
  11. data/bin/android2csv +13 -0
  12. data/bin/babelish +6 -0
  13. data/bin/csv2android +13 -0
  14. data/bin/csv2json +13 -0
  15. data/bin/csv2php +13 -0
  16. data/bin/csv2strings +14 -0
  17. data/bin/json2csv +13 -0
  18. data/bin/php2csv +13 -0
  19. data/bin/strings2csv +13 -0
  20. data/lib/babelish/android2csv.rb +25 -0
  21. data/lib/babelish/base2csv.rb +98 -0
  22. data/lib/babelish/commandline.rb +114 -0
  23. data/lib/babelish/csv2android.rb +36 -0
  24. data/lib/babelish/csv2base.rb +148 -0
  25. data/lib/babelish/csv2json.rb +22 -0
  26. data/lib/babelish/csv2php.rb +24 -0
  27. data/lib/babelish/csv2strings.rb +30 -0
  28. data/lib/babelish/google_doc.rb +36 -0
  29. data/lib/babelish/json2csv.rb +20 -0
  30. data/lib/babelish/language.rb +25 -0
  31. data/lib/babelish/php2csv.rb +30 -0
  32. data/lib/babelish/strings2csv.rb +47 -0
  33. data/lib/babelish/version.rb +3 -0
  34. data/lib/babelish.rb +27 -0
  35. data/test/babelish/commands/test_command_android2csv.rb +60 -0
  36. data/test/babelish/commands/test_command_csv2android.rb +35 -0
  37. data/test/babelish/commands/test_command_csv2strings.rb +60 -0
  38. data/test/babelish/commands/test_command_strings2csv.rb +95 -0
  39. data/test/babelish/test_android2csv.rb +35 -0
  40. data/test/babelish/test_base2csv.rb +43 -0
  41. data/test/babelish/test_bins.rb +24 -0
  42. data/test/babelish/test_csv2android.rb +26 -0
  43. data/test/babelish/test_csv2base.rb +40 -0
  44. data/test/babelish/test_csv2json.rb +26 -0
  45. data/test/babelish/test_csv2php.rb +26 -0
  46. data/test/babelish/test_csv2strings.rb +20 -0
  47. data/test/babelish/test_json2csv.rb +35 -0
  48. data/test/babelish/test_php2csv.rb +74 -0
  49. data/test/babelish/test_strings2csv.rb +114 -0
  50. data/test/data/android-en.xml +8 -0
  51. data/test/data/android-fr.xml +8 -0
  52. data/test/data/android.xml +8 -0
  53. data/test/data/genstrings.strings +0 -0
  54. data/test/data/json.json +6 -0
  55. data/test/data/php_lang.php +8 -0
  56. data/test/data/test_data.csv +3 -0
  57. data/test/data/test_data.strings +2 -0
  58. data/test/data/test_data_multiple_langs.csv +3 -0
  59. data/test/data/test_en.strings +2 -0
  60. data/test/data/test_fr.strings +2 -0
  61. data/test/data/test_utf16.strings +0 -0
  62. data/test/data/test_with_nil.csv +3 -0
  63. data/test/data/test_with_nil.strings +4 -0
  64. data/test/data/xcode_empty.strings +7 -0
  65. data/test/test_helper.rb +17 -0
  66. metadata +248 -0
@@ -0,0 +1,148 @@
1
+ module Babelish
2
+ class Csv2Base
3
+ attr_accessor :default_path, :output_file
4
+ attr_accessor :langs
5
+ attr_accessor :csv_filename
6
+ attr_accessor :default_lang
7
+ attr_accessor :excluded_states, :state_column, :keys_column
8
+ attr_accessor :languages
9
+
10
+ def initialize(filename, langs, args = {})
11
+ default_args = {
12
+ :excluded_states => [],
13
+ :state_column => nil,
14
+ :keys_column => 0
15
+ }
16
+
17
+ args = default_args.merge!(args)
18
+
19
+ @langs = langs
20
+ if !@langs.is_a?(Hash) || @langs.size == 0
21
+ raise "wrong format or/and langs parameter" + @langs.inspect
22
+ end
23
+
24
+ @output_file = args[:output_file]
25
+ @default_path = args[:default_path].to_s
26
+ @csv_filename = filename
27
+ @excluded_states = args[:excluded_states]
28
+ @state_column = args[:state_column]
29
+ @keys_column = args[:keys_column]
30
+ @default_lang = args[:default_lang]
31
+
32
+ @languages = []
33
+ end
34
+
35
+ def create_file_from_path(file_path)
36
+ path = File.dirname(file_path)
37
+ FileUtils.mkdir_p path
38
+ return File.new(file_path, "w")
39
+ end
40
+
41
+ def language_filepaths(language)
42
+ #implement in subclass
43
+ []
44
+ end
45
+
46
+ def process_value(row_value, default_value)
47
+ value = row_value.nil? ? default_value : row_value
48
+ value = "" if value.nil?
49
+ value.gsub!(/\\*\"/, "\\\"") #escape double quotes
50
+ value.gsub!(/\s*(\n|\\\s*n)\s*/, "\\n") #replace new lines with \n + strip
51
+ value.gsub!(/%\s+([a-zA-Z@])([^a-zA-Z@]|$)/, "%\\1\\2") #repair string formats ("% d points" etc)
52
+ value.gsub!(/([^0-9\s\(\{\[^])%/, "\\1 %")
53
+ value.strip!
54
+ return value.to_utf8
55
+ end
56
+
57
+ def get_row_format(row_key, row_value)
58
+ return "\"" + row_key + "\" = \"" + row_value + "\""
59
+ end
60
+
61
+ # Convert csv file to multiple Localizable.strings files for each column
62
+ def convert(name = @csv_filename)
63
+ rowIndex = 0
64
+ excludedCols = []
65
+ defaultCol = 0
66
+
67
+ CSV.foreach(name, :quote_char => '"', :col_sep => ',', :row_sep => :auto) do |row|
68
+
69
+ if rowIndex == 0
70
+ #check there's at least two columns
71
+ return unless row.count > 1
72
+ else
73
+ #skip empty lines (or sections)
74
+ next if row == nil or row[@keys_column].nil?
75
+ end
76
+
77
+ # go through columns
78
+ row.size.times do |i|
79
+ next if excludedCols.include? i
80
+
81
+ #header
82
+ if rowIndex == 0
83
+ # ignore all headers not listed in langs to create files
84
+ (excludedCols << i and next) unless @langs.has_key?(row[i])
85
+
86
+ defaultCol = i if self.default_lang == row[i]
87
+ language = Language.new(row[i])
88
+ if @langs[row[i]].is_a?(Array)
89
+ @langs[row[i]].each do |id|
90
+ language.add_language_id(id.to_s)
91
+ end
92
+ else
93
+ language.add_language_id(@langs[row[i]].to_s)
94
+ end
95
+ @languages[i] = language
96
+ elsif !@state_column || (row[@state_column].nil? || row[@state_column] == '' || !@excluded_states.include?(row[@state_column]))
97
+ # TODO: add option to strip the constant or referenced language
98
+ key = row[@keys_column].strip
99
+ value = self.process_value(row[i], row[defaultCol])
100
+
101
+ @languages[i].add_content_pair(key, value)
102
+ end
103
+ end
104
+
105
+ rowIndex += 1
106
+ end
107
+
108
+ write_content
109
+ end
110
+
111
+ def write_content
112
+ info = "List of created files:\n"
113
+ count = 0
114
+ @languages.each do |language|
115
+ next if language.nil?
116
+
117
+ files = []
118
+ if @output_file
119
+ files << create_file_from_path(@output_file)
120
+ else
121
+ language_filepaths(language).each do |filename|
122
+ files << create_file_from_path(filename)
123
+ end
124
+ end
125
+ files.each do |file|
126
+ file.write hash_to_output(language.content)
127
+ info += "#{file.path.to_s}\n"
128
+ count += 1
129
+
130
+ file.close
131
+ end
132
+ end
133
+
134
+ info = "Created #{count} files.\n" + info
135
+ return info
136
+ end
137
+
138
+ def hash_to_output(content = {})
139
+ output = ''
140
+ if content && content.size > 0
141
+ content.each do |key, value|
142
+ output += get_row_format(key, value)
143
+ end
144
+ end
145
+ return output
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,22 @@
1
+ module Babelish
2
+ require 'json'
3
+ class CSV2JSON < Csv2Base
4
+ attr_accessor :file_path
5
+
6
+ def initialize(filename, langs, args = {})
7
+ super(filename, langs, args)
8
+
9
+ @file_path = args[:default_path].to_s
10
+ end
11
+
12
+ def language_filepaths(language)
13
+ require 'pathname'
14
+ filepath = Pathname.new("#{@file_path}#{language.code}.js")
15
+ return filepath ? [filepath] : []
16
+ end
17
+
18
+ def hash_to_output(content = {})
19
+ return content.to_json
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module Babelish
2
+ class CSV2Php < Csv2Base
3
+ attr_accessor :php_tag
4
+ attr_accessor :file_path
5
+
6
+ def initialize(filename, langs, args = {})
7
+ super(filename, langs, args)
8
+
9
+ @php_tag = args[:php_tag].nil? ? 'lang' : args[:php_tag]
10
+ @file_path = args[:default_path].to_s
11
+ end
12
+
13
+ def language_filepaths(language)
14
+ require 'pathname'
15
+ filepath = Pathname.new(@file_path) + "#{language.code}" + "lang.php"
16
+ return filepath ? [filepath] : []
17
+ end
18
+
19
+ def get_row_format(row_key, row_value)
20
+ return "$" + @php_tag + "['#{row_key}'] = \"#{row_value}\";\n"
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ module Babelish
2
+ class CSV2Strings < Csv2Base
3
+ attr_accessor :file_path
4
+
5
+ def initialize(filename, langs, args = {})
6
+ super(filename, langs, args)
7
+
8
+ @file_path = args[:default_path].to_s
9
+ end
10
+
11
+ def language_filepaths(language)
12
+ require 'pathname'
13
+ filepaths = []
14
+
15
+ if language.regions.empty?
16
+ filepaths << Pathname.new(@file_path) + "#{language.code}.lproj/Localizable.strings"
17
+ else
18
+ language.regions.each do |region|
19
+ filepaths << Pathname.new(@file_path) + "#{language.code}-#{region}.lproj/Localizable.strings"
20
+ end
21
+ end
22
+ filepaths
23
+ end
24
+
25
+ def get_row_format(row_key, row_value)
26
+ return "\"#{row_key}\" = \"#{row_value}\";\n"
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ module Babelish
2
+ # Faraday is a dependency of google_drive, this silents the warning
3
+ # see https://github.com/CocoaPods/CocoaPods/commit/f33f967427b857bf73645fd4d3f19eb05e9be0e0
4
+ # This is to make sure Faraday doesn't warn the user about the `system_timer` gem missing.
5
+ old_warn, $-w = $-w, nil
6
+ begin
7
+ require "google_drive"
8
+ ensure
9
+ $-w = old_warn
10
+ end
11
+
12
+ class GoogleDoc
13
+ attr_accessor :session
14
+
15
+ def authenticate
16
+ # will try to get token from ~/.ruby_google_drive.token
17
+ @session = GoogleDrive.saved_session
18
+ end
19
+
20
+ def download(requested_filename, worksheet_index = nil, output_filename = "translations.csv")
21
+ unless @session
22
+ authenticate
23
+ end
24
+ result = @session.file_by_title(requested_filename)
25
+ if result.is_a? Array
26
+ file = result.first
27
+ else
28
+ file = result
29
+ end
30
+ return nil unless file
31
+ file.export_as_file(output_filename, "csv", worksheet_index)
32
+ return output_filename
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ module Babelish
2
+ require 'json'
3
+ class JSON2CSV < Base2Csv
4
+
5
+ def initialize(args = {:filenames => []})
6
+ super(args)
7
+ end
8
+
9
+ def load_strings(strings_filename)
10
+ strings = {}
11
+ raise Errno::ENOENT unless File.exist?(strings_filename)
12
+ json_file = File.open(strings_filename, 'r')
13
+ json_string = json_file.read
14
+ json_file.close
15
+ strings = JSON.parse(json_string).to_hash
16
+ return strings
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ module Babelish
2
+ class Language
3
+ attr_accessor :name, :content, :code, :regions
4
+
5
+ def initialize(name, content = {})
6
+ @name = name
7
+ @content = content
8
+ end
9
+
10
+ def add_content_pair(key, value)
11
+ @content[key] = value
12
+ end
13
+
14
+ def add_language_id(language_id)
15
+ code, region = language_id.split('-')
16
+ @code ||= code
17
+ @regions ||= []
18
+ @regions << region if region
19
+ end
20
+
21
+ def region
22
+ @regions.first
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ module Babelish
2
+ class Php2CSV < Base2Csv
3
+
4
+ def initialize(args = {:filenames => []})
5
+ super(args)
6
+ end
7
+
8
+ def load_strings(strings_filename)
9
+ strings = {}
10
+ File.open(strings_filename, 'r') do |strings_file|
11
+ strings_file.read.each_line do |line|
12
+ parsed_line = parse_dotstrings_line(line)
13
+ unless parsed_line.nil?
14
+ converted_line = parse_dotstrings_line(line)
15
+ strings.merge!(converted_line) unless converted_line.nil?
16
+ end
17
+ end
18
+ end
19
+ strings
20
+ end
21
+
22
+ def parse_dotstrings_line(line)
23
+ line.strip!
24
+ if line[0] != ?# && line[0] != ?=
25
+ m = line.match(/^[\$].*\[[\"\'](.*)[\"\']\]\s*=\s*[\"\'](.*)[\"\'];/)
26
+ return {m[1] => m[2]} unless m.nil?
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ module Babelish
2
+ class Strings2CSV < Base2Csv
3
+ # default_lang is the the column to refer to if a value is missing
4
+ # actually default_lang = default_filename
5
+ attr_accessor :csv_filename, :headers, :filenames, :default_lang
6
+
7
+ def initialize(args = {:filenames => []})
8
+ super(args)
9
+ end
10
+
11
+ def parse_dotstrings_line(line)
12
+ line.strip!
13
+ if line[0] != ?# && line[0] != ?=
14
+ m = line.match(/^[^\"]*\"(.+)\"[^=]+=[^\"]*\"(.*)\";/)
15
+ return {m[1] => m[2]} unless m.nil?
16
+ end
17
+ end
18
+
19
+ # Load all strings of a given file
20
+ def load_strings(strings_filename)
21
+ strings = {}
22
+
23
+ # genstrings uses utf16, so that's what we expect. utf8 should not be impact
24
+ file = File.open(strings_filename, "r:utf-16:utf-8")
25
+ begin
26
+ contents = file.read
27
+ if RUBY_VERSION == "1.9.2"
28
+ # fixes conversion, see http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
29
+ require 'iconv'
30
+ ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
31
+ contents = ic.iconv(contents + ' ')[0..-2]
32
+ end
33
+ rescue Encoding::InvalidByteSequenceError => e
34
+ # silent error
35
+ # faults back to utf8
36
+ contents = File.open(strings_filename, "r:utf-8")
37
+ end
38
+ contents.each_line do |line|
39
+ hash = self.parse_dotstrings_line(line)
40
+ strings.merge!(hash) if hash
41
+ end
42
+
43
+ strings
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Babelish
2
+ VERSION = '0.3.0'
3
+ end
data/lib/babelish.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'csv'
2
+
3
+ # Fixes UTF8 issues
4
+ # see http://stackoverflow.com/questions/4583924/string-force-encoding-in-ruby-1-8-7-or-rails-2-x
5
+ class String
6
+ def to_utf8
7
+ force_encoding("UTF-8")
8
+ end
9
+ end
10
+
11
+ # From CSV
12
+ require "babelish/csv2base"
13
+ require "babelish/csv2strings"
14
+ require "babelish/csv2android"
15
+ require "babelish/csv2php"
16
+ require "babelish/csv2json"
17
+
18
+ # To CSV
19
+ require "babelish/base2csv"
20
+ require "babelish/strings2csv"
21
+ require "babelish/android2csv"
22
+ require "babelish/php2csv"
23
+ require "babelish/json2csv"
24
+
25
+ # General
26
+ require "babelish/language"
27
+ require "babelish/google_doc"
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+ class TestAndroid2CSVCommand < Test::Unit::TestCase
3
+ def test_android2csv
4
+ options = {:filenames => ["test/data/android.xml"]}
5
+ Commandline.new([], options).android2csv
6
+
7
+ assert File.exist?("translations.csv")
8
+
9
+ #clean up
10
+ system("rm -f translations.csv")
11
+ end
12
+
13
+ def test_android2csv_with_dryrun_option
14
+ options = {:filenames => ["test/data/android.xml"], :dryrun => true}
15
+ Commandline.new([], options).android2csv
16
+
17
+ assert !File.exist?("translations.csv")
18
+
19
+ #clean up
20
+ system("rm -f translations.csv")
21
+ end
22
+
23
+ def test_android2csv_with_output_file
24
+ options = {:filenames => ["test/data/android.xml"], :csv_filename => "myfile.csv"}
25
+ # -i, -o
26
+ Commandline.new([], options).android2csv
27
+
28
+ assert File.exist?("myfile.csv")
29
+
30
+ #clean up
31
+ system("rm -f myfile.csv")
32
+ end
33
+
34
+ def test_android2csv_with_headers
35
+ options = {:filenames => ["test/data/android.xml"], :headers => ["constants", "english"]}
36
+ # -i, -h
37
+ Commandline.new([], options).android2csv
38
+
39
+ #TODO assertion or move test on at lib level
40
+
41
+ #clean up
42
+ system("rm -f translations.csv")
43
+ end
44
+
45
+ def test_android2csv_with_two_files
46
+ options = {
47
+ :filenames => ["test/data/android-en.xml", "test/data/android-fr.xml"],
48
+ :headers => %w{Constants English French},
49
+ :csv_filename => "enfr.csv"
50
+ }
51
+ # --filenames, --headers, -o
52
+ Commandline.new([], options).android2csv
53
+
54
+ #TODO assertion
55
+
56
+ #clean up
57
+ system("rm -f enfr.csv")
58
+ end
59
+
60
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+ class TestCSV2AndroidCommand < Test::Unit::TestCase
3
+
4
+ def test_csv2android_with_multiple_2_languages
5
+ options = {
6
+ :filename => "test/data/test_data_multiple_langs.csv",
7
+ :langs => {"English" => "en", "French" => "fr"}
8
+ }
9
+ Commandline.new([], options).csv2android
10
+
11
+ assert File.exist?("./values-en/strings.xml")
12
+ assert File.exist?("./values-fr/strings.xml")
13
+
14
+ #clean up
15
+ system("rm -rf ./values-en/")
16
+ system("rm -rf ./values-fr/")
17
+ end
18
+
19
+ def test_csv2android_with_default_path
20
+ options = {
21
+ :filename => "test/data/test_data_multiple_langs.csv",
22
+ :langs => {"English" => "en", "French" => "fr"},
23
+ :default_path => "mynewlocation"
24
+ }
25
+
26
+ Commandline.new([], options).csv2android
27
+ # testing
28
+ assert File.exist?("./mynewlocation/values-en/strings.xml"), "can't find output file for English"
29
+ assert File.exist?("./mynewlocation/values-fr/strings.xml"), "can't find output file for French"
30
+
31
+ #clean up
32
+ system("rm -rf ./mynewlocation")
33
+ end
34
+
35
+ end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+ class TestCSV2StringsCommand < Test::Unit::TestCase
3
+
4
+ def test_csv2strings_with_multiple_2_languages
5
+ options = {
6
+ :filename => "test/data/test_data_multiple_langs.csv",
7
+ :langs => {"English" => "en", "French" => "fr"}
8
+ }
9
+ Commandline.new([], options).csv2strings
10
+
11
+ assert File.exist?("./en.lproj/Localizable.strings")
12
+ assert File.exist?("./fr.lproj/Localizable.strings")
13
+
14
+ #clean up
15
+ system("rm -rf ./en.lproj/")
16
+ system("rm -rf ./fr.lproj/")
17
+ end
18
+
19
+ def test_csv2strings_with_default_path
20
+ options = {
21
+ :filename => "test/data/test_data_multiple_langs.csv",
22
+ :langs => {"English" => "en", "French" => "fr"},
23
+ :default_path => "mynewlocation"
24
+ }
25
+ Commandline.new([], options).csv2strings
26
+
27
+ # testing
28
+ assert File.exist?("./mynewlocation/en.lproj/Localizable.strings"), "can't find output file for English"
29
+ assert File.exist?("./mynewlocation/fr.lproj/Localizable.strings"), "can't find output file for French"
30
+
31
+ #clean up
32
+ system("rm -rf ./mynewlocation")
33
+ end
34
+
35
+ def test_csv2strings_with_fetch_google_doc
36
+ omit if ENV['TRAVIS']
37
+ options = {
38
+ :filename => "my_trads",
39
+ :langs => {"English" => "en", "French" => "fr"},
40
+ :fetch => true
41
+ }
42
+ assert_nothing_raised do
43
+ Commandline.new([], options).csv2strings
44
+ end
45
+ end
46
+
47
+ def test_csv2strings_with_config_file
48
+ system("cp .babelish.sample .babelish")
49
+
50
+ assert_nothing_raised do
51
+ Commandline.new.csv2strings
52
+ end
53
+
54
+ end
55
+
56
+ def teardown
57
+
58
+ system("rm -f .babelish")
59
+ end
60
+ end
@@ -0,0 +1,95 @@
1
+ require 'test_helper'
2
+ class TestStrings2CSVCommand < Test::Unit::TestCase
3
+
4
+ def test_strings2csv
5
+ options = {:filenames => ["test/data/test_data.strings"]}
6
+ Commandline.new([], options).strings2csv
7
+
8
+ assert File.exist?("translations.csv")
9
+
10
+ #clean up
11
+ system("rm -f translations.csv")
12
+ end
13
+
14
+ def test_strings2csv_with_dryrun_option
15
+ options = {:filenames => ["test/data/test_data.strings"], :dryrun => true}
16
+ Commandline.new([], options).strings2csv
17
+
18
+ assert !File.exist?("translations.csv")
19
+
20
+ #clean up
21
+ system("rm -f translations.csv")
22
+ end
23
+
24
+ def test_strings2csv_with_output_file
25
+ options = {:filenames => ["test/data/test_data.strings"], :csv_filename => "myfile.csv"}
26
+ # -i, -o
27
+ Commandline.new([], options).strings2csv
28
+
29
+ assert File.exist?("myfile.csv")
30
+
31
+ #clean up
32
+ system("rm -f myfile.csv")
33
+ end
34
+
35
+ def test_strings2csv_with_headers
36
+ options = {:filenames => ["test/data/test_data.strings"], :headers => ["constants", "english"]}
37
+ # -i, -h
38
+ Commandline.new([], options).strings2csv
39
+
40
+ #TODO assertion or move test on at lib level
41
+
42
+ #clean up
43
+ system("rm -f translations.csv")
44
+ end
45
+
46
+ def test_strings2csv_with_two_files
47
+ options = {
48
+ :filenames => ["test/data/test_en.strings", "test/data/test_fr.strings"],
49
+ :headers => %w{Constants English French},
50
+ :csv_filename => "enfr.csv"
51
+ }
52
+ # --filenames, --headers, -o
53
+ Commandline.new([], options).strings2csv
54
+
55
+ #TODO assertion
56
+
57
+ #clean up
58
+ system("rm -f enfr.csv")
59
+ end
60
+
61
+ def test_strings2csv_with_empty_lines
62
+ options = {
63
+ :filenames => ["test/data/test_with_nil.strings"],
64
+ :csv_filename => "test_with_nil.csv"
65
+ }
66
+ # -i, -o
67
+
68
+
69
+ assert_nothing_raised do
70
+ Commandline.new([], options).strings2csv
71
+ end
72
+ assert system("diff test_with_nil.csv test/data/test_with_nil.csv"), "no difference on output"
73
+
74
+ #clean up
75
+ system("rm -f test_with_nil.csv")
76
+ end
77
+
78
+ def test_strings2csv_utf16
79
+ options = {
80
+ :filenames => ["test/data/test_utf16.strings"],
81
+ :csv_filename => "test_utf16.csv"
82
+ }
83
+ # -i, -o
84
+
85
+
86
+ assert_nothing_raised do
87
+ Commandline.new([], options).strings2csv
88
+ end
89
+
90
+ #clean up
91
+ system("rm -f test_utf16.csv")
92
+
93
+ end
94
+
95
+ end