Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/babelish/csv2android.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<string name=\"#{row_key}\">#{row_value}</string>\n"
entry = comment.to_s.empty? ? "" : "\n\t<!-- #{comment} -->\n"
entry + "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
end

def hash_to_output(content = {})
Expand All @@ -34,7 +35,8 @@ def hash_to_output(content = {})
output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
output += "<resources>\n"
content.each do |key, value|
output += get_row_format(key, value)
comment = @comments[key]
output += get_row_format(key, value, comment)
end
output += "</resources>\n"
end
Expand Down
33 changes: 27 additions & 6 deletions test/babelish/test_csv2android.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the parameters of a method call if they span more than one line.

: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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the parameters of a method call if they span more than one line.

: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
9 changes: 9 additions & 0 deletions test/data/test_data_fr_with_comments.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- this is a greeting string -->
<string name="GREETINGS">Salut</string>

<!-- this is another example -->
<string name="ANOTHER_STRING">testEN</string>
</resources>