babelish 0.3.1 → 0.3.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 +13 -5
- data/.babelish.sample +13 -12
- data/.gitignore +3 -1
- data/.travis.yml +1 -1
- data/babelish.gemspec +3 -3
- data/lib/babelish/commandline.rb +13 -3
- data/lib/babelish/csv2base.rb +17 -3
- data/lib/babelish/csv2strings.rb +7 -4
- data/lib/babelish/google_doc.rb +2 -2
- data/lib/babelish/strings2csv.rb +1 -1
- data/lib/babelish/version.rb +1 -1
- data/lib/babelish/xcode_macros.rb +46 -0
- data/lib/babelish.rb +3 -0
- data/test/babelish/commands/test_command_csv2strings.rb +40 -11
- data/test/babelish/test_csv2strings.rb +67 -0
- data/test/babelish/test_strings2csv.rb +13 -4
- data/test/babelish/test_xcode_macros.rb +60 -0
- metadata +32 -65
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Nzk3MzY5NzE0NzhmMDBiZmFlMmQ2OTJhMzdiZjE4YjFjMDU2YzUwZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGUxMTM3OGI3OTU4M2I3M2FjYWEwNTRmMDljZjJkZTUxZDQxZDBkNQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzljNjRjMDk4MmEyOGI0MmZjYmUzMGVlYTEwZTBjMzZkZjJjNGU3NWU3NDI1
|
10
|
+
MjFjNmRhOGRlNmE0NGU5NTU2NjdlOTM0MDZhZDgwNTIyYjE1MzkwODNkMWUx
|
11
|
+
NGQ2Y2Q5ODhjZGM5ZDkyNjYwMWExOTY0OGU5Y2UxOTQ5NDBiYjI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjRiMDk1NDI1Y2M3OTc0OTUzNjA2ODAzNDllZjQ5MGQ2YzQxZTdlZDViNDIx
|
14
|
+
ZWNiODdlMTY2MzUzNjQ5NjY3ZjBiNmY3MjViZjUwMWE2ZGEzNGI3Y2IyMDI1
|
15
|
+
MGFhMzhkYzBkNmQxNmU0NzY5OTdmN2YxOTY3NzVkM2RkMGY3ZGM=
|
data/.babelish.sample
CHANGED
@@ -13,19 +13,20 @@ filenames: ["test/data/test_en.strings", "test/data/test_fr.strings"]
|
|
13
13
|
# CSV2Base
|
14
14
|
|
15
15
|
## required
|
16
|
-
filename: test/data/test_data.csv
|
17
|
-
langs:
|
16
|
+
filename: test/data/test_data.csv # CSV file (CSV_FILENAME) to convert from or name of file in Google Drive
|
17
|
+
langs: # Languages to convert. i.e. English:en
|
18
18
|
English: "en"
|
19
19
|
|
20
20
|
## optional
|
21
21
|
# fetch: true # set to true to get file(filename) from google drive
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
22
|
+
# excluded_states: ["Images", "Xib"] # Exclude rows with given state
|
23
|
+
# state_column: 3 # Position of column for state if any
|
24
|
+
# keys_column: 0 # Position of column for keys
|
25
|
+
# default_lang: "English" # Header name of column containing fallback value if value is empty
|
26
|
+
# output_dir: "resources/" # Path of output files
|
27
|
+
# output_basenames: # Basename of output files
|
28
|
+
# - Localizable
|
29
|
+
# - info
|
30
|
+
# ignore_lang_path: true # does not care about lang component path. i.e: en.lproj/
|
31
|
+
# sheet: 0 # Index of worksheet to download. First index is 0.
|
32
|
+
# macros_filename: Babelish.h # File to output the defines of localized strings
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -9,5 +9,5 @@ deploy:
|
|
9
9
|
secure: Xjq+v+jEU6wK4BtyfnV1elegNcxK6Ah/O99Sn9c2IlkCmJ1wxLBouqzEiSorSJ4IOMa5H2y3gwo5GXOr6Y7d8huyGrPuBeCSGqAmH77wNCIv7G+jnLiYb1sRZbtKcPW2QaN6JF81qDIelwyspMfo6/ug1qN1x323UaxZl7f7nUE=
|
10
10
|
gem: babelish
|
11
11
|
on:
|
12
|
-
tags: true
|
13
12
|
repo: netbe/Babelish
|
13
|
+
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-
|
9
|
+
s.date = '2014-09-24'
|
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)
|
@@ -15,12 +15,12 @@ Gem::Specification.new do |s|
|
|
15
15
|
- .php"
|
16
16
|
s.authors = ["François Benaiteau", "Markus Paeschke"]
|
17
17
|
s.email = ['francois.benaiteau@gmail.com', 'markus.paeschke@gmail.com']
|
18
|
-
s.homepage = '
|
18
|
+
s.homepage = 'http://netbe.github.io/Babelish/'
|
19
19
|
s.license = 'MIT'
|
20
20
|
|
21
21
|
s.add_dependency "thor"
|
22
22
|
|
23
|
-
s.add_dependency "google_drive"
|
23
|
+
s.add_dependency "google_drive", "~> 0.3.10"
|
24
24
|
# google_drive dependency to ask for mail and password
|
25
25
|
s.add_dependency "highline"
|
26
26
|
|
data/lib/babelish/commandline.rb
CHANGED
@@ -23,8 +23,12 @@ 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 :ignore_lang_path, :type => :boolean, :aliases => "-I", :
|
26
|
+
method_option :ignore_lang_path, :type => :boolean, :aliases => "-I", :lazy_default => false, :desc => "Ignore the path component of langs"
|
27
27
|
method_option :fetch, :type => :boolean, :desc => "Download file from Google Drive"
|
28
|
+
method_option :sheet, :type => :numeric, :desc => "Index of worksheet to download. First index is 0"
|
29
|
+
if klass[:name] == "CSV2Strings"
|
30
|
+
method_option :macros_filename, :type => :boolean, :aliases => "-m", :lazy_default => false, :desc => "Filename containing defines of localized keys"
|
31
|
+
end
|
28
32
|
define_method("#{klass[:name].downcase}") do
|
29
33
|
csv2base(klass[:name])
|
30
34
|
end
|
@@ -93,7 +97,7 @@ class Commandline < Thor
|
|
93
97
|
files = [file_path].compact
|
94
98
|
else
|
95
99
|
files = gd.download filename.to_s
|
96
|
-
file_path = files.join("\n")
|
100
|
+
file_path = files.join("\n") unless files.empty?
|
97
101
|
end
|
98
102
|
|
99
103
|
if file_path
|
@@ -108,7 +112,7 @@ class Commandline < Thor
|
|
108
112
|
args = options.dup
|
109
113
|
if options[:fetch]
|
110
114
|
say "Fetching csv file #{options[:filename]} from Google Drive"
|
111
|
-
files = download(options[:filename])
|
115
|
+
files = download(options[:filename], nil, options[:sheet])
|
112
116
|
abort if files.empty? # no file downloaded
|
113
117
|
args.delete(:fetch)
|
114
118
|
else
|
@@ -117,6 +121,7 @@ class Commandline < Thor
|
|
117
121
|
args.delete(:langs)
|
118
122
|
args.delete(:filename)
|
119
123
|
|
124
|
+
xcode_macros = Babelish::XcodeMacros.new if options[:macros_filename]
|
120
125
|
files.each_with_index do |filename, index|
|
121
126
|
if options[:output_basenames]
|
122
127
|
args[:output_basename] = options[:output_basenames][index]
|
@@ -126,6 +131,11 @@ class Commandline < Thor
|
|
126
131
|
args = Thor::CoreExt::HashWithIndifferentAccess.new(args)
|
127
132
|
converter = class_object.new(filename, options[:langs], args)
|
128
133
|
say converter.convert
|
134
|
+
xcode_macros.process(converter.table, converter.keys) if options[:macros_filename]
|
135
|
+
end
|
136
|
+
if options[:macros_filename]
|
137
|
+
say "generating macros"
|
138
|
+
xcode_macros.write_content(options[:macros_filename])
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
data/lib/babelish/csv2base.rb
CHANGED
@@ -43,6 +43,18 @@ module Babelish
|
|
43
43
|
return File.new(file_path, "w")
|
44
44
|
end
|
45
45
|
|
46
|
+
def keys
|
47
|
+
@languages.each do |lang|
|
48
|
+
next unless lang
|
49
|
+
return lang.content.keys unless lang.content.keys.empty?
|
50
|
+
end
|
51
|
+
return []
|
52
|
+
end
|
53
|
+
|
54
|
+
def table
|
55
|
+
output_basename
|
56
|
+
end
|
57
|
+
|
46
58
|
def language_filepaths(language)
|
47
59
|
#implement in subclass
|
48
60
|
[]
|
@@ -54,7 +66,7 @@ module Babelish
|
|
54
66
|
end
|
55
67
|
|
56
68
|
def default_filepath
|
57
|
-
Pathname.new(@output_dir) + "#{
|
69
|
+
Pathname.new(@output_dir) + "#{output_basename}.#{extension}"
|
58
70
|
end
|
59
71
|
|
60
72
|
def process_value(row_value, default_value)
|
@@ -94,10 +106,11 @@ module Babelish
|
|
94
106
|
|
95
107
|
#header
|
96
108
|
if rowIndex == 0
|
109
|
+
# defaultCol can be the keyValue
|
110
|
+
defaultCol = i if self.default_lang == row[i]
|
97
111
|
# ignore all headers not listed in langs to create files
|
98
112
|
(excludedCols << i and next) unless @langs.has_key?(row[i])
|
99
113
|
|
100
|
-
defaultCol = i if self.default_lang == row[i]
|
101
114
|
language = Language.new(row[i])
|
102
115
|
if @langs[row[i]].is_a?(Array)
|
103
116
|
@langs[row[i]].each do |id|
|
@@ -110,7 +123,8 @@ module Babelish
|
|
110
123
|
elsif !@state_column || (row[@state_column].nil? || row[@state_column] == '' || !@excluded_states.include?(row[@state_column]))
|
111
124
|
# TODO: add option to strip the constant or referenced language
|
112
125
|
key = row[@keys_column].strip
|
113
|
-
|
126
|
+
default_value = self.default_lang ? row[defaultCol] : nil
|
127
|
+
value = self.process_value(row[i], default_value)
|
114
128
|
|
115
129
|
@languages[i].add_content_pair(key, value)
|
116
130
|
end
|
data/lib/babelish/csv2strings.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
module Babelish
|
2
2
|
class CSV2Strings < Csv2Base
|
3
|
+
attr_accessor :languages
|
3
4
|
|
4
5
|
def language_filepaths(language)
|
5
6
|
require 'pathname'
|
6
7
|
filepaths = []
|
7
|
-
filename = @output_basename || 'Localizable'
|
8
|
-
|
9
8
|
if language.regions.empty?
|
10
|
-
filepaths << Pathname.new(@output_dir) + "#{language.code}.lproj/#{
|
9
|
+
filepaths << Pathname.new(@output_dir) + "#{language.code}.lproj/#{output_basename}.#{extension}"
|
11
10
|
else
|
12
11
|
language.regions.each do |region|
|
13
|
-
filepaths << Pathname.new(@output_dir) + "#{language.code}-#{region}.lproj/#{
|
12
|
+
filepaths << Pathname.new(@output_dir) + "#{language.code}-#{region}.lproj/#{output_basename}.#{extension}"
|
14
13
|
end
|
15
14
|
end
|
16
15
|
filepaths
|
@@ -23,5 +22,9 @@ module Babelish
|
|
23
22
|
def extension
|
24
23
|
"strings"
|
25
24
|
end
|
25
|
+
|
26
|
+
def output_basename
|
27
|
+
@output_basename || 'Localizable'
|
28
|
+
end
|
26
29
|
end
|
27
30
|
end
|
data/lib/babelish/google_doc.rb
CHANGED
@@ -40,8 +40,8 @@ module Babelish
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def authenticate
|
43
|
-
# will try to get token
|
44
|
-
@session = GoogleDrive.saved_session
|
43
|
+
# will try to get token and store in file below
|
44
|
+
@session = GoogleDrive.saved_session ".babelish.token"
|
45
45
|
end
|
46
46
|
|
47
47
|
def file_with_name(name)
|
data/lib/babelish/strings2csv.rb
CHANGED
@@ -10,7 +10,7 @@ module Babelish
|
|
10
10
|
|
11
11
|
def parse_dotstrings_line(line)
|
12
12
|
line.strip!
|
13
|
-
if line[0] != ?# && line[0] != ?=
|
13
|
+
if line[0] != ?# && line[0] != ?= && line[0] != ?/
|
14
14
|
m = line.match(/^[^\"]*\"(.+)\"[^=]+=[^\"]*\"(.*)\";/)
|
15
15
|
return {m[1] => m[2]} unless m.nil?
|
16
16
|
end
|
data/lib/babelish/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Babelish
|
2
|
+
class XcodeMacros
|
3
|
+
attr_accessor :content, :table, :keys
|
4
|
+
def initialize(table = "Localizable", keys = {})
|
5
|
+
@content = ""
|
6
|
+
@table = table
|
7
|
+
@keys = keys
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.write_macros(file_path, table, keys)
|
11
|
+
instance = XcodeMacros.new
|
12
|
+
instance.process(table, keys)
|
13
|
+
instance.write_content(file_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def process(table, keys)
|
17
|
+
keys.each do |key|
|
18
|
+
macro_name = "LS_#{key.upcase}"
|
19
|
+
macro_name += "_#{table.upcase}" if table != "Localizable"
|
20
|
+
macro_name.gsub!(' ', '')
|
21
|
+
macro_name.gsub!('.', '_')
|
22
|
+
macro_name.gsub!('-', '_')
|
23
|
+
@content << String.new(<<-EOS)
|
24
|
+
#define #{macro_name} NSLocalizedStringFromTable(@"#{key}",@"#{table}",@"")
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
@content
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_content(file_path)
|
31
|
+
header = String.new(<<-EOS)
|
32
|
+
//
|
33
|
+
// file_path
|
34
|
+
//
|
35
|
+
// This file was generated by Babelish
|
36
|
+
//
|
37
|
+
// https://github.com/netbe/babelish
|
38
|
+
//
|
39
|
+
EOS
|
40
|
+
header.gsub! "file_path", File.basename(file_path)
|
41
|
+
file = File.new(file_path, "w")
|
42
|
+
file.write header + @content
|
43
|
+
file.close
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/babelish.rb
CHANGED
@@ -11,7 +11,7 @@ class TestCSV2StringsCommand < Test::Unit::TestCase
|
|
11
11
|
assert File.exist?("./en.lproj/Localizable.strings")
|
12
12
|
assert File.exist?("./fr.lproj/Localizable.strings")
|
13
13
|
|
14
|
-
#clean up
|
14
|
+
# clean up
|
15
15
|
system("rm -rf ./en.lproj/")
|
16
16
|
system("rm -rf ./fr.lproj/")
|
17
17
|
end
|
@@ -28,7 +28,7 @@ class TestCSV2StringsCommand < Test::Unit::TestCase
|
|
28
28
|
assert File.exist?("./mynewlocation/en.lproj/Localizable.strings"), "can't find output file for English in mynewlocation folder"
|
29
29
|
assert File.exist?("./mynewlocation/fr.lproj/Localizable.strings"), "can't find output file for French in mynewlocation folder"
|
30
30
|
|
31
|
-
#clean up
|
31
|
+
# clean up
|
32
32
|
system("rm -rf ./mynewlocation")
|
33
33
|
end
|
34
34
|
|
@@ -43,7 +43,7 @@ class TestCSV2StringsCommand < Test::Unit::TestCase
|
|
43
43
|
Commandline.new([], options).csv2strings
|
44
44
|
end
|
45
45
|
|
46
|
-
#clean up
|
46
|
+
# clean up
|
47
47
|
system("rm -rf ./en.lproj/")
|
48
48
|
system("rm -rf ./fr.lproj/")
|
49
49
|
end
|
@@ -55,7 +55,7 @@ class TestCSV2StringsCommand < Test::Unit::TestCase
|
|
55
55
|
Commandline.new.csv2strings
|
56
56
|
end
|
57
57
|
|
58
|
-
#clean up
|
58
|
+
# clean up
|
59
59
|
system("rm -rf ./en.lproj/")
|
60
60
|
system("rm -rf ./fr.lproj/")
|
61
61
|
end
|
@@ -76,7 +76,7 @@ class TestCSV2StringsCommand < Test::Unit::TestCase
|
|
76
76
|
assert File.exist?("./en.lproj/sheet2.strings"), "can't find output file for sheet2 English"
|
77
77
|
assert File.exist?("./fr.lproj/sheet2.strings"), "can't find output file for sheet2 French"
|
78
78
|
|
79
|
-
#clean up
|
79
|
+
# clean up
|
80
80
|
system("rm -rf ./en.lproj/")
|
81
81
|
system("rm -rf ./fr.lproj/")
|
82
82
|
end
|
@@ -85,7 +85,7 @@ class TestCSV2StringsCommand < Test::Unit::TestCase
|
|
85
85
|
omit if ENV['TRAVIS']
|
86
86
|
options = {
|
87
87
|
:filename => "my_strings",
|
88
|
-
:langs => {"English" => "en"
|
88
|
+
:langs => {"English" => "en"},
|
89
89
|
:fetch => true,
|
90
90
|
:ignore_lang_path => true,
|
91
91
|
:output_basenames => %w(sheet1 sheet2),
|
@@ -94,13 +94,42 @@ class TestCSV2StringsCommand < Test::Unit::TestCase
|
|
94
94
|
Commandline.new([], options).csv2strings
|
95
95
|
# testing
|
96
96
|
assert File.exist?("./sheet1.strings"), "can't find output file for sheet1 English with_ignore_lang_path_option"
|
97
|
-
assert File.exist?("./sheet1.strings"), "can't find output file for sheet1 French with_ignore_lang_path_option"
|
98
97
|
assert File.exist?("./sheet2.strings"), "can't find output file for sheet2 English with_ignore_lang_path_option"
|
99
|
-
assert File.exist?("./sheet2.strings"), "can't find output file for sheet2 French with_ignore_lang_path_option"
|
100
98
|
|
101
|
-
#clean up
|
102
|
-
system("rm -
|
103
|
-
system("rm -
|
99
|
+
# clean up
|
100
|
+
system("rm -f sheet1.strings")
|
101
|
+
system("rm -f sheet2.strings")
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_csv2strings_with_ignore_lang_path_option_local
|
105
|
+
options = {
|
106
|
+
:filename => "test/data/test_data.csv",
|
107
|
+
:langs => {"English" => "en"},
|
108
|
+
:ignore_lang_path => true,
|
109
|
+
}
|
110
|
+
|
111
|
+
Commandline.new([], options).csv2strings
|
112
|
+
# testing
|
113
|
+
assert File.exist?("./Localizable.strings"), "can't find output file for English with_ignore_lang_path_option"
|
114
|
+
|
115
|
+
# clean up
|
116
|
+
system("rm -f ./Localizable.strings")
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_csv2string_with_macros_filename
|
120
|
+
options = {
|
121
|
+
:filename => "test/data/test_data.csv",
|
122
|
+
:macros_filename => "Babelish.h",
|
123
|
+
:langs => { "English" => "en" }
|
124
|
+
}
|
125
|
+
|
126
|
+
Commandline.new([], options).csv2strings
|
127
|
+
# testing
|
128
|
+
assert File.exist?("./Babelish.h"), "can't find macros file"
|
129
|
+
|
130
|
+
# clean up
|
131
|
+
system("rm -f ./Localizable.strings")
|
132
|
+
system("rm -f ./Babelish.h")
|
104
133
|
end
|
105
134
|
|
106
135
|
def teardown
|
@@ -6,6 +6,7 @@ class TestCSV2Strings < Test::Unit::TestCase
|
|
6
6
|
converter = Babelish::CSV2Strings.new(csv_file, 'English' => [:en])
|
7
7
|
converter.convert
|
8
8
|
assert File.exists?("en.lproj/Localizable.strings"), "the ouptut file does not exist"
|
9
|
+
system("rm -rf en.lproj/")
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_converting_csv_to_dotstrings_one_output_option
|
@@ -17,5 +18,71 @@ class TestCSV2Strings < Test::Unit::TestCase
|
|
17
18
|
:ignore_lang_path => true)
|
18
19
|
converter.convert
|
19
20
|
assert File.exists?(single_file), "the ouptut file does not exist"
|
21
|
+
system("rm -f #{single_file}")
|
20
22
|
end
|
23
|
+
|
24
|
+
def test_converting_csv_to_dotstrings_default_lang
|
25
|
+
expected_output = String.new(<<-EOS)
|
26
|
+
"GREETINGS" = "Buenos dias";
|
27
|
+
"ANOTHER_STRING" = "testEN";
|
28
|
+
EOS
|
29
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
30
|
+
spanish_file = "es.lproj/Localizable.strings"
|
31
|
+
converter = Babelish::CSV2Strings.new(csv_file,
|
32
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"},
|
33
|
+
:default_lang => "English")
|
34
|
+
converter.convert
|
35
|
+
assert File.exists?(spanish_file), "the ouptut file does not exist"
|
36
|
+
result = File.read(spanish_file)
|
37
|
+
assert_equal expected_output, result
|
38
|
+
system("rm -rf *.lproj")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_converting_csv_to_dotstrings_with_no_default_lang_is_empty
|
42
|
+
expected_output = String.new(<<-EOS)
|
43
|
+
"GREETINGS" = "Buenos dias";
|
44
|
+
"ANOTHER_STRING" = "";
|
45
|
+
EOS
|
46
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
47
|
+
spanish_file = "es.lproj/Localizable.strings"
|
48
|
+
converter = Babelish::CSV2Strings.new(csv_file,
|
49
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"})
|
50
|
+
converter.convert
|
51
|
+
assert File.exists?(spanish_file), "the ouptut file does not exist"
|
52
|
+
result = File.read(spanish_file)
|
53
|
+
assert_equal expected_output, result
|
54
|
+
system("rm -rf *.lproj")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_converting_csv_to_dotstrings_default_lang_to_key
|
58
|
+
expected_output = String.new(<<-EOS)
|
59
|
+
"GREETINGS" = "Buenos dias";
|
60
|
+
"ANOTHER_STRING" = "ANOTHER_STRING";
|
61
|
+
EOS
|
62
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
63
|
+
spanish_file = "es.lproj/Localizable.strings"
|
64
|
+
converter = Babelish::CSV2Strings.new(csv_file,
|
65
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"},
|
66
|
+
:default_lang => "variables")
|
67
|
+
converter.convert
|
68
|
+
assert File.exists?(spanish_file), "the ouptut file does not exist"
|
69
|
+
result = File.read(spanish_file)
|
70
|
+
assert_equal expected_output, result
|
71
|
+
system("rm -rf *.lproj")
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_converting_csv_to_dotstrings_keys
|
75
|
+
expected_output = String.new(<<-EOS)
|
76
|
+
"GREETINGS" = "Buenos dias";
|
77
|
+
"ANOTHER_STRING" = "ANOTHER_STRING";
|
78
|
+
EOS
|
79
|
+
csv_file = "test/data/test_data_multiple_langs.csv"
|
80
|
+
converter = Babelish::CSV2Strings.new(csv_file,
|
81
|
+
{'English' => [:en], "French" => "fr", "German" => "de", "Spanish" => "es"},
|
82
|
+
:default_lang => "variables")
|
83
|
+
converter.convert
|
84
|
+
assert !converter.keys.empty?
|
85
|
+
system("rm -rf *.lproj")
|
86
|
+
end
|
87
|
+
|
21
88
|
end
|
@@ -40,6 +40,15 @@ class TestStrings2CSV < Test::Unit::TestCase
|
|
40
40
|
assert_nil output, "output should be nil with wrong syntax"
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_parse_dotstrings_line_with_comment
|
44
|
+
input = String.new(<<-EOS)
|
45
|
+
/* Class = "IBUIButton"; normalTitle = "Wibble"; ObjectID = "xxx-xx-123"; */
|
46
|
+
EOS
|
47
|
+
|
48
|
+
output = Babelish::Strings2CSV.new.parse_dotstrings_line input
|
49
|
+
assert_nil output, "output should be nil with comment"
|
50
|
+
end
|
51
|
+
|
43
52
|
def test_load_strings_with_wrong_file
|
44
53
|
assert_raise(Errno::ENOENT) do
|
45
54
|
output = Babelish::Strings2CSV.new.load_strings "file that does not exist.strings"
|
@@ -106,9 +115,9 @@ class TestStrings2CSV < Test::Unit::TestCase
|
|
106
115
|
assert_equal filenames, converter.filenames
|
107
116
|
end
|
108
117
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
118
|
+
def test_initialize_with_default_values
|
119
|
+
converter = Babelish::Strings2CSV.new
|
120
|
+
assert_not_nil converter.csv_filename
|
121
|
+
end
|
113
122
|
|
114
123
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
class TestXcodeMacros < Test::Unit::TestCase
|
3
|
+
def test_process
|
4
|
+
keys = ["login.title", "login.button"]
|
5
|
+
table = "Localizable"
|
6
|
+
xcode_macros = Babelish::XcodeMacros.new
|
7
|
+
content = xcode_macros.process(table, keys)
|
8
|
+
expected_output = String.new(<<-EOS)
|
9
|
+
#define LS_LOGIN_TITLE NSLocalizedStringFromTable(@"login.title",@"Localizable",@"")
|
10
|
+
#define LS_LOGIN_BUTTON NSLocalizedStringFromTable(@"login.button",@"Localizable",@"")
|
11
|
+
EOS
|
12
|
+
assert_equal expected_output, content
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_write_macros_class_method
|
16
|
+
keys = ["login.title", "login.button"]
|
17
|
+
table = "Localizable"
|
18
|
+
Babelish::XcodeMacros.write_macros("Babelish.h", table, keys)
|
19
|
+
expected_output = String.new(<<-EOS)
|
20
|
+
//
|
21
|
+
// Babelish.h
|
22
|
+
//
|
23
|
+
// This file was generated by Babelish
|
24
|
+
//
|
25
|
+
// https://github.com/netbe/babelish
|
26
|
+
//
|
27
|
+
#define LS_LOGIN_TITLE NSLocalizedStringFromTable(@"login.title",@"Localizable",@"")
|
28
|
+
#define LS_LOGIN_BUTTON NSLocalizedStringFromTable(@"login.button",@"Localizable",@"")
|
29
|
+
EOS
|
30
|
+
assert File.exists?("Babelish.h")
|
31
|
+
result = File.read("Babelish.h")
|
32
|
+
assert_equal expected_output, result
|
33
|
+
#clean up
|
34
|
+
system("rm -f ./Babelish.h")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_write_macros_process
|
38
|
+
keys = ["login.title", "login.button"]
|
39
|
+
table = "Localizable"
|
40
|
+
macros = Babelish::XcodeMacros.new
|
41
|
+
macros.process(table, keys)
|
42
|
+
macros.write_content("Babelish.h")
|
43
|
+
expected_output = String.new(<<-EOS)
|
44
|
+
//
|
45
|
+
// Babelish.h
|
46
|
+
//
|
47
|
+
// This file was generated by Babelish
|
48
|
+
//
|
49
|
+
// https://github.com/netbe/babelish
|
50
|
+
//
|
51
|
+
#define LS_LOGIN_TITLE NSLocalizedStringFromTable(@"login.title",@"Localizable",@"")
|
52
|
+
#define LS_LOGIN_BUTTON NSLocalizedStringFromTable(@"login.button",@"Localizable",@"")
|
53
|
+
EOS
|
54
|
+
assert File.exists?("Babelish.h")
|
55
|
+
result = File.read("Babelish.h")
|
56
|
+
assert_equal expected_output, result
|
57
|
+
#clean up
|
58
|
+
system("rm -f ./Babelish.h")
|
59
|
+
end
|
60
|
+
end
|
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
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- François Benaiteau
|
@@ -9,140 +9,137 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - '>='
|
18
|
+
- - ! '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - '>='
|
25
|
+
- - ! '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: google_drive
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 0.3.10
|
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:
|
41
|
+
version: 0.3.10
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: highline
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - '>='
|
46
|
+
- - ! '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - '>='
|
53
|
+
- - ! '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: xml-simple
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - '>='
|
60
|
+
- - ! '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - '>='
|
67
|
+
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: json
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - '>='
|
74
|
+
- - ! '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - '>='
|
81
|
+
- - ! '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rake
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - '>='
|
88
|
+
- - ! '>='
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - '>='
|
95
|
+
- - ! '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: test-unit
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - '>='
|
102
|
+
- - ! '>='
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - '>='
|
109
|
+
- - ! '>='
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: simplecov
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - '>='
|
116
|
+
- - ! '>='
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - '>='
|
123
|
+
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: yard
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- - '>='
|
130
|
+
- - ! '>='
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- - '>='
|
137
|
+
- - ! '>='
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
|
-
description:
|
141
|
-
|
142
|
-
|
143
|
-
- .xml (Android)
|
144
|
-
- .json
|
145
|
-
- .php
|
140
|
+
description: ! "This set of commands converts a CSV file to the following formats:\n
|
141
|
+
\ - .strings (iOS)\n - .xml (Android)\n -
|
142
|
+
.json\n - .php"
|
146
143
|
email:
|
147
144
|
- francois.benaiteau@gmail.com
|
148
145
|
- markus.paeschke@gmail.com
|
@@ -192,6 +189,7 @@ files:
|
|
192
189
|
- lib/babelish/php2csv.rb
|
193
190
|
- lib/babelish/strings2csv.rb
|
194
191
|
- lib/babelish/version.rb
|
192
|
+
- lib/babelish/xcode_macros.rb
|
195
193
|
- test/babelish/commands/test_command_android2csv.rb
|
196
194
|
- test/babelish/commands/test_command_csv2android.rb
|
197
195
|
- test/babelish/commands/test_command_csv2strings.rb
|
@@ -208,6 +206,7 @@ files:
|
|
208
206
|
- test/babelish/test_json2csv.rb
|
209
207
|
- test/babelish/test_php2csv.rb
|
210
208
|
- test/babelish/test_strings2csv.rb
|
209
|
+
- test/babelish/test_xcode_macros.rb
|
211
210
|
- test/data/android-en.xml
|
212
211
|
- test/data/android-fr.xml
|
213
212
|
- test/data/android.xml
|
@@ -224,7 +223,7 @@ files:
|
|
224
223
|
- test/data/test_with_nil.strings
|
225
224
|
- test/data/xcode_empty.strings
|
226
225
|
- test/test_helper.rb
|
227
|
-
homepage:
|
226
|
+
homepage: http://netbe.github.io/Babelish/
|
228
227
|
licenses:
|
229
228
|
- MIT
|
230
229
|
metadata: {}
|
@@ -234,51 +233,19 @@ require_paths:
|
|
234
233
|
- lib
|
235
234
|
required_ruby_version: !ruby/object:Gem::Requirement
|
236
235
|
requirements:
|
237
|
-
- - '>='
|
236
|
+
- - ! '>='
|
238
237
|
- !ruby/object:Gem::Version
|
239
238
|
version: '0'
|
240
239
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
240
|
requirements:
|
242
|
-
- - '>='
|
241
|
+
- - ! '>='
|
243
242
|
- !ruby/object:Gem::Version
|
244
243
|
version: '0'
|
245
244
|
requirements: []
|
246
245
|
rubyforge_project:
|
247
|
-
rubygems_version: 2.
|
246
|
+
rubygems_version: 2.4.1
|
248
247
|
signing_key:
|
249
248
|
specification_version: 4
|
250
249
|
summary: CSV converter for localization files
|
251
|
-
test_files:
|
252
|
-
- test/babelish/commands/test_command_android2csv.rb
|
253
|
-
- test/babelish/commands/test_command_csv2android.rb
|
254
|
-
- test/babelish/commands/test_command_csv2strings.rb
|
255
|
-
- test/babelish/commands/test_command_strings2csv.rb
|
256
|
-
- test/babelish/test_android2csv.rb
|
257
|
-
- test/babelish/test_base2csv.rb
|
258
|
-
- test/babelish/test_bins.rb
|
259
|
-
- test/babelish/test_commandline.rb
|
260
|
-
- test/babelish/test_csv2android.rb
|
261
|
-
- test/babelish/test_csv2base.rb
|
262
|
-
- test/babelish/test_csv2json.rb
|
263
|
-
- test/babelish/test_csv2php.rb
|
264
|
-
- test/babelish/test_csv2strings.rb
|
265
|
-
- test/babelish/test_json2csv.rb
|
266
|
-
- test/babelish/test_php2csv.rb
|
267
|
-
- test/babelish/test_strings2csv.rb
|
268
|
-
- test/data/android-en.xml
|
269
|
-
- test/data/android-fr.xml
|
270
|
-
- test/data/android.xml
|
271
|
-
- test/data/genstrings.strings
|
272
|
-
- test/data/json.json
|
273
|
-
- test/data/php_lang.php
|
274
|
-
- test/data/test_data.csv
|
275
|
-
- test/data/test_data.strings
|
276
|
-
- test/data/test_data_multiple_langs.csv
|
277
|
-
- test/data/test_en.strings
|
278
|
-
- test/data/test_fr.strings
|
279
|
-
- test/data/test_utf16.strings
|
280
|
-
- test/data/test_with_nil.csv
|
281
|
-
- test/data/test_with_nil.strings
|
282
|
-
- test/data/xcode_empty.strings
|
283
|
-
- test/test_helper.rb
|
250
|
+
test_files: []
|
284
251
|
has_rdoc:
|