ibtoolTranslation 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f212a50e88e5031ad42ecc816bce4177d6f29a25
4
- data.tar.gz: 713b2ab555e6179ababca801541091f31c5a76b6
3
+ metadata.gz: 12aee41996f1618b4c1743fecc55e4e8f5d75c5e
4
+ data.tar.gz: cc67ba19546505cda6bab6662a07b2d94339f1d5
5
5
  SHA512:
6
- metadata.gz: 8847a86cf6f93fe0921caac32ada90dd87d5ba27b4e1d58ab0598fa773b371da3fed04d05f929043cf700c41bb96cac4d5ba7f742a9f7b5d376a252496c23597
7
- data.tar.gz: 4de708ae5c4997d371f588b985aa22d1fd42812f4ff04b0b19e3a5a07e842eb810a6142ca27e2e8524b8bd8151ecece0590fc97b677139dd4874b558862bc701
6
+ metadata.gz: a65a4838a62f9fdc483f96902513f6110ddad38fe728187f526c540c91fe7ae8fa56c3a1c9feb8395114cf31fc97206c0d8746d0e3f4b48e7dd7a5e577193a7c
7
+ data.tar.gz: 26651e28f9885f3f1a4817f54e47db06ba1c2f5acad0c2a03a95729164a330c76a2801068d91b50e5d2da706fa2b1fc7e41bdc414d636f9389b370211ceafe0c
@@ -7,126 +7,127 @@ $/
7
7
 
8
8
  module IbtoolTranslation
9
9
  class Core
10
- def create(dirName, sourceDir, lps, string)
11
- lprojs = lps.map {|lp| dirName + lp + ".lproj"}
12
- sourceLproj = dirName + sourceDir + ".lproj"
13
- storyboards = self.storyboards sourceLproj
10
+ def create(dirName, sourceDir, lps, string)
11
+ lprojs = lps.map {|lp| dirName + lp + ".lproj"}
12
+ sourceLproj = dirName + sourceDir + ".lproj"
13
+ storyboards = self.storyboards sourceLproj
14
14
 
15
- if (string)
16
- self.deleteStringsFile(sourceLproj, lprojs)
17
- end
18
- self.makeDirectory(lprojs)
19
- self.createTranslation(sourceLproj, lprojs, storyboards)
20
- unless (string)
21
- self.deleteStringsFile(sourceLproj, lprojs)
22
- end
23
- end
24
- def update(dirName, sourceDir, lps, string)
25
- lprojs = lps.map {|lp| dirName + lp + ".lproj"}
26
- sourceLproj = dirName + sourceDir + ".lproj"
27
- storyboards = self.storyboards sourceLproj
15
+ if (string)
16
+ self.deleteStringsFile(sourceLproj, lprojs)
17
+ end
18
+ self.makeDirectory(lprojs)
19
+ self.createTranslation(sourceLproj, lprojs, storyboards)
20
+ unless (string)
21
+ self.deleteStringsFile(sourceLproj, lprojs)
22
+ end
23
+ end
24
+ def update(dirName, sourceDir, lps, string)
25
+ lprojs = lps.map {|lp| dirName + lp + ".lproj"}
26
+ sourceLproj = dirName + sourceDir + ".lproj"
27
+ storyboards = self.storyboards sourceLproj
28
28
 
