babelish 0.3.4 → 0.4.0

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
- OGYzYzgwY2Y1NWU1MjVjMWY1YmI1YjhhMjc5M2VmZDlkODU5ODUxNg==
4
+ NTYwYjA5YzUyN2Q2YTQ1YjZjMjljMmU3ZGNlYTgxODFhYzY4NjYyMg==
5
5
  data.tar.gz: !binary |-
6
- OTg3NjllNjQ4ZTRkM2UzMTBmZDFhMjNjZjdhMWVmOTY3NTczMjA0Mw==
6
+ NjkyYzg1ODVmYTUyNDdiNThmNTFiMjM2OWRmM2U4ZGRjOTIyNjdjZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzE3MjhiZjc3YmJiMThjNGMyNmY1OGU0YWFiZTE5MWMxMDdkMGVkZGZkZGRk
10
- NWQ5NWQ3MDc1NmJkZWEyY2JiODNlNjBjODhhOWQ4YTZjOTdmZTZkMzliOTFk
11
- MzJjYTQ1ZWNhMDQ2YTJiZTZmMDEzMDk4ZGMxZWFiOGZiYjIxYWY=
9
+ MTJiOGU1MGNhYmQ5OTI1NjZkM2JmNTcyYTRhY2M4ZGRjNzUyZDk1ZTQ4NjQ1
10
+ NzM1ZTUzNzIxZjNmMzQ1OTZjMTA4MjU1MDkwOGYwZTg1MDdhYjU0MzA3Njhk
11
+ OTNkOTc2MTc0MDQ1NTFmZjExOTFiOTkzZjNjN2Y5MjBlZTYxOTE=
12
12
  data.tar.gz: !binary |-
13
- MTU1YmNiMDFjODRmMjQ0Y2UyYTE5Zjk1YjQxYjRlYWY5ODcyNzIwZjZkZTNh
14
- MDFkNDVkYTIyMGExZTZmNTYzN2NhZTJjMDVhNGY0ZDJkN2ZkYTMwZDVhMjgy
15
- ZjRiYmM5ZDQ4Zjk5Y2YxOGMwZmYwY2ZmNWYzMThjMmRhNTU3NDc=
13
+ M2FlYmFlNzIzYTQ2YzVhYzU5ZTMyYWM0MmNmNDk1Mjg0Zjk2NmRmZDJmMjBk
14
+ NDNhM2UyZGNkZDA3MzM3YjI3NWM0ZDk1YTQzZDFjYTM1MGY4ZmZmZWIxYmJi
15
+ YThmMDI1YWI2Yjk1YjFlNzVlN2RhMWI3Y2NlNGM5Zjk4MWExZjg=
data/.babelish.sample CHANGED
@@ -20,6 +20,7 @@ langs: # Languages to convert. i.e. English:en
20
20
  ## optional
21
21
  # fetch: true # set to true to get file(filename) from google drive
22
22
  # excluded_states: ["Images", "Xib"] # Exclude rows with given state
23
+ # comments_column: 4 # Position of column for comments if any
23
24
  # state_column: 3 # Position of column for state if any
24
25
  # keys_column: 0 # Position of column for keys
25
26
  # default_lang: "English" # Header name of column containing fallback value if value is empty
data/README.md CHANGED
@@ -45,6 +45,9 @@ See [.babelish.sample](.babelish.sample) file in the doc folder. as the possible
45
45
 
46
46
  *For previous CSV-to-iOS-Localizable.strings-converter, rename your `.csvconverter` into `.babelish`.*
47
47
 
48
+ **For more details, check the documentation:**
49
+ https://github.com/netbe/Babelish/wiki/How-to-Use
50
+
48
51
  # Contributing
49
52
 
50
53
  Want to add another support for a new format or/and usage? Add a new feature? Fix a bug?
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-03-16'
9
+ s.date = '2015-05-22'
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)
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "thor"
22
22
 
23
- s.add_dependency "google_drive", "~> 0.3.10"
23
+ s.add_dependency "google_drive", "~> 1.0.1"
24
24
  # google_drive dependency to ask for mail and password
