diff --git a/lib/babelish/csv2android.rb b/lib/babelish/csv2android.rb index 4ce6204..8452364 100644 --- a/lib/babelish/csv2android.rb +++ b/lib/babelish/csv2android.rb @@ -25,7 +25,8 @@ def process_value(row_value, default_value) end def get_row_format(row_key, row_value, comment = nil, indentation = 0) - "\t#{row_value}\n" + entry = comment.to_s.empty? ? "" : "\n\t\n" + entry + "\t#{row_value}\n" end def hash_to_output(content = {}) @@ -34,7 +35,8 @@ def hash_to_output(content = {}) output += "\n" output += "\n" content.each do |key, value| - output += get_row_format(key, value) + comment = @comments[key] + output += get_row_format(key, value, comment) end output += "\n" end diff --git a/test/babelish/test_csv2android.rb b/test/babelish/test_csv2android.rb index 7bd8ee4..5b30b6a 100644 --- a/test/babelish/test_csv2android.rb +++ b/test/babelish/test_csv2android.rb @@ -3,7 +3,7 @@ class TestCSV2Android < Test::Unit::TestCase def test_converting_csv_to_xml csv_file = "test/data/test_data.csv" - converter = Babelish::CSV2Android.new(csv_file, 'English' => "en") + converter = Babelish::CSV2Android.new(csv_file, "English" => "en") converter.convert assert File.exist?("values-en/strings.xml"), "the ouptut file does not exist" @@ -24,15 +24,36 @@ def test_converting_csv_with_special_chars def test_converting_csv_to_dotstrings_one_output_option csv_file = "test/data/test_data.csv" - single_file = 'myApp.xml' - converter = Babelish::CSV2Android.new(csv_file, - {'English' => "en"}, - :output_basename => 'myApp', - :ignore_lang_path => true) + single_file = "myApp.xml" + converter = Babelish::CSV2Android.new( + csv_file, + { "English" => "en" }, + :output_basename => "myApp", + :ignore_lang_path => true + ) converter.convert assert File.exist?(single_file), "the ouptut file does not exist" # clean up system("rm -rf ./" + single_file) end + + def test_converting_with_comments + csv_file = "test/data/test_data_with_comments.csv" + french_file = "values-fr/strings.xml" + expected_output = File.read("test/data/test_data_fr_with_comments.xml") + converter = Babelish::CSV2Android.new( + csv_file, + { "French" => "fr" }, + :default_lang => "English", + :comments_column => 5 + ) + converter.convert + assert File.exist?(french_file), "the ouptut file does not exist" + result = File.read(french_file) + assert_equal expected_output, result + + # clean up + system("rm -rf values-fr") + end end diff --git a/test/data/test_data_fr_with_comments.xml b/test/data/test_data_fr_with_comments.xml new file mode 100644 index 0000000..70119a6 --- /dev/null +++ b/test/data/test_data_fr_with_comments.xml @@ -0,0 +1,9 @@ + + + + + Salut + + + testEN +