29
- if (string)
30
- self.deleteStringsFile(sourceLproj, lprojs)
31
- end
32
- self.makeDirectory(lprojs)
33
- self.createTranslation(sourceLproj, lprojs, storyboards)
34
- self.translateStrings(sourceLproj, lprojs, storyboards)
35
- unless (string)
36
- self.translateStoryboards(sourceLproj, lprojs, storyboards)
37
- self.deleteStringsFile(sourceLproj, lprojs)
38
- end
39
- end
40
- def makeDirectory(lprojs)
41
- lprojs.each {|lproj| FileUtils.mkdir_p(lproj) }
42
- end
43
- def createTranslation(sourceDir, lprojs, storyboards)
44
- lprojs.each {|lproj|
45
- transText = self.transText("#{lproj}/Translation.strings")
46
- baseData = self.baseDataForTransText(transText)
47
- storyboards.each { |fileName|
48
- `ibtool --generate-stringsfile #{lproj}/#{fileName}.strings #{sourceDir}/#{fileName}.storyboard`
49
- addtionData = self.addtionData("#{lproj}/#{fileName}.strings")
50
- aData = addtionData.select{|f| baseData.include?(f) == false}
51
- transText = transText + aData.map{|f| "\"#{f}\";\n"}.join("")
52
- }
53
- self.writeTransText("#{lproj}/Translation.strings", transText)
54
- }
55
- end
56
- def translateStrings(sourceDir, lprojs, storyboards)
57
- lprojs.each {|lproj|
58
- transText = self.transText("#{lproj}/Translation.strings")
59
- storyboards.each { |fileName|
60
- self.translateStringsFile(lproj, fileName, transText)
61
- puts fileName unless $debug
62
- }
63
- }
64
- end
65
- def translateStoryboards(sourceDir, lprojs, storyboards)
66
- lprojs.each {|lproj|
67
- storyboards.each { |fileName|
68
- `ibtool --write #{lproj}/#{fileName}.storyboard -d #{lproj}/#{fileName}.strings #{sourceDir}/#{fileName}.storyboard`
69
- }
70
- }
71
- end
72
- def deleteStringsFile(sourceDir, lprojs)
73
- storyboards = self.storyboards sourceDir
29
+ if (string)
30
+ self.deleteStringsFile(sourceLproj, lprojs)
31
+ end
32
+ self.makeDirectory(lprojs)
33
+ self.createTranslation(sourceLproj, lprojs, storyboards)
34
+ self.translateStrings(sourceLproj, lprojs, storyboards)
35
+ unless (string)
36
+ self.translateStoryboards(sourceLproj, lprojs, storyboards)
37
+ self.deleteStringsFile(sourceLproj, lprojs)
38
+ end
39
+ end
40
+ def makeDirectory(lprojs)
41
+ lprojs.each {|lproj| FileUtils.mkdir_p(lproj) }
42
+ end
43
+ def createTranslation(sourceDir, lprojs, storyboards)
44
+ lprojs.each {|lproj|
45
+ transText = self.transText("#{lproj}/Translation.strings")
46
+ baseData = self.baseDataForTransText(transText)
47
+ storyboards.each { |fileName|
48
+ `ibtool --generate-stringsfile #{lproj}/#{fileName}.strings #{sourceDir}/#{fileName}.storyboard`
49
+ addtionData = self.addtionData("#{lproj}/#{fileName}.strings")
50
+ aData = addtionData.select{|f| baseData.include?(f) == false}
51
+ transText = transText + aData.map{|f| "\"#{f}\";\n"}.join("")
52
+ }
53
+ self.writeTransText("#{lproj}/Translation.strings", transText)
54
+ }
55
+ end
56
+ def translateStrings(sourceDir, lprojs, storyboards)
57
+ lprojs.each {|lproj|
58
+ transText = self.transText("#{lproj}/Translation.strings")
59
+ storyboards.each { |fileName|
60
+ self.translateStringsFile(lproj, fileName, transText)
61
+ puts fileName unless $debug
62
+ }
63
+ }
64
+ end
65
+ def translateStoryboards(sourceDir, lprojs, storyboards)
66
+ lprojs.each {|lproj|
67
+ storyboards.each { |fileName|
68
+ `ibtool --write #{lproj}/#{fileName}.storyboard -d #{lproj}/#{fileName}.strings #{sourceDir}/#{fileName}.storyboard`
69
+ }
70
+ }
71
+ end
72
+ def deleteStringsFile(sourceDir, lprojs)
73
+ storyboards = self.storyboards sourceDir
74
74
 
75
- lprojs.each {|lproj|
76
- storyboards.each { |fileName|
77
- File::delete("#{lproj}/#{fileName}.strings")
78
- }
79
- }
80
- end
75
+ lprojs.each {|lproj|
76
+ storyboards.each { |fileName|
77
+ filePath = "#{lproj}/#{fileName}.strings"
78
+ File::delete(filePath) if FileTest.exist?(filePath)
79
+ }
80
+ }
81
+ end
81
82
 
82
- def translateStringsFile(lproj, fileName, transText)
83
- translationData = self.translationData("#{lproj}/#{fileName}.strings")
84
- translationDict = self.translationDict(transText)
83
+ def translateStringsFile(lproj, fileName, transText)
84
+ translationData = self.translationData("#{lproj}/#{fileName}.strings")
85
+ translationDict = self.translationDict(transText)
85
86
 