25
25
  s.add_dependency "highline"
26
26
 
@@ -18,7 +18,7 @@ module Babelish
18
18
  end
19
19
  end
20
20
 
21
- strings
21
+ [strings, {}]
22
22
  end
23
23
 
24
24
  end
@@ -24,17 +24,19 @@ module Babelish
24
24
  def convert(write_to_file = true)
25
25
  strings = {}
26
26
  keys = nil
27
+ comments = {}
27
28
 
28
29
  @filenames.each do |fname|
29
30
  header = fname
30
- strings[header] = load_strings(fname)
31
+ strings[header], file_comments = load_strings(fname)
31
32
  keys ||= strings[header].keys
33
+ comments.merge!(file_comments)
32
34
  end
33
35
 
34
36
  if write_to_file
35
37
  # Create csv file
36
38
  puts "Creating #{@csv_filename}"
37
- create_csv_file(keys, strings)
39
+ create_csv_file(keys, strings, comments)
38
40
  else
39
41
  return keys, strings
40
42
  end
@@ -48,7 +50,7 @@ module Babelish
48
50
  # for a given language
49
51
  # @return [Hash] the translations for a given language
50
52
  def load_strings(strings_filename)
51
- return {}
53
+ return [{}, {}]
52
54
  end
53
55
 
54
56
  # Give the default headers of csv file
@@ -77,7 +79,8 @@ module Babelish
77
79
  #
78
80
  # @param [Array] keys references of all translations
79
81
  # @param [Array] strings translations of all languages
80
- def create_csv_file(keys, strings)
82
+ # @param [Hash] comments hash containing keys, comments related to each keys, describe the translation
83
+ def create_csv_file(keys, strings, comments = nil)
81
84
  raise "csv_filename must not be nil" unless @csv_filename
82
85
  CSV.open(@csv_filename, "wb") do |csv|
83
86
  csv << @headers
@@ -89,6 +92,7 @@ module Babelish
89
92
  current_val = (lang != default_lang && strings[lang][key] == default_val) ? '' : strings[lang][key]
90
93
  line << current_val
91
94
  end
95
+ line << comments[key] if comments && comments[key]
92
96
  csv << line
93
97
  end
94
98
  puts "Done"
@@ -19,7 +19,8 @@ class Commandline < Thor
19
19
  # optional options
20
20
  method_option :excluded_states, :type => :array, :aliases => "-x", :desc => "Exclude rows with given state"
21
21
  method_option :state_column, :type => :numeric, :aliases => "-s", :desc => "Position of column for state if any"
22
- method_option :keys_column, :type => :numeric, :aliases => "-k", :desc => "Position of column for keys"
22
+ method_option :keys_column, :type => :numeric, :aliases => "-k", :desc => "Position of column for keys"
23
+ method_option :comments_column, :type => :numeric, :aliases => "-c", :desc => "Position of column for comments if any"
23
24
  method_option :default_lang, :type => :string, :aliases => "-l", :desc => "Default language to use for empty values if any"
24
25
  method_option :csv_separator, :type => :string, :aliases => "-cs", :desc => "CSV column separator character, uses ',' by default"
25
26
  method_option :output_dir, :type => :string, :aliases => "-d", :desc => "Path of output files"
@@ -85,6 +86,22 @@ class Commandline < Thor
85
86
  end
86
87
  end
87
88
 
89
+ desc "init", "Create a configuration file from template"
90
+ def init
91
+ if File.exists?(".babelish")
92
+ say "Config file '.babelish' already exists."
93
+ else
94
+ say "Creating new config file '.babelish'."
95
+ config_file = File.expand_path("../../../.babelish.sample", __FILE__)
96
+ if File.exists?(config_file)
97
+ system "cp #{config_file} .babelish"
98
+ else
99
+ say "Template '#{config_file}' not found."
100
+ end
101
+ end
102
+ end
103
+
104
+
88
105
  desc "version", "Display current version"
89
106
  def version
90
107
  require "babelish/version"
