Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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<!-- #{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
14 changes: 14 additions & 0 deletions test/babelish/test_csv2android.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ def test_converting_csv_to_dotstrings_one_output_option
# 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"},

Copy link
Copy Markdown
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.
Space inside { missing.
Space inside } missing.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

:default_lang => "English", :comments_column => 5)

Copy link
Copy Markdown
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.

converter.convert
assert File.exist?(french_file), "the ouptut file does not exist"
result = File.read(french_file)
assert_equal expected_output, result
system("rm -rf values-fr")
end
end
10 changes: 10 additions & 0 deletions test/data/test_data_fr_with_comments.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>