86
- aData = translate(translationData, translationDict)
87
- transText = aData.map{|f| "\"#{f[0]}\" = \"#{f[1]}\";\n"}.join("")
88
- File.open("#{lproj}/#{fileName}.strings", "w:UTF-16"){|f| f.write transText}
89
- end
90
- def translate(translationData, translationDict)
91
- translationData.map{|arr|
92
- (translationDict.key? arr[1]) ? [arr[0], translationDict[arr[1]]] : arr
93
- }
94
- end
95
- def translationDict(transText)
96
- Hash[*(transText.scan(/"(.*)"\s*=\s*"(.*)";?\s*\n/).flatten)]
97
- end
98
- def translationData(fileName)
99
- self.readFile(fileName).scan(/"(.*)" *= *"(.*)";\n/).uniq
100
- end
101
- def writeTransText(fileName, transText)
102
- File.open(fileName, "w:UTF-16"){|f| f.write transText}
103
- end
104
- def baseDataForTransText(transText)
87
+ aData = translate(translationData, translationDict)
88
+ transText = aData.map{|f| "\"#{f[0]}\" = \"#{f[1]}\";\n"}.join("")
89
+ File.open("#{lproj}/#{fileName}.strings", "w:UTF-16"){|f| f.write transText}
90
+ end
91
+ def translate(translationData, translationDict)
92
+ translationData.map{|arr|
93
+ (translationDict.key? arr[1]) ? [arr[0], translationDict[arr[1]]] : arr
94
+ }
95
+ end
96
+ def translationDict(transText)
97
+ Hash[*(transText.scan(/"(.*)"\s*=\s*"(.*)";?\s*\n/).flatten)]
98
+ end
99
+ def translationData(fileName)
100
+ self.readFile(fileName).scan(/"(.*)" *= *"(.*)";\n/).uniq
101
+ end
102
+ def writeTransText(fileName, transText)
103
+ File.open(fileName, "w:UTF-16"){|f| f.write transText}
104
+ end
105
+ def baseDataForTransText(transText)
105
106
  (transText.scan(/"(.*)"\s*=\s*".*";?\s*\n/) + transText.scan(/"(.*)";?\s*\n/)).flatten
106
- end
107
- def transText(fileName)
108
- self.readFile(fileName)
109
- end
110
- def addtionData(fileName)
111
- self.readFile(fileName).scan(/".*" *= *"(.*)";\n/).uniq.flatten
112
- end
113
- def storyboards(sourceDir)
114
- Dir.open(sourceDir).map {|f|
115
- f.gsub(/(.*)\.storyboard/, '\1').gsub(/\w*\.\w*/, "")
116
- }.select {|f| f != "" }
117
- end
118
- def readFile(fileName)
119
- FileTest.exist?(fileName) ? File.read(fileName, :mode => "rb", :encoding => "UTF-16LE").toutf8 : ""
120
- end
121
- def deleteDir(dir)
122
- Dir::glob(dir + "**/").sort {
123
- |a,b| b.split('/').size <=> a.split('/').size
124
- }.each {|d|
125
- Dir::foreach(d) {|f|
126
- File::delete(d+f) if ! (/\.+$/ =~ f)
127
- }
128
- Dir::rmdir(d)
129
- }
130
- end
107
+ end
108
+ def transText(fileName)
109
+ self.readFile(fileName)
110
+ end
111
+ def addtionData(fileName)
112
+ self.readFile(fileName).scan(/".*" *= *"(.*)";\n/).uniq.flatten
113
+ end
114
+ def storyboards(sourceDir)
115
+ Dir.open(sourceDir).map {|f|
116
+ f.gsub(/(.*)\.storyboard/, '\1').gsub(/\w*\.\w*/, "")
117
+ }.select {|f| f != "" }
118
+ end
119
+ def readFile(fileName)
120
+ FileTest.exist?(fileName) ? File.read(fileName, :mode => "rb", :encoding => "UTF-16LE").toutf8 : ""
121
+ end
122
+ def deleteDir(dir)
123
+ Dir::glob(dir + "**/").sort {
124
+ |a,b| b.split('/').size <=> a.split('/').size
125
+ }.each {|d|
126
+ Dir::foreach(d) {|f|
127
+ File::delete(d+f) if ! (/\.+$/ =~ f)
128
+ }
129
+ Dir::rmdir(d)
130
+ }
131
+ end
131
132
  end
132
133
  end
@@ -1,3 +1,3 @@
1
1
  module IbtoolTranslation
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibtoolTranslation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - akuraru