babelish 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Nzk3MzY5NzE0NzhmMDBiZmFlMmQ2OTJhMzdiZjE4YjFjMDU2YzUwZA==
4
+ NDQ1NTdlNzA0OGNiMjcxMDZjZmE5NTEzNmExY2JlNzZiZTUwYWYwMw==
5
5
  data.tar.gz: !binary |-
6
- MGUxMTM3OGI3OTU4M2I3M2FjYWEwNTRmMDljZjJkZTUxZDQxZDBkNQ==
6
+ MGMyZGE0NTk1MzE4Njc2ZTE2OWY1YjA4MWUwOTU1ZWQ4YTVmOWZmMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzljNjRjMDk4MmEyOGI0MmZjYmUzMGVlYTEwZTBjMzZkZjJjNGU3NWU3NDI1
10
- MjFjNmRhOGRlNmE0NGU5NTU2NjdlOTM0MDZhZDgwNTIyYjE1MzkwODNkMWUx
11
- NGQ2Y2Q5ODhjZGM5ZDkyNjYwMWExOTY0OGU5Y2UxOTQ5NDBiYjI=
9
+ MzgzMmY1ZDM1ZTQ3YmM2NDlhOWI0ZTFhNTYwM2Y1YjNhZWQ2YzNlNGM0ZDcy
10
+ NDI0NjAzNjA5OTkyMjA3MGM5OTU1OGUxZGU2YjdiOTk4YzI5MWVkZTM0Yjcw
11
+ OTI1MDQ1ODFiOGE0ZGEzZWQ4MTI0YTRiYmY4OTQ2Y2M1MzEzYTE=
12
12
  data.tar.gz: !binary |-
13
- NjRiMDk1NDI1Y2M3OTc0OTUzNjA2ODAzNDllZjQ5MGQ2YzQxZTdlZDViNDIx
14
- ZWNiODdlMTY2MzUzNjQ5NjY3ZjBiNmY3MjViZjUwMWE2ZGEzNGI3Y2IyMDI1
15
- MGFhMzhkYzBkNmQxNmU0NzY5OTdmN2YxOTY3NzVkM2RkMGY3ZGM=
13
+ YTYwZjZmNWUzZTlhOTljNDdlN2E4ZjA5Y2Y1ZjgwMGMxY2E2OTIzMDNiYzc1
14
+ ZmE3NWU0OTc3YzRiM2U2NDk1YTM3YzdiYWRiMWE5ZjNiNmZkNTM1MDJlZmZl
15
+ ODI1NWRjMThjNWYxNDIxN2FkMTYyMjE5OWFjMmM3ZGM0MzkyNjI=
data/.babelish.sample CHANGED
@@ -1,6 +1,6 @@
1
1
  # This is a sample configuration file
2
2
 
3
- # Base2CSV
3
+ ###################################### Base2CSV ######################################
4
4
 
5
5
  ## required, location of strings files (FILENAMES)
6
6
  filenames: ["test/data/test_en.strings", "test/data/test_fr.strings"]
@@ -10,7 +10,7 @@ filenames: ["test/data/test_en.strings", "test/data/test_fr.strings"]
10
10
  # csv_filename: "testconfig.csv" # location of output file
11
11
  # dryrun: true # prints out content of hash without writing file
12
12
 
13
- # CSV2Base
13
+ ###################################### CSV2Base ######################################
14
14
 
15
15
  ## required
16
16
  filename: test/data/test_data.csv # CSV file (CSV_FILENAME) to convert from or name of file in Google Drive
@@ -30,3 +30,4 @@ langs: # Languages to convert. i.e. English:en
30
30
  # ignore_lang_path: true # does not care about lang component path. i.e: en.lproj/
31
31
  # sheet: 0 # Index of worksheet to download. First index is 0.
32
32
  # macros_filename: Babelish.h # File to output the defines of localized strings
