locgen 0.0.2 → 0.0.3
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 +4 -4
- data/bin/locgen +2 -1
- data/lib/LocGen.rb +24 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ce50a6e53535efebef12e0b3de6d7da0adeaed2
|
4
|
+
data.tar.gz: 8923910802d71841f1d76e45c29ba09d2359036c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd9f449e3e16928a48746d002173cac4c2a7db6e8d37e1110b5fa0d0041cb891682a544384f1ea1ea9eff6ddbdd9b1249ddb69ac00f97e8ce7415d6d8ff857e2
|
7
|
+
data.tar.gz: cf8d2c9993f2c2319631e68daa3f9021c2758e2d6d64df34904b69c32046de8537a9201d5b1c2e9f7dd14a50b279f13f8c25443769dd2be7323fdb905c5135f4
|
data/bin/locgen
CHANGED
@@ -13,9 +13,10 @@ OptionParser.new do |opts|
|
|
13
13
|
opts.on('-o', '--output DIR', 'Output directory path') { |v| options[:output] = v }
|
14
14
|
opts.on('-c', '--comment_col NAME', 'Comments column name (default: comment)') { |v| options[:comment] = v }
|
15
15
|
opts.on('-k', '--key_col NAME', 'Keys column name (default: key)') { |v| options[:key] = v }
|
16
|
+
opts.on('-b', '--base_lang NAME', 'Language identifier to generate Base.lproj localizable file (default: first lang column on the left)') { |v| options[:baselang] = v }
|
16
17
|
|
17
18
|
end.parse!
|
18
19
|
|
19
20
|
|
20
|
-
gen = LocGen.new(options[:url],options[:output],options[:comment],options[:key])
|
21
|
+
gen = LocGen.new(options[:url],options[:output],options[:comment],options[:key], options[:baselang])
|
21
22
|
gen.process()
|
data/lib/LocGen.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'rubyXL' # need install
|
2
2
|
require 'iso-639' # need install
|
3
3
|
require 'open-uri'
|
4
|
-
require 'yaml'
|
5
4
|
|
6
5
|
class LocGen
|
7
6
|
TEMPORARY_SHEET_FILE = "temp_loc_sheet.xlsx"
|
8
7
|
OUTPUT_FILE_NAME = "Localizable.strings"
|
9
8
|
LOCAL_INDEX_KEY = "localIndex"
|
10
9
|
SHEET_INDEX_KEY = "sheetIndex"
|
11
|
-
|
10
|
+
LANG_KEY = "lang"
|
12
11
|
|
13
|
-
def initialize(url, outputDir, comment, key)
|
12
|
+
def initialize(url, outputDir, comment, key, baselang)
|
14
13
|
@url = url
|
15
14
|
@outputDir = outputDir
|
16
15
|
@commentColumnName = comment || "comment"
|
17
16
|
@keyColumnName = key || "key"
|
17
|
+
@baseLang = baselang
|
18
18
|
end
|
19
19
|
|
20
20
|
def process()
|
@@ -24,6 +24,7 @@ class LocGen
|
|
24
24
|
prepareIndices()
|
25
25
|
readLocalizations()
|
26
26
|
writeFiles(@outputDir, OUTPUT_FILE_NAME)
|
27
|
+
writeBaseLocalizable(@outputDir, OUTPUT_FILE_NAME)
|
27
28
|
deleteTempFile(TEMPORARY_SHEET_FILE)
|
28
29
|
end
|
29
30
|
end
|
@@ -68,7 +69,7 @@ class LocGen
|
|
68
69
|
else
|
69
70
|
lang = val && ISO_639.find_by_code(val)
|
70
71
|
if lang && lang.length > 0
|
71
|
-
hash = {
|
72
|
+
hash = {LANG_KEY => val, SHEET_INDEX_KEY => cellIndex, LOCAL_INDEX_KEY => localIndex}
|
72
73
|
if !@languages.include?(hash)
|
73
74
|
@languages.push(hash)
|
74
75
|
@localizations[localIndex] = []
|
@@ -116,4 +117,23 @@ class LocGen
|
|
116
117
|
}
|
117
118
|
end
|
118
119
|
|
120
|
+
private
|
121
|
+
def writeBaseLocalizable(dir, fileName)
|
122
|
+
selectedHash = @languages[0]
|
123
|
+
if @baseLang && @baseLang.length == 2
|
124
|
+
hashes = @languages.select { |item|
|
125
|
+
item[LANG_KEY] == @baseLang
|
126
|
+
}
|
127
|
+
if hashes.length > 0
|
128
|
+
selectedHash = hashes[0]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
localIndex = selectedHash["localIndex"]
|
133
|
+
dirName = "Base.lproj"
|
134
|
+
dirPath = File.join(dir, dirName)
|
135
|
+
Dir.mkdir(dirPath) unless File.exists?(dirPath)
|
136
|
+
File.write("#{dirPath}/#{fileName}", @localizations[localIndex].join("\n\n"))
|
137
|
+
end
|
138
|
+
|
119
139
|
end
|