babelish 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzU1ODMxMGY0MGFhMWQ3MzZlMjI0N2MwZDNjODlkMTlkYjJlOWQ3ZQ==
4
+ MmI5Mjk2MTU1YmY5NTMyY2Q1ZjAxNzQxMDQ3ZWEzZTVlNTcxZTliMw==
5
5
  data.tar.gz: !binary |-
6
- ZDY1Y2E1NjU2YjAzYjJlOTBjMmJmYjhmNWQ1ZmMwYjA3NmViZmY3Nw==
6
+ M2MyNjU2ZmIxYzNjZWI2OWJhOTAxNzhhNDczYmE5ZDJlZjA1YTE0Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWM2OWNiYmRjYjczZGY5MTUwN2Q0NGJjZDI1ZjdlMjc2M2MzZmU3ZjQ0MDgx
10
- ZmMzNzkwOGVlNzc3NzMyNzk5YmViOWQyZTUzOTgzNzUzYTAyOTEzYTAzNmNl
11
- NzNkZDhiNjU3OTkxNGU1NWQ2YWI1ZjY4NDRlNWRlZGY2N2Y5ZDY=
9
+ M2FiOTQ3MTZlZDYxNzkyNWViNGNkNGYyNDg3ZDZmZWQxOTJkYzliM2M5ZDA0
10
+ NTAxMThkZGZhM2U2MWY5OTJiNWIzYmI5Nzk1N2ZhMGQzOWZkYWM3Mjc2YzYy
11
+ ZjI1NjY2MjEzZGI5ZTg1N2ZhZjU2ODIyNjExMDU0ZDQ5Yjk0ZjE=
12
12
  data.tar.gz: !binary |-
13
- MWVlYWQ5NDljOTEyMTk5M2EwOTM0OWZlZjYwODJhNWMzYzllNjFkMDZmMThk
14
- OGQzYmIyNzBlOTJjOTYxNGU5YzIwOTJhMDQ2ZjM4MjNjMGEyNDZlODE1NjBh
15
- MjMyZDk0ZGEwMDNmZmMzNjA1MTc1OWQ4YTA1NTY0NTI5MzM5MTI=
13
+ MDJhMWQxY2Q2ZTA0MTVkZmJiYTVjMzUyNjBlNTVhNGViMTFiNTI5ZDE1Y2Vm
14
+ NTkyNGU5YTE5Mjk4NjI4M2I5ZjMzNTY4ZDNkM2E2NmU1YmQ5NWQxNGQ3OWFh
15
+ NzY2OGVkYjhhZjczOTUyYWY1ZTEwNTM2NmU0ZGY3NWM4MjY0Njc=
data/.travis.yml CHANGED
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0.0
5
6
  - 2.1.0
7
+ - 2.2
6
8
  deploy:
7
9
  provider: rubygems