33
+ # stripping: false # Strips values inside the spreadsheet
data/.travis.yml CHANGED
@@ -9,5 +9,6 @@ deploy:
9
9
  secure: Xjq+v+jEU6wK4BtyfnV1elegNcxK6Ah/O99Sn9c2IlkCmJ1wxLBouqzEiSorSJ4IOMa5H2y3gwo5GXOr6Y7d8huyGrPuBeCSGqAmH77wNCIv7G+jnLiYb1sRZbtKcPW2QaN6JF81qDIelwyspMfo6/ug1qN1x323UaxZl7f7nUE=
10
10
  gem: babelish
11
11
  on:
12
+ tags: true
12
13
  repo: netbe/Babelish
13
14
  all_branches: true
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 = '2014-09-24'
9
+ s.date = '2014-10-29'
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)
@@ -23,6 +23,7 @@ class Commandline < Thor
23
23
  method_option :default_lang, :type => :string, :aliases => "-l", :desc => "Default language to use for empty values if any"
24
24
  method_option :output_dir, :type => :string, :aliases => "-d", :desc => "Path of output files"
25
25
  method_option :output_basenames, :type => :array, :aliases => "-o", :desc => "Basename of output files"
26
+ method_option :stripping, :type => :boolean, :aliases => "-N", :default => false, :desc => "Strips values of spreadsheet"
26
27
  method_option :ignore_lang_path, :type => :boolean, :aliases => "-I", :lazy_default => false, :desc => "Ignore the path component of langs"
27
28
  method_option :fetch, :type => :boolean, :desc => "Download file from Google Drive"
28
29
  method_option :sheet, :type => :numeric, :desc => "Index of worksheet to download. First index is 0"
@@ -34,6 +34,7 @@ module Babelish
34
34
  @keys_column = args[:keys_column]
35
35
  @default_lang = args[:default_lang]
36
36
  @ignore_lang_path = args[:ignore_lang_path]
37
+ @stripping = args[:stripping]
37
38
  @languages = []
38
39
  end
39
40
 
@@ -72,11 +73,9 @@ module Babelish
72
73
  def process_value(row_value, default_value)
73
74
  value = row_value.nil? ? default_value : row_value
74
75
  value = "" if value.nil?
