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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/locgen +2 -1
  3. data/lib/LocGen.rb +24 -4
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 350d93a13fcaa97106fd8f132cc05a39373419b3
4
- data.tar.gz: c0f01d9c70c3912f98a7ba1458c21de50d47363b
3
+ metadata.gz: 4ce50a6e53535efebef12e0b3de6d7da0adeaed2
4
+ data.tar.gz: 8923910802d71841f1d76e45c29ba09d2359036c
5
5
  SHA512:
6
- metadata.gz: 42b946312331ad05adfdce950d2441cd5023065cee46b756400aa865ade0d61c03f7f36061ce3da5d484bb05bf54ab3089bc47e6a5c2a319d516d3f64b78a4bb
7
- data.tar.gz: e84b46994f024c4692431ead80e1afaa28962581bcb669247498ff4890eb416712f0eff0f5d6f119435056514c2c39d3215bc413ccdb35f3b5f4bc70ffdb069d
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
- LANG_INDEX_KEY = "lang"
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 = {LANG_INDEX_KEY => val, SHEET_INDEX_KEY => cellIndex, LOCAL_INDEX_KEY => localIndex}
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Lisik