Skip to content

Commit

Permalink
Merge 90452c7 into 4660b17
Browse files Browse the repository at this point in the history
  • Loading branch information
powtac committed Dec 9, 2014
2 parents 4660b17 + 90452c7 commit cddce62
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
7 changes: 4 additions & 3 deletions lib/babelish/csv2base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def process_value(row_value, default_value)
return value.to_utf8
end

def get_row_format(row_key, row_value)
return "\"" + row_key + "\" = \"" + row_value + "\""
def get_row_format(row_key, row_value, indentation = 0)
return "\"#{row_key}\"" + " " * indentation + " = \"#{row_value}\""
end

# Convert csv file to multiple Localizable.strings files for each column
Expand Down Expand Up @@ -164,9 +164,10 @@ def write_content

def hash_to_output(content = {})
output = ''
indentation = content.map(&:first).max{|a, b| a.length <=> b.length}.length
if content && content.size > 0
content.each do |key, value|
output += get_row_format(key, value)
output += get_row_format(key, value, indentation - key.length)
end
end
return output
Expand Down
4 changes: 2 additions & 2 deletions lib/babelish/csv2php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def language_filepaths(language)
return filepath ? [filepath] : []
end

def get_row_format(row_key, row_value)
return "$" + @php_tag + "['#{row_key}'] = \"#{row_value}\";\n"
def get_row_format(row_key, row_value, indentation = 0)
return "$" + @php_tag + "['#{row_key}']" + " " * indentation + " = \"#{row_value}\";\n"
end

def extension
Expand Down
4 changes: 2 additions & 2 deletions lib/babelish/csv2strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def language_filepaths(language)
filepaths
end

def get_row_format(row_key, row_value)
return "\"#{row_key}\" = \"#{row_value}\";\n"
def get_row_format(row_key, row_value, indentation = 0)
return "\"#{row_key}\"" + " " * indentation + " = \"#{row_value}\";\n"
end

def extension
Expand Down
18 changes: 9 additions & 9 deletions test/babelish/test_csv2strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_converting_csv_to_dotstrings_one_output_option

def test_converting_csv_to_dotstrings_default_lang
expected_output = String.new(<<-EOS)
"GREETINGS" = "Buenos dias";
"GREETINGS" = "Buenos dias";
"ANOTHER_STRING" = "testEN";
EOS
csv_file = "test/data/test_data_multiple_langs.csv"
Expand All @@ -40,7 +40,7 @@ def test_converting_csv_to_dotstrings_default_lang

def test_converting_csv_to_dotstrings_with_no_default_lang_is_empty
expected_output = String.new(<<-EOS)
"GREETINGS" = "Buenos dias";
"GREETINGS" = "Buenos dias";
"ANOTHER_STRING" = "";
EOS
csv_file = "test/data/test_data_multiple_langs.csv"
Expand All @@ -56,7 +56,7 @@ def test_converting_csv_to_dotstrings_with_no_default_lang_is_empty

def test_converting_csv_to_dotstrings_default_lang_to_key
expected_output = String.new(<<-EOS)
"GREETINGS" = "Buenos dias";
"GREETINGS" = "Buenos dias";
"ANOTHER_STRING" = "ANOTHER_STRING";
EOS
csv_file = "test/data/test_data_multiple_langs.csv"
Expand All @@ -73,7 +73,7 @@ def test_converting_csv_to_dotstrings_default_lang_to_key

def test_converting_csv_to_dotstrings_keys
expected_output = String.new(<<-EOS)
"GREETINGS" = "Buenos dias";
"GREETINGS" = "Buenos dias";
"ANOTHER_STRING" = "ANOTHER_STRING";
EOS
csv_file = "test/data/test_data_multiple_langs.csv"
Expand All @@ -87,7 +87,7 @@ def test_converting_csv_to_dotstrings_keys

def test_converting_csv_to_dotstrings_with_percent
expected_output = String.new(<<-EOS)
"GREETINGS" = "hello_%@";
"GREETINGS" = "hello_%@";
"ANOTHER_STRING" = "hello";
EOS
csv_file = "test/data/test_data_with_percent.csv"
Expand All @@ -100,7 +100,7 @@ def test_converting_csv_to_dotstrings_with_percent

def test_converting_csv_to_dotstrings_with_spaces
expected_output = String.new(<<-EOS)
"GREETINGS " = "hello ";
"GREETINGS " = "hello ";
"ANOTHER_STRING" = " my other string with space at begin";
EOS
csv_file = "test/data/test_data_with_spaces.csv"
Expand All @@ -113,8 +113,8 @@ def test_converting_csv_to_dotstrings_with_spaces

def test_converting_csv_to_dotstrings_with_percent_space
expected_output = String.new(<<-EOS)
"GREETINGS" = "you have %d points";
"ANOTHER_STRING" = "this is a string with 10% of juice";
"GREETINGS" = "you have %d points";
"ANOTHER_STRING" = "this is a string with 10% of juice";
"ANOTHER_EXAMPLE" = "tu as fait 10% d'efforts";
EOS
csv_file = "test/data/test_data_with_percent_space.csv"
Expand All @@ -127,7 +127,7 @@ def test_converting_csv_to_dotstrings_with_percent_space

def test_converting_csv_to_dotstrings_with_stripping_option
expected_output = String.new(<<-EOS)
"GREETINGS" = "hello";
"GREETINGS" = "hello";
"ANOTHER_STRING" = "my other string with space at begin";
EOS
csv_file = "test/data/test_data_with_spaces.csv"
Expand Down

0 comments on commit cddce62

Please sign in to comment.