8
10
  api_key:
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Code Climate](https://codeclimate.com/github/netbe/Babelish.png)](https://codeclimate.com/github/netbe/Babelish)[![Coverage Status](https://coveralls.io/repos/netbe/Babelish/badge.png)](https://coveralls.io/r/netbe/Babelish)
3
3
  [![Gem Version](https://badge.fury.io/rb/babelish.svg)](http://badge.fury.io/rb/babelish)
4
4
 
5
+
5
6
  **Babelish : Chaotically confused, like Babel**
6
7
 
7
8
  Originally created to deal with localizedStrings files (aka *CSV-to-iOS-Localizable.strings-converter*), this command tool now converts a csv file of translations into the below file formats and vice-versa:
@@ -18,6 +19,8 @@ It can also fetch the csv file from GoogleDrive.
18
19
 
19
20
  Requires Ruby 1.9.3 or above.
20
21
 
22
+ Or download [Latest Release](https://github.com/netbe/Babelish/releases/latest).
23
+
21
24
  # Usage
22
25
 
23
26
  ```
data/babelish.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'babelish/version'
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'babelish'
8
8
  s.version = Babelish::VERSION
9
- s.date = '2015-05-22'
9
+ s.date = '2015-11-09'
10
10
  s.summary = "CSV converter for localization files"
11
11
  s.description = "This set of commands converts a CSV file to the following formats:
12
12
  - .strings (iOS)
@@ -21,11 +21,10 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "thor"
22
22
 
23
23
  s.add_dependency "google_drive", "~> 1.0.1"
24
+ s.add_dependency "nokogiri"
24
25
  # google_drive dependency to ask for mail and password
25
26
  s.add_dependency "highline"
26
27
 
27
- # android support
28
- s.add_dependency "xml-simple"
29
28
  # json support
30
29
  s.add_dependency "json"
31
30
 
@@ -1,5 +1,5 @@
1
1
  module Babelish
2
- require 'xmlsimple'
2
+ require "nokogiri"
3
3
  class Android2CSV < Base2Csv
4
4
 
5
5
  def initialize(args = {:filenames => []})
@@ -8,16 +8,19 @@ module Babelish
8
8
 
9
9
  def load_strings(strings_filename)
10
10
  strings = {}
11
- raise Errno::ENOENT unless File.exist?(strings_filename)
11
+ xml_file = File.open(strings_filename)
12
12
 
13
- xmlfile = XmlSimple.xml_in(strings_filename)
14
- xmlfile['string'].each do |element|
15
- if !element.nil? && !element['name'].nil?
16
- content = element['content'].nil? ? '' : element['content']
17
- strings.merge!({element['name'] => content})
13
+ parser = Nokogiri::XML(xml_file) do |config|
14
+ config.strict.noent
15
+ end
16
+ parser.xpath("//string").each do |node|
17
+ if !node.nil? && !node["name"].nil?
18
+ strings.merge!(node["name"] => node.inner_html)
18
19
  end
19
20
  end
20
21
 
22
+ xml_file.close
23
+
21
24
  [strings, {}]
22
25
  end
23
26
 
@@ -1,7 +1,5 @@
1
1
  module Babelish
2
2
  class CSV2Android < Csv2Base
3
- require 'xmlsimple'
4
-
5
3
  attr_accessor :file_path
6
4
 
7
5
  def initialize(filename, langs, args = {})
@@ -16,19 +14,29 @@ module Babelish
16
14
  return filepath ? [filepath] : []
17
15
  end
18
16
 
17
+ def process_value(row_value, default_value)
18
+ value = super(row_value, default_value)
19
+ # if the value begins and ends with a quote we must leave them unescapted
20
+ if value.size > 4 && value[0, 2] == "\\\"" && value[value.size - 2, value.size] == "\\\""
21
+ value[0, 2] = "\""
22
+ value[value.size - 2, value.size] = "\""
23
+ end
24
+ value.to_utf8
25
+ end
26
+
19
27
  def get_row_format(row_key, row_value, comment = nil, indentation = 0)
20
- return "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
28
+ "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
21
29
  end
22
30
 
23
31
  def hash_to_output(content = {})
24
32
  output = ''
25
33
  if content && content.size > 0
26
- output += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
34
+ output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
27
35
  output += "<resources>\n"
28
36
  content.each do |key, value|
29
37
  output += get_row_format(key, value)
30
38
  end
31
- output += "</resources>"
39
+ output += "</resources>\n"
32
40
  end
33
41
  return output
34
42
  end
@@ -1,3 +1,3 @@
1
1
  module Babelish
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -15,21 +15,39 @@ class TestAndroid2CSV < Test::Unit::TestCase
15
15
 
16
16
  def test_initialize
17
17
  csv_filename = "file.csv"
18
- filenames = %w{"french.strings english.strings"}
19
- headers = %w{"constants french english"}
20
- converter = Babelish::Android2CSV.new({
18
+ filenames = %w{french.strings english.strings}
19
+ headers = %w{constants french english}
20
+ converter = Babelish::Android2CSV.new(
21
21
  :csv_filename => csv_filename,
22
22
  :headers => headers,
23
- :filenames => filenames
24
- })
23
+ :filenames => filenames)
25
24
 
26
- assert_equal csv_filename, converter.csv_filename
27
- assert_equal headers, converter.headers
28
- assert_equal filenames, converter.filenames
29
- end
25
+ assert_equal csv_filename, converter.csv_filename
26
+ assert_equal headers, converter.headers
27
+ assert_equal filenames, converter.filenames
28
+ end
30
29
 
31
- def test_initialize_with_default_values
32
- converter = Babelish::Android2CSV.new
33
- assert_not_nil converter.csv_filename
34
- end
30
+ def test_initialize_with_default_values
31
+ converter = Babelish::Android2CSV.new
32
+ assert_not_nil converter.csv_filename
33
+ end
34
+
35
+ def test_special_chars
36
+ csv_filename = "./android_special_chars_output.csv"
37
+ filenames = "test/data/android_special_chars.xml"
38
+ headers = %w{variables german}
39
+
40
+ converter = Babelish::Android2CSV.new(
41
+ :csv_filename => csv_filename,
42
+ :headers => headers,
43
+ :filenames => [filenames])
44
+
45
+ converter.convert
46
+
47
+ assert File.exist?(converter.csv_filename)
48
+ assert_equal File.read("test/data/android_special_chars.csv"), File.read(csv_filename)
49
+
50
+ # clean up
51
+ system("rm -rf ./" + csv_filename)
35
52
  end
53
+ end
@@ -6,7 +6,7 @@ class TestBins < Test::Unit::TestCase
6
6
  assert_nothing_raised do
7
7
  system("./bin/babelish csv2strings --fetch --filename my_strings --langs English:en")
8
8
  end
9
- assert_equal $?.exitstatus, 0
9
+ assert_equal 0, $?.exitstatus
10
10
  end
11
11
 
12
12
  def test_csv2strings_with_google_doc_missing_langs
@@ -14,7 +14,7 @@ class TestBins < Test::Unit::TestCase
14
14
  assert_nothing_raised do
15
15
  system("./bin/babelish csv2strings --fetch --filename my_strings")
16
16
  end
17
- assert_equal $?.exitstatus, 1
17
+ assert_equal 1, $?.exitstatus
18
18
  end
19
19
 
20
20
  def test_csv2strings_with_config_file
@@ -23,7 +23,7 @@ class TestBins < Test::Unit::TestCase
23
23
  assert_nothing_raised NameError do
24
24
  system("./bin/babelish csv2strings")
25
25
  end
26
- assert_equal $?.exitstatus, 0
26
+ assert_equal 0, $?.exitstatus
27
27
  end
28
28
 
29
29
  def teardown
@@ -5,12 +5,23 @@ class TestCSV2Android < Test::Unit::TestCase
5
5
  csv_file = "test/data/test_data.csv"
6
6
  converter = Babelish::CSV2Android.new(csv_file, 'English' => "en")
7
7
  converter.convert
8
- assert File.exists?("values-en/strings.xml"), "the ouptut file does not exist"
8
+ assert File.exist?("values-en/strings.xml"), "the ouptut file does not exist"
9
9
 
10
- #clean up
10
+ # clean up
11
11
  system("rm -rf ./values-en")
12
12
  end
13
13
 
14
+ def test_converting_csv_with_special_chars
15
+ csv_file = "test/data/android_special_chars.csv"
16
+ converter = Babelish::CSV2Android.new(csv_file, "german" => "de")
17
+ converter.convert
18
+ assert File.exist?("values-de/strings.xml"), "the ouptut file does not exist"
19
+ assert_equal File.read("test/data/android_special_chars_test_result.xml"), File.read("values-de/strings.xml")
20
+
21
+ # clean up
22
+ system("rm -rf ./values-de")
23
+ end
24
+
14
25
  def test_converting_csv_to_dotstrings_one_output_option
15
26
  csv_file = "test/data/test_data.csv"
16
27
  single_file = 'myApp.xml'
@@ -19,9 +30,9 @@ class TestCSV2Android < Test::Unit::TestCase
19
30
  :output_basename => 'myApp',
20
31
  :ignore_lang_path => true)
21
32
  converter.convert
22
- assert File.exists?(single_file), "the ouptut file does not exist"
33
+ assert File.exist?(single_file), "the ouptut file does not exist"
23
34
 
24
- #clean up
35
+ # clean up
25
36
  system("rm -rf ./" + single_file)
26
37
  end
27
38
  end
@@ -9,39 +9,36 @@ class TestCsv2Base < Test::Unit::TestCase
9
9
  converter = Babelish::Csv2Base.new(csv_filename, {"English" => ["en"]}, {
10
10
  :excluded_states => excluded_states,
11
11
  :state_column => state_column,
12
- :keys_column => keys_column
13
- })
12
+ :keys_column => keys_column })
14
13
 
15
- assert_equal csv_filename, converter.csv_filename
16
- assert_equal excluded_states, converter.excluded_states
17
- assert_equal state_column, converter.state_column
18
- assert_equal keys_column, converter.keys_column
19
- end
14
+ assert_equal csv_filename, converter.csv_filename
15
+ assert_equal excluded_states, converter.excluded_states
16
+ assert_equal state_column, converter.state_column
17
+ assert_equal keys_column, converter.keys_column
18
+ end
20
19
 
21
- def test_initialize_with_default_values
22
- converter = Babelish::Csv2Base.new("file.csv", {"English" => ["en"]})
23
- assert_not_nil converter.csv_filename
24
- end
25
-
26
- def test_initialize_with_custom_separator
27
- converter = Babelish::Csv2Base.new("file.csv", {"English" => ["en"]}, {
28
- :csv_separator => ";"
29
- })
30
- assert_not_nil converter.csv_filename
31
- end
20
+ def test_initialize_with_default_values
21
+ converter = Babelish::Csv2Base.new("file.csv", "English" => ["en"])
22
+ assert_not_nil converter.csv_filename
23
+ end
32
24
 
33
- def test_create_file_from_path
34
- test_file = "test_file.txt"
35
- Babelish::Csv2Base.new("file.csv", {"English" => ["en"]}).create_file_from_path test_file
36
- assert File.exist?(test_file)
25
+ def test_initialize_with_custom_separator
26
+ converter = Babelish::Csv2Base.new("file.csv", { "English" => ["en"] }, { :csv_separator => ";" })
27
+ assert_not_nil converter.csv_filename
28
+ end
37
29
 
38
- #clean up
39
- system("rm -rf ./" + test_file)
40
- end
30
+ def test_create_file_from_path
31
+ test_file = "test_file.txt"
32
+ Babelish::Csv2Base.new("file.csv", "English" => ["en"]).create_file_from_path test_file
33
+ assert File.exist?(test_file)
34
+
35
+ # clean up
36
+ system("rm -rf ./" + test_file)
37
+ end
41
38
 
42
- def test_get_row_format
43
- expected_output = "\"test_key\" = \"test_value\""
44
- output = Babelish::Csv2Base.new("file.csv", {"English" => ["en"]}).get_row_format("test_key", "test_value")
45
- assert_equal expected_output, output
46
- end
39
+ def test_get_row_format
40
+ expected_output = "\"test_key\" = \"test_value\""
41
+ output = Babelish::Csv2Base.new("file.csv", "English" => ["en"]).get_row_format("test_key", "test_value")
42
+ assert_equal expected_output, output
47
43
  end
44
+ end
@@ -20,16 +20,15 @@ class JSON2CSVTest < Test::Unit::TestCase
20
20
  converter = Babelish::JSON2CSV.new({
21
21
  :csv_filename => csv_filename,
22
22
  :headers => headers,
23
- :filenames => filenames
24
- })
23
+ :filenames => filenames })
25
24
 
26
- assert_equal csv_filename, converter.csv_filename
27
- assert_equal headers, converter.headers
28
- assert_equal filenames, converter.filenames
29
- end
25
+ assert_equal csv_filename, converter.csv_filename
26
+ assert_equal headers, converter.headers
27
+ assert_equal filenames, converter.filenames
28
+ end
30
29
 
31
- def test_initialize_with_default_values
32
- converter = Babelish::JSON2CSV.new
33
- assert_not_nil converter.csv_filename
34
- end
30
+ def test_initialize_with_default_values
31
+ converter = Babelish::JSON2CSV.new
32
+ assert_not_nil converter.csv_filename
35
33
  end
34
+ end
@@ -59,16 +59,15 @@ class TestPhp2CSV < Test::Unit::TestCase
59
59
  converter = Babelish::Php2CSV.new({
60
60
  :csv_filename => csv_filename,
61
61
  :headers => headers,
62
- :filenames => filenames
63
- })
62
+ :filenames => filenames })
64
63
 
65
- assert_equal csv_filename, converter.csv_filename
66
- assert_equal headers, converter.headers
67
- assert_equal filenames, converter.filenames
68
- end
64
+ assert_equal csv_filename, converter.csv_filename
65
+ assert_equal headers, converter.headers
66
+ assert_equal filenames, converter.filenames
67
+ end
69
68
 
70
- def test_initialize_with_default_values
71
- converter = Babelish::Php2CSV.new
72
- assert_not_nil converter.csv_filename
73
- end
69
+ def test_initialize_with_default_values
70
+ converter = Babelish::Php2CSV.new
71
+ assert_not_nil converter.csv_filename
74
72
  end
73
+ end
@@ -8,7 +8,7 @@ class TestStrings2CSV < Test::Unit::TestCase
8
8
  expected_output = ["MY_CONSTANT","This is ok"]
9
9
 
10
10
  output = Babelish::Strings2CSV.new.parse_dotstrings_line input
11
- assert_equal expected_output, output
11
+ assert_equal expected_output, output
12
12
  end
13
13
 
14
14
  def test_parse_dotstrings_line_with_single_quote
@@ -68,13 +68,13 @@ class TestStrings2CSV < Test::Unit::TestCase
68
68
  end
69
69
 
70
70
  def test_load_strings_with_spaces
71
- expected_output = [{"name"=>"definition",
72
- "name1"=>"definition1",
73
- "name2"=>"definition2",
74
- "name3"=>"definition3",
75
- "name4"=>"definition4",
76
- "this is a name"=>"a definition"
77
- },{}]
71
+ expected_output = [{ "name" => "definition",
72
+ "name1" => "definition1",
73
+ "name2" => "definition2",
74
+ "name3" => "definition3",
75
+ "name4" => "definition4",
76
+ "this is a name" => "a definition"
77
+ }, {}]
78
78
  output = Babelish::Strings2CSV.new.load_strings "test/data/test_space.strings"
79
79
  assert_equal expected_output, output
80
80
  end
@@ -127,13 +127,12 @@ class TestStrings2CSV < Test::Unit::TestCase
127
127
 
128
128
  def test_initialize
129
129
  csv_filename = "file.csv"
130
- filenames = %w{"french.strings english.strings"}
131
- headers = %w{"constants french english"}
130
+ filenames = %w{french.strings english.strings}
131
+ headers = %w{constants french english}
132
132
  converter = Babelish::Strings2CSV.new({
133
133
  :csv_filename => csv_filename,
134
134
  :headers => headers,
135
- :filenames => filenames
136
- })
135
+ :filenames => filenames })
137
136
 
138
137
  assert_equal csv_filename, converter.csv_filename
139
138
  assert_equal headers, converter.headers
@@ -1,3 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
1
2
  <resources>
2
3
 
3
4
  <string name="app_name">android2csv</string>
@@ -1,3 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
1
2
  <resources>
2
3
 
3
4
  <string name="app_name">android2csv</string>
@@ -1,3 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
1
2
  <resources>
2
3
 
3
4
  <string name="app_name">android2csv</string>
@@ -0,0 +1,8 @@
1
+ variables,german
2
+ good_example_1,This\'ll work
3
+ good_example_2,"This is a \""good string\""."
4
+ good_example_3,"""This'll also work"""
5
+ welcome_messages_1,"Hello, %1$s! You have %2$d new messages."
6
+ welcome_messages_2,"Hello, %1$s! You have &lt;b&gt;%2$d new messages&lt;/b&gt;."
7
+ ANOTHER_STRING,"text <b>with</b> html and \' special # chars ` ´ !""§$%/()==?{[]}"
8
+ title,"Title of &lt;a href=""asd""&gt;File&lt;/a&gt;"
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+
4
+ <string name="good_example_1">This\'ll work</string>
5
+ <string name="good_example_2">This is a \"good string\".</string>
6
+ <string name="good_example_3">"This'll also work"</string>
7
+ <string name="welcome_messages_1">Hello, %1$s! You have %2$d new messages.</string>
8
+ <string name="welcome_messages_2">Hello, %1$s! You have &lt;b>%2$d new messages&lt;/b>.</string>
9
+ <string name="ANOTHER_STRING">text <b>with</b> html and \' special # chars ` ´ !"§$%/()==?{[]}</string>
10
+ <string name="title">Title of &lt;a href="asd">File&lt;/a></string>
11
+
12
+ </resources>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="good_example_1">This\'ll work</string>
4
+ <string name="good_example_2">This is a \"good string\".</string>
5
+ <string name="good_example_3">"This'll also work"</string>
6
+ <string name="welcome_messages_1">Hello, %1$s! You have %2$d new messages.</string>
7
+ <string name="welcome_messages_2">Hello, %1$s! You have &lt;b&gt;%2$d new messages&lt;/b&gt;.</string>
8
+ <string name="ANOTHER_STRING">text <b>with</b> html and \' special # chars ` ´ !\"§$%/()==?{[]}</string>
9
+ <string name="title">Title of &lt;a href=\"asd\"&gt;File&lt;/a&gt;</string>
10
+ </resources>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babelish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - François Benaiteau
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-22 00:00:00.000000000 Z
12
+ date: 2015-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: 1.0.1
42
42
  - !ruby/object:Gem::Dependency
43
- name: highline
43
+ name: nokogiri
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: xml-simple
57
+ name: highline
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ! '>='
@@ -194,6 +194,9 @@ files:
194
194
  - test/data/android-en.xml
195
195
  - test/data/android-fr.xml
196
196
  - test/data/android.xml
197
+ - test/data/android_special_chars.csv
198
+ - test/data/android_special_chars.xml
199
+ - test/data/android_special_chars_test_result.xml
197
200
  - test/data/genstrings.strings
198
201
  - test/data/json.json
199
202
  - test/data/php_lang.php