@@ -133,7 +150,7 @@ class Commandline < Thor
133
150
  args = Thor::CoreExt::HashWithIndifferentAccess.new(args)
134
151
  converter = class_object.new(filename, options[:langs], args)
135
152
  say converter.convert
136
- xcode_macros.process(converter.table, converter.keys) if options[:macros_filename]
153
+ xcode_macros.process(converter.table, converter.keys, converter.comments) if options[:macros_filename]
137
154
  end
138
155
  if options[:macros_filename]
139
156
  say "generating macros"
@@ -16,8 +16,8 @@ module Babelish
16
16
  return filepath ? [filepath] : []
17
17
  end
18
18
 
19
- def get_row_format(row_key, row_value)
20
- return "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
19
+ def get_row_format(row_key, row_value, comment = nil, indentation = 0)
20
+ return "\t<string name=\"#{row_key}\">#{row_value}</string>\n"
21
21
  end
22
22
 
23
23
  def hash_to_output(content = {})
@@ -7,7 +7,7 @@ module Babelish
7
7
  attr_accessor :csv_filename
8
8
  attr_accessor :default_lang
9
9
  attr_accessor :csv_separator
10
- attr_accessor :excluded_states, :state_column, :keys_column
10
+ attr_accessor :excluded_states, :state_column, :keys_column, :comments_column
11
11
  attr_accessor :languages
12
12
 
13
13
  def initialize(filename, langs, args = {})
@@ -34,11 +34,13 @@ module Babelish
34
34
  @excluded_states = args[:excluded_states]
35
35
  @state_column = args[:state_column]
36
36
  @keys_column = args[:keys_column]
37
+ @comments_column = args[:comments_column]
37
38
  @default_lang = args[:default_lang]
38
39
  @csv_separator = args[:csv_separator]
39
40
  @ignore_lang_path = args[:ignore_lang_path]
40
41
  @stripping = args[:stripping]
41
42
  @languages = []
43
+ @comments = {}
42
44
  end
43
45
 
44
46
  def create_file_from_path(file_path)
@@ -59,6 +61,10 @@ module Babelish
59
61
  output_basename
60
62
  end
61
63
 
64
+ def comments
65
+ @comments
66
+ end
67
+
62
68
  def language_filepaths(language)
63
69
  #implement in subclass
64
70
  []
@@ -82,8 +88,9 @@ module Babelish
82
88
  return value.to_utf8
83
89
  end
84
90
 
85
- def get_row_format(row_key, row_value)
86
- return "\"" + row_key + "\" = \"" + row_value + "\""
91
+ def get_row_format(row_key, row_value, comment = nil, indentation = 0)
92
+ # ignoring comment by default
93
+ "\"#{row_key}\"" + " " * indentation + " = \"#{row_value}\""
87
94
  end
88
95
 
89
96
  # Convert csv file to multiple Localizable.strings files for each column
@@ -124,10 +131,11 @@ module Babelish
124
131
  @languages[i] = language
125
132
  elsif !@state_column || (row[@state_column].nil? || row[@state_column] == '' || !@excluded_states.include?(row[@state_column]))
126
133
  key = row[@keys_column]
134
+ comment = @comments_column ? row[@comments_column] : nil
127
135
  key.strip! if @stripping
128
136
  default_value = self.default_lang ? row[defaultCol] : nil
129
137
  value = self.process_value(row[i], default_value)
130
-
138
+ @comments[key] = comment
131
139
  @languages[i].add_content_pair(key, value)
132
140
  end
133
141
  end
@@ -167,9 +175,11 @@ module Babelish
167
175
 
168
176
  def hash_to_output(content = {})
169
177
  output = ''
178
+ indentation = content.map(&:first).max { |a, b| a.length <=> b.length }.length
170
179
  if content && content.size > 0
171
180
  content.each do |key, value|
172
- output += get_row_format(key, value)
181
+ comment = @comments[key]
182
+ output += get_row_format(key, value, comment, indentation - key.length)
173
183
  end
174
184
  end