75
- value.gsub!(/\\*\"/, "\\\"") #escape double quotes
76
- value.gsub!(/\s*(\n|\\\s*n)\s*/, "\\n") #replace new lines with \n + strip
77
- value.gsub!(/%\s+([a-zA-Z@])([^a-zA-Z@]|$)/, "%\\1\\2") #repair string formats ("% d points" etc)
78
- value.gsub!(/([^0-9\s\(\{\[^])%/, "\\1 %")
79
- value.strip!
76
+ value.gsub!(/\\*\"/, "\\\"") # escape double quotes
77
+ value.gsub!(/\n/, "\\n") # replace new lines with \n, dont strip
78
+ value.strip! if @stripping
80
79
  return value.to_utf8
81
80
  end
82
81
 
@@ -121,8 +120,8 @@ module Babelish
121
120
  end
122
121
  @languages[i] = language
123
122
  elsif !@state_column || (row[@state_column].nil? || row[@state_column] == '' || !@excluded_states.include?(row[@state_column]))
124
- # TODO: add option to strip the constant or referenced language
125
- key = row[@keys_column].strip
123
+ key = row[@keys_column]
124
+ key.strip! if @stripping
126
125
  default_value = self.default_lang ? row[defaultCol] : nil
127
126
  value = self.process_value(row[i], default_value)
128
127
 
@@ -1,3 +1,3 @@
1
1
  module Babelish
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -15,11 +15,13 @@ module Babelish
15
15
 
16
16
  def process(table, keys)
17
17
  keys.each do |key|
18
- macro_name = "LS_#{key.upcase}"
18
+ clean_key = key.gsub(' ', '')
19
+ clean_key.gsub!(/[[:punct:]]/, '_')
20
+ clean_key.gsub!('__', '_')
21
+ clean_key = clean_key[1..clean_key.size-1] if clean_key[0] == '_'
22
+ clean_key = clean_key[0..clean_key.size-2] if clean_key.size > 1 and clean_key[clean_key.size-1] == '_'
23
+ macro_name = "LS_#{clean_key.upcase}"
19
24
  macro_name += "_#{table.upcase}" if table != "Localizable"
20
- macro_name.gsub!(' ', '')
21
- macro_name.gsub!('.', '_')
22
- macro_name.gsub!('-', '_')
23
25
  @content << String.new(<<-EOS)
24
26
  #define #{macro_name} NSLocalizedStringFromTable(@"#{key}",@"#{table}",@"")
25
27
  EOS
@@ -4,7 +4,7 @@ class TestBins < Test::Unit::TestCase
4
4
  def test_csv2strings_with_google_doc
5
5
  omit if ENV['TRAVIS']
6
6
  assert_nothing_raised do
7
- system("./bin/csv2strings --fetch --filename my_strings --langs English:en")
7
+ system("./bin/babelish csv2strings --fetch --filename my_strings --langs English:en")
8
8
  end
9
9
  assert_equal $?.exitstatus, 0
10
10
  end
@@ -12,7 +12,7 @@ class TestBins < Test::Unit::TestCase
12
12
  def test_csv2strings_with_google_doc_missing_langs
13
13
  omit if ENV['TRAVIS']
14
14
  assert_nothing_raised do
15
- system("./bin/csv2strings --fetch --filename my_strings")
15
+ system("./bin/babelish csv2strings --fetch --filename my_strings")
16
16
  end
17
17
  assert_equal $?.exitstatus, 1
18
18
  end
@@ -21,7 +21,7 @@ class TestBins < Test::Unit::TestCase
21
21
  system("cp .babelish.sample .babelish")
22
22
 
23
23
  assert_nothing_raised NameError do
24
- system("./bin/csv2strings")
24
+ system("./bin/babelish csv2strings")
25
25
  end
26
26
  assert_equal $?.exitstatus, 0
27
27
  end
@@ -85,4 +85,56 @@ class TestCSV2Strings < Test::Unit::TestCase
85
85
  system("rm -rf *.lproj")
86
86
  end
87
87
 
88
+ def test_converting_csv_to_dotstrings_with_percent
89
+ expected_output = String.new(<<-EOS)
90
+ "GREETINGS" = "hello_%@";
91
+ "ANOTHER_STRING" = "hello";
92
+ EOS
93
+ csv_file = "test/data/test_data_with_percent.csv"
94
+ converter = Babelish::CSV2Strings.new(csv_file, "English" => [:en])
95
+ converter.convert
96
+ result = File.read("en.lproj/Localizable.strings")
97
+ assert_equal expected_output, result
98
+ system("rm -rf *.lproj")
99
+ end
100
+
101
+ def test_converting_csv_to_dotstrings_with_spaces
102
+ expected_output = String.new(<<-EOS)
103
+ "GREETINGS " = "hello ";
104
+ "ANOTHER_STRING" = " my other string with space at begin";
105
+ EOS
106
+ csv_file = "test/data/test_data_with_spaces.csv"
107
+ converter = Babelish::CSV2Strings.new(csv_file, "English" => [:en])
108
+ converter.convert
109
+ result = File.read("en.lproj/Localizable.strings")
110
+ assert_equal expected_output, result
111
+ system("rm -rf *.lproj")
112
+ end
113
+
114
+ def test_converting_csv_to_dotstrings_with_percent_space
115
+ expected_output = String.new(<<-EOS)
116
+ "GREETINGS" = "you have %d points";
117
+ "ANOTHER_STRING" = "this is a string with 10% of juice";
118
+ "ANOTHER_EXAMPLE" = "tu as fait 10% d'efforts";
119
+ EOS
120
+ csv_file = "test/data/test_data_with_percent_space.csv"
121
+ converter = Babelish::CSV2Strings.new(csv_file, "English" => [:en])
122
+ converter.convert
123
+ result = File.read("en.lproj/Localizable.strings")
124
+ assert_equal expected_output, result
125
+ system("rm -rf *.lproj")
126
+ end
127
+
128
+ def test_converting_csv_to_dotstrings_with_stripping_option
129
+ expected_output = String.new(<<-EOS)
130
+ "GREETINGS" = "hello";
131
+ "ANOTHER_STRING" = "my other string with space at begin";
132
+ EOS
133
+ csv_file = "test/data/test_data_with_spaces.csv"
134
+ converter = Babelish::CSV2Strings.new(csv_file, {"English" => [:en]}, :stripping => true)
135
+ converter.convert
136
+ result = File.read("en.lproj/Localizable.strings")
137
+ assert_equal expected_output, result
138
+ system("rm -rf *.lproj")
139
+ end
88
140
  end
@@ -57,4 +57,31 @@ class TestXcodeMacros < Test::Unit::TestCase
57
57
  #clean up
58
58
  system("rm -f ./Babelish.h")
59
59
  end
60
+
61
+ def test_write_macros_process_with_special_characters
62
+ keys = ["%d blabla", "login!", "HEY!!"]
63
+ table = "Localizable"
64
+ macros = Babelish::XcodeMacros.new
65
+ macros.process(table, keys)
66
+ macros.write_content("Babelish.h")
67
+ expected_output = String.new(<<-EOS)
68
+ //
69
+ // Babelish.h
70
+ //
71
+ // This file was generated by Babelish
72
+ //
73
+ // https://github.com/netbe/babelish
74
+ //
75
+ #define LS_DBLABLA NSLocalizedStringFromTable(@"%d blabla",@"Localizable",@"")
76
+ #define LS_LOGIN NSLocalizedStringFromTable(@"login!",@"Localizable",@"")
77
+ #define LS_HEY NSLocalizedStringFromTable(@"HEY!!",@"Localizable",@"")
78
+ EOS
79
+ assert File.exists?("Babelish.h")
80
+ result = File.read("Babelish.h")
81
+ assert_equal expected_output, result
82
+ #clean up
83
+ system("rm -f ./Babelish.h")
84
+ end
85
+
86
+
60
87
  end
@@ -0,0 +1,3 @@
1
+ variables,English
2
+ GREETINGS,hello_%@
3
+ ANOTHER_STRING,hello
@@ -0,0 +1,4 @@
1
+ variables,English
2
+ GREETINGS,you have %d points
3
+ ANOTHER_STRING,this is a string with 10% of juice
4
+ ANOTHER_EXAMPLE,tu as fait 10% d'efforts
@@ -0,0 +1,3 @@
1
+ variables,English
2
+ GREETINGS ,hello
3
+ ANOTHER_STRING, my other string with space at begin
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.2
4
+ version: 0.3.3
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: 2014-09-24 00:00:00.000000000 Z
12
+ date: 2014-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -144,15 +144,7 @@ email:
144
144
  - francois.benaiteau@gmail.com
145
145
  - markus.paeschke@gmail.com
146
146
  executables:
147
- - android2csv
148
147
  - babelish
149
- - csv2android
150
- - csv2json
151
- - csv2php
152
- - csv2strings
153
- - json2csv
154
- - php2csv
155
- - strings2csv
156
148
  extensions: []
157
149
  extra_rdoc_files: []
158
150
  files:
@@ -165,15 +157,7 @@ files:
165
157
  - README.md
166
158
  - Rakefile
167
159
  - babelish.gemspec
168
- - bin/android2csv
169
160
  - bin/babelish
170
- - bin/csv2android
171
- - bin/csv2json
172
- - bin/csv2php
173
- - bin/csv2strings
174
- - bin/json2csv
175
- - bin/php2csv
176
- - bin/strings2csv
177
161
  - lib/babelish.rb
178
162
  - lib/babelish/android2csv.rb
179
163
  - lib/babelish/base2csv.rb
@@ -216,6 +200,9 @@ files:
216
200
  - test/data/test_data.csv
217
201
  - test/data/test_data.strings
218
202
  - test/data/test_data_multiple_langs.csv
203
+ - test/data/test_data_with_percent.csv
204
+ - test/data/test_data_with_percent_space.csv
205
+ - test/data/test_data_with_spaces.csv
219
206
  - test/data/test_en.strings
220
207
  - test/data/test_fr.strings
221
208
  - test/data/test_utf16.strings
@@ -243,9 +230,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
230
  version: '0'
244
231
  requirements: []
245
232
  rubyforge_project:
246
- rubygems_version: 2.4.1
233
+ rubygems_version: 2.4.2
247
234
  signing_key:
248
235
  specification_version: 4
249
236
  summary: CSV converter for localization files
250
237
  test_files: []
251
- has_rdoc:
data/bin/android2csv DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
- require 'babelish'
4
- require 'babelish/commandline'
5
-
6
- puts "DEPRECATED: use babelish command"
7
- args = [File.basename(__FILE__)]
8
- if ARGV.first == "help"
9
- args.insert(0, ARGV.first)
10
- ARGV.delete(ARGV.first)
11
- end
12
- args += ARGV
13
- Commandline.start(args)
data/bin/csv2android DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
- require 'babelish'
4
- require 'babelish/commandline'
5
-
6
- puts "DEPRECATED: use babelish command"
7
- args = [File.basename(__FILE__)]
8
- if ARGV.first == "help"
9
- args.insert(0, ARGV.first)
10
- ARGV.delete(ARGV.first)
11
- end
12
- args += ARGV
13
- Commandline.start(args)
data/bin/csv2json DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
- require 'babelish'
4
- require 'babelish/commandline'
5
-
6
- puts "DEPRECATED: use babelish command"
7
- args = [File.basename(__FILE__)]
8
- if ARGV.first == "help"
9
- args.insert(0, ARGV.first)
10
- ARGV.delete(ARGV.first)
11
- end
12
- args += ARGV
13
- Commandline.start(args)
data/bin/csv2php DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
- require 'babelish'
4
- require 'babelish/commandline'
5
-
6
- puts "DEPRECATED: use babelish command"
7
- args = [File.basename(__FILE__)]
8
- if ARGV.first == "help"
9
- args.insert(0, ARGV.first)
10
- ARGV.delete(ARGV.first)
11
- end
12
- args += ARGV
13
- Commandline.start(args)
data/bin/csv2strings DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
-
4
- require 'babelish'
5
- require 'babelish/commandline'
6
-
7
- puts "DEPRECATED: use babelish command"
8
- args = [File.basename(__FILE__)]
9
- if ARGV.first == "help"
10
- args.insert(0, ARGV.first)
11
- ARGV.delete(ARGV.first)
12
- end
13
- args += ARGV
14
- Commandline.start(args)
data/bin/json2csv DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
- require 'babelish'
4
- require 'babelish/commandline'
5
-
6
- puts "DEPRECATED: use babelish command"
7
- args = [File.basename(__FILE__)]
8
- if ARGV.first == "help"
9
- args.insert(0, ARGV.first)
10
- ARGV.delete(ARGV.first)
11
- end
12
- args += ARGV
13
- Commandline.start(args)
data/bin/php2csv DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
- require 'babelish'
4
- require 'babelish/commandline'
5
-
6
- puts "DEPRECATED: use babelish command"
7
- args = [File.basename(__FILE__)]
8
- if ARGV.first == "help"
9
- args.insert(0, ARGV.first)
10
- ARGV.delete(ARGV.first)
11
- end
12
- args += ARGV
13
- Commandline.start(args)
data/bin/strings2csv DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path("../../lib", __FILE__)
3
- require 'babelish'
4
- require 'babelish/commandline'
5
-
6
- puts "DEPRECATED: use babelish command"
7
- args = [File.basename(__FILE__)]
8
- if ARGV.first == "help"
9
- args.insert(0, ARGV.first)
10
- ARGV.delete(ARGV.first)
11
- end
12
- args += ARGV
13
- Commandline.start(args)