175
185
  return output
@@ -14,8 +14,8 @@ module Babelish
14
14
  return filepath ? [filepath] : []
15
15
  end
16
16
 
17
- def get_row_format(row_key, row_value)
18
- return "$" + @php_tag + "['#{row_key}'] = \"#{row_value}\";\n"
17
+ def get_row_format(row_key, row_value, comment = nil, indentation = 0)
18
+ "$" + @php_tag + "['#{row_key}']" + " " * indentation + " = \"#{row_value}\";\n"
19
19
  end
20
20
 
21
21
  def extension
@@ -15,8 +15,9 @@ module Babelish
15
15
  filepaths
16
16
  end
17
17
 
18
- def get_row_format(row_key, row_value)
19
- return "\"#{row_key}\" = \"#{row_value}\";\n"
18
+ def get_row_format(row_key, row_value, comment = nil, indentation = 0)
19
+ entry = comment.to_s.empty? ? "" : "\n/* #{comment} */\n"
20
+ entry + "\"#{row_key}\"" + " " * indentation + " = \"#{row_value}\";\n"
20
21
  end
21
22
 
22
23
  def extension
@@ -24,9 +24,10 @@ module Babelish
24
24
 
25
25
  def download_spreadsheet(requested_filename, output_filename, worksheet_index = 0)
26
26
  output_filename ||= "translations.csv"
27
- file = file_with_name(requested_filename)
28
- return nil unless file
29
- file.export_as_file(output_filename, "csv", worksheet_index)
27
+ spreadsheet = file_with_name(requested_filename)
28
+ return nil unless spreadsheet
29
+ worksheet = spreadsheet.worksheets[worksheet_index]
30
+ worksheet.export_as_file(output_filename)
30
31
  return output_filename
31
32
  end
32
33
 
@@ -48,12 +49,7 @@ module Babelish
48
49
  unless @session
49
50
  authenticate
50
51
  end
51
- result = @session.file_by_title(name)
52
- if result.is_a? Array
53
- file = result.first
54
- else
55
- file = result
56
- end
52
+ @session.spreadsheet_by_title(name)
57
53
  end
58
54
  end
59
55
  end
@@ -11,15 +11,23 @@ module Babelish
11
11
  def parse_dotstrings_line(line)
12
12
  line.strip!
13
13
  if line[0] != ?# && line[0] != ?= && line[0] != ?/
14
- m = line.match(/^[^\"]*\"(.+)\"[^=]+=[^\"]*\"(.*)\";/)
15
- return {m[1] => m[2]} unless m.nil?
14
+ m = line.match(/^[\s*]*\"(.+)\"[\s]*=\s*\"(.*)\"\s*;/)
15
+ return m[1], m[2] unless m.nil?
16
+ end
17
+ end
18
+
19
+ def parse_comment_line(line)
20
+ line.strip!
21
+ if line[0] != ?# && line[0] != ?=
22
+ m = line.match(/^\/\*(.*)\*\/\s*$/)
23
+ return m[1].strip! unless m.nil?
16
24
  end
17
25
  end
18
26
 
19
27
  # Load all strings of a given file
20
28
  def load_strings(strings_filename)
21
29
  strings = {}
22
-
30
+ comments = {}
23
31
  # genstrings uses utf16, so that's what we expect. utf8 should not be impact
24
32
  file = File.open(strings_filename, "r:utf-16:utf-8")
25
33
  begin
@@ -35,12 +43,18 @@ module Babelish
35
43
  # faults back to utf8
36
44
  contents = File.open(strings_filename, "r:utf-8")
37
45
  end
46
+ previous_comment = nil
38
47
  contents.each_line do |line|
39
- hash = self.parse_dotstrings_line(line)
40
- strings.merge!(hash) if hash
48
+ key, value = self.parse_dotstrings_line(line)
49
+ if key
50
+ strings.merge!({key => value})
51
+ comments[key] = previous_comment if previous_comment
52
+ else
53
+ previous_comment = self.parse_comment_line(line)
54
+ end
41
55
  end
42
56
 
43
- strings
57
+ [strings, comments]
44
58
  end
45
59
 
46
60
  end
@@ -1,3 +1,3 @@
1
1
  module Babelish
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -7,13 +7,13 @@ module Babelish
7
7
  @keys = keys
8
8
  end
9
9
 
10
- def self.write_macros(file_path, table, keys)
10
+ def self.write_macros(file_path, table, keys, comments = {})
11
11
  instance = XcodeMacros.new
12
- instance.process(table, keys)
12
+ instance.process(table, keys, comments)
13
13
  instance.write_content(file_path)
14
14
  end
15
15
 
16
- def process(table, keys)
16
+ def process(table, keys, comments = {})
17
17
  keys.each do |key|
18
18
  clean_key = key.gsub(' ', '')
19
19
  clean_key.gsub!(/[[:punct:]]/, '_')
@@ -22,8 +22,9 @@ module Babelish
22
22
  clean_key = clean_key[0..clean_key.size-2] if clean_key.size > 1 and clean_key[clean_key.size-1] == '_'
23
23
  macro_name = "LS_#{clean_key.upcase}"
24
24
  macro_name += "_#{table.upcase}" if table != "Localizable"
25
+ comment = comments[key]
25
26
  @content << String.new(<<-EOS)
26
- #define #{macro_name} NSLocalizedStringFromTable(@"#{key}",@"#{table}",@"")
27
+ #define #{macro_name} NSLocalizedStringFromTable(@"#{key}",@"#{table}",@"#{comment.to_s}")
27
28
  EOS
28
29
  end
29
30
  @content
@@ -8,7 +8,7 @@ class TestAndroid2CSV < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_load_strings
11
- expected_output = {"app_name" => "android2csv", "action_greetings" => "Hello", "ANOTHER_STRING" => "testEN", "empty" => ""}
11
+ expected_output = [{"app_name" => "android2csv", "action_greetings" => "Hello", "ANOTHER_STRING" => "testEN", "empty" => ""}, {}]
12
12
  output = Babelish::Android2CSV.new.load_strings "test/data/android.xml"
13
13
  assert_equal expected_output, output
14
14
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
  class TestBase2Csv < Test::Unit::TestCase
3
3
 
4
4
  def test_load_strings
5
- expected_output = {}
5
+ expected_output = [{}, {}]
6
6
  output = Babelish::Base2Csv.new.send :load_strings, nil
7
7
  assert_equal expected_output, output
8
8
  end
@@ -1,6 +1,14 @@
1
1
  require 'test_helper'
2
2
  class TestCommandLine < Test::Unit::TestCase
3
3
 
4
+ def test_init
5
+ assert_nothing_raised do
6
+ Commandline.new.init
7
+ end
8
+ #clean up
9
+ system("rm -f .babelish")
10
+ end
11
+
4
12
  def test_csv2base_with_config_file_all_required_options
5
13
  options = {
6
14
  :filename => "test/data/test_data_multiple_langs.csv",
@@ -23,7 +23,7 @@ class TestCSV2Strings < Test::Unit::TestCase
23
23
 
24
24
  def test_converting_csv_to_dotstrings_default_lang
25
25
  expected_output = String.new(<<-EOS)
26
- "GREETINGS" = "Buenos dias";
26
+ "GREETINGS" = "Buenos dias";
27
27
  "ANOTHER_STRING" = "testEN";
28
28
  EOS
29
29
  csv_file = "test/data/test_data_multiple_langs.csv"
@@ -40,7 +40,7 @@ class TestCSV2Strings < Test::Unit::TestCase
40
40
 
41
41
  def test_converting_csv_to_dotstrings_with_no_default_lang_is_empty
42
42
  expected_output = String.new(<<-EOS)
43
- "GREETINGS" = "Buenos dias";
43
+ "GREETINGS" = "Buenos dias";
44
44
  "ANOTHER_STRING" = "";
45
45
  EOS
46
46
  csv_file = "test/data/test_data_multiple_langs.csv"
@@ -56,7 +56,7 @@ class TestCSV2Strings < Test::Unit::TestCase
56
56
 
57
57
  def test_converting_csv_to_dotstrings_default_lang_to_key
58
58
  expected_output = String.new(<<-EOS)
59
- "GREETINGS" = "Buenos dias";
59
+ "GREETINGS" = "Buenos dias";
60
60
  "ANOTHER_STRING" = "ANOTHER_STRING";
61
61
  EOS
62
62
  csv_file = "test/data/test_data_multiple_langs.csv"
@@ -73,7 +73,7 @@ class TestCSV2Strings < Test::Unit::TestCase
73
73
 
74
74
  def test_converting_csv_to_dotstrings_keys
75
75
  expected_output = String.new(<<-EOS)
76
- "GREETINGS" = "Buenos dias";
76
+ "GREETINGS" = "Buenos dias";
77
77
  "ANOTHER_STRING" = "ANOTHER_STRING";
78
78
  EOS
79
79
  csv_file = "test/data/test_data_multiple_langs.csv"
@@ -87,7 +87,7 @@ class TestCSV2Strings < Test::Unit::TestCase
87
87
 
88
88
  def test_converting_csv_to_dotstrings_with_percent
89
89
  expected_output = String.new(<<-EOS)
90
- "GREETINGS" = "hello_%@";
90
+ "GREETINGS" = "hello_%@";
91
91
  "ANOTHER_STRING" = "hello";
92
92
  EOS
93
93
  csv_file = "test/data/test_data_with_percent.csv"
@@ -100,7 +100,7 @@ class TestCSV2Strings < Test::Unit::TestCase
100
100
 
101
101
  def test_converting_csv_to_dotstrings_with_spaces
102
102
  expected_output = String.new(<<-EOS)
103
- "GREETINGS " = "hello ";
103
+ "GREETINGS " = "hello ";
104
104
  "ANOTHER_STRING" = " my other string with space at begin";
105
105
  EOS
106
106
  csv_file = "test/data/test_data_with_spaces.csv"
@@ -113,8 +113,8 @@ class TestCSV2Strings < Test::Unit::TestCase
113
113
 
114
114
  def test_converting_csv_to_dotstrings_with_percent_space
115
115
  expected_output = String.new(<<-EOS)
116
- "GREETINGS" = "you have %d points";
117
- "ANOTHER_STRING" = "this is a string with 10% of juice";
116
+ "GREETINGS" = "you have %d points";
117
+ "ANOTHER_STRING" = "this is a string with 10% of juice";
118
118
  "ANOTHER_EXAMPLE" = "tu as fait 10% d'efforts";
119
119
  EOS
120
120
  csv_file = "test/data/test_data_with_percent_space.csv"
@@ -127,7 +127,7 @@ class TestCSV2Strings < Test::Unit::TestCase
127
127
 
128
128
  def test_converting_csv_to_dotstrings_with_stripping_option
129
129
  expected_output = String.new(<<-EOS)
130
- "GREETINGS" = "hello";
130
+ "GREETINGS" = "hello";
131
131
  "ANOTHER_STRING" = "my other string with space at begin";
132
132
  EOS
133
133
  csv_file = "test/data/test_data_with_spaces.csv"
@@ -137,4 +137,18 @@ class TestCSV2Strings < Test::Unit::TestCase
137
137
  assert_equal expected_output, result
138
138
  system("rm -rf *.lproj")
139
139
  end
140
+
141
+ def test_converting_with_comments
142
+ csv_file = "test/data/test_data_with_comments.csv"
143
+ spanish_file = "fr.lproj/Localizable.strings"
144
+ expected_output = File.read("test/data/test_data_fr_with_comments.strings")
145
+ converter = Babelish::CSV2Strings.new(csv_file,
146
+ {"French" => "fr"},
147
+ :default_lang => "English", :comments_column => 5)
148
+ converter.convert
149
+ assert File.exists?(spanish_file), "the ouptut file does not exist"
150
+ result = File.read(spanish_file)
151
+ assert_equal expected_output, result
152
+ system("rm -rf *.lproj")
153
+ end
140
154
  end
@@ -5,30 +5,30 @@ class TestStrings2CSV < Test::Unit::TestCase
5
5
  input = String.new(<<-EOS)
6
6
  "MY_CONSTANT" = "This is ok";
7
7
  EOS
8
- expected_output = {"MY_CONSTANT"=>"This is ok"}
8
+ expected_output = ["MY_CONSTANT","This is ok"]
9
9
 
10
10
  output = Babelish::Strings2CSV.new.parse_dotstrings_line input
11
- assert_equal output, expected_output
11
+ assert_equal expected_output, output
12
12
  end
13
13
 
14
14
  def test_parse_dotstrings_line_with_single_quote
15
15
  input = String.new(<<-EOS)
16
16
  "MY_CONSTANT" = "This 'is' ok";
17
17
  EOS
18
- expected_output = {"MY_CONSTANT"=>"This 'is' ok"}
18
+ expected_output = ["MY_CONSTANT","This 'is' ok"]
19
19
 
20
20
  output = Babelish::Strings2CSV.new.parse_dotstrings_line input
21
- assert_equal output, expected_output
21
+ assert_equal expected_output, output
22
22
  end
23
23
 
24
24
  def test_parse_dotstrings_line_with_double_quotes
25
25
  input = String.new(<<-EOS)
26
26
  "MY_CONSTANT" = "This "is" ok";
27
27
  EOS
28
- expected_output = {"MY_CONSTANT"=>"This \"is\" ok"}
28
+ expected_output = ["MY_CONSTANT","This \"is\" ok"]
29
29
 
30
30
  output = Babelish::Strings2CSV.new.parse_dotstrings_line input
31
- assert_equal output, expected_output
31
+ assert_equal expected_output, output
32
32
  end
33
33
 
34
34
  def test_parse_dotstrings_line_with_wrong_string
@@ -49,6 +49,12 @@ class TestStrings2CSV < Test::Unit::TestCase
49
49
  assert_nil output, "output should be nil with comment"
50
50
  end
51
51
 
52
+ def test_parse_comment
53
+ comment= "/* this is a comment */"
54
+ output = Babelish::Strings2CSV.new.parse_comment_line comment
55
+ assert_equal "this is a comment", output
56
+ end
57
+
52
58
  def test_load_strings_with_wrong_file
53
59
  assert_raise(Errno::ENOENT) do
54
60
  output = Babelish::Strings2CSV.new.load_strings "file that does not exist.strings"
@@ -56,11 +62,30 @@ class TestStrings2CSV < Test::Unit::TestCase
56
62
  end
57
63
 
58
64
  def test_load_strings
59
- expected_output = {"ERROR_HANDLER_WARNING_DISMISS" => "OK", "ANOTHER_STRING" => "hello"}
65
+ expected_output = [{"ERROR_HANDLER_WARNING_DISMISS" => "OK", "ANOTHER_STRING" => "hello"}, {}]
60
66
  output = Babelish::Strings2CSV.new.load_strings "test/data/test_data.strings"
61
67
  assert_equal expected_output, output
62
68
  end
63
69
 
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
+ },{}]
78
+ output = Babelish::Strings2CSV.new.load_strings "test/data/test_space.strings"
79
+ assert_equal expected_output, output
80
+ end
81
+
82
+ def test_load_strings_with_comments
83
+ expected_output = [{"MY_CONSTANT"=>"This 'is' ok"}, {"MY_CONSTANT"=> "this is a comment"}]
84
+
85
+ output = Babelish::Strings2CSV.new.load_strings "test/data/test_comments.strings"
86
+ assert_equal expected_output, output
87
+ end
88
+
64
89
  def test_load_strings_with_empty_lines
65
90
  assert_nothing_raised do
66
91
  output = Babelish::Strings2CSV.new.load_strings "test/data/test_with_nil.strings"
@@ -120,4 +145,4 @@ class TestStrings2CSV < Test::Unit::TestCase
120
145
  assert_not_nil converter.csv_filename
121
146
  end
122
147
 
123
- end
148
+ end
@@ -83,5 +83,30 @@ class TestXcodeMacros < Test::Unit::TestCase
83
83
  system("rm -f ./Babelish.h")
84
84
  end
85
85
 
86
+ def test_write_macros_with_comments_process
87
+ keys = ["login.title", "login.button"]
88
+ table = "Localizable"
89
+ comments = {"login.title" => "this is the login screen title", "login.button" => nil}
90
+ macros = Babelish::XcodeMacros.new
91
+ macros.process(table, keys, comments)
92
+ macros.write_content("Babelish.h")
93
+ expected_output = String.new(<<-EOS)
94
+ //
95
+ // Babelish.h
96
+ //
97
+ // This file was generated by Babelish
98
+ //
99
+ // https://github.com/netbe/babelish
100
+ //
101
+ #define LS_LOGIN_TITLE NSLocalizedStringFromTable(@"login.title",@"Localizable",@"this is the login screen title")
102
+ #define LS_LOGIN_BUTTON NSLocalizedStringFromTable(@"login.button",@"Localizable",@"")
103
+ EOS
104
+ assert File.exists?("Babelish.h")
105
+ result = File.read("Babelish.h")
106
+ assert_equal expected_output, result
107
+ #clean up
108
+ system("rm -f ./Babelish.h")
109
+ end
110
+
86
111
 
87
112
  end
@@ -0,0 +1,2 @@
1
+ /* this is a comment */
2
+ "MY_CONSTANT" = "This 'is' ok";
@@ -0,0 +1,6 @@
1
+
2
+ /* this is a greeting string */
3
+ "GREETINGS" = "Salut";
4
+
5
+ /* this is another example */
6
+ "ANOTHER_STRING" = "testEN";
@@ -0,0 +1,3 @@
1
+ variables,English,German,French,Spanish,Comments
2
+ GREETINGS,Hello,Hallo,Salut,Buenos dias,this is a greeting string
3
+ ANOTHER_STRING,testEN,,,,this is another example
@@ -0,0 +1,10 @@
1
+ "name"= "definition";
2
+ "name1"="definition1";
3
+ "name2" = "definition2";
4
+ "name3" = "definition3" ;
5
+ "name4" = "definition4";
6
+ "this is a name"="a definition";
7
+ wrong format "should be ignored" = "really" ;
8
+ "should be ignored"wrong format = "really" ;
9
+ "should be ignored"= "really" dd;
10
+ "should be ignored"=aa "really";
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.3.4
4
+ version: 0.4.0
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-03-16 00:00:00.000000000 Z
12
+ date: 2015-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: 0.3.10
34
+ version: 1.0.1
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ~>
40
40
  - !ruby/object:Gem::Version
41
- version: 0.3.10
41
+ version: 1.0.1
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: highline
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -197,15 +197,19 @@ files:
197
197
  - test/data/genstrings.strings
198
198
  - test/data/json.json
199
199
  - test/data/php_lang.php
200
+ - test/data/test_comments.strings
200
201
  - test/data/test_data.csv
201
202
  - test/data/test_data.strings
203
+ - test/data/test_data_fr_with_comments.strings
202
204
  - test/data/test_data_multiple_langs.csv
205
+ - test/data/test_data_with_comments.csv
203
206
  - test/data/test_data_with_percent.csv
204
207
  - test/data/test_data_with_percent_space.csv
205
208
  - test/data/test_data_with_semicolon.csv
206
209
  - test/data/test_data_with_spaces.csv
207
210
  - test/data/test_en.strings
208
211
  - test/data/test_fr.strings
212
+ - test/data/test_space.strings
209
213
  - test/data/test_utf16.strings
210
214
  - test/data/test_with_nil.csv
211
215
  - test/data/test_with_nil.strings
@@ -236,3 +240,4 @@ signing_key:
236
240
  specification_version: 4
237
241
  summary: CSV converter for localization files
238
242
  test_files: []
243
+ has_rdoc: