ibtoolTranslation 0.0.8 → 0.0.9
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/lib/ibtoolTranslation.rb +116 -115
 - data/lib/ibtoolTranslation/version.rb +1 -1
 - 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: 12aee41996f1618b4c1743fecc55e4e8f5d75c5e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: cc67ba19546505cda6bab6662a07b2d94339f1d5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a65a4838a62f9fdc483f96902513f6110ddad38fe728187f526c540c91fe7ae8fa56c3a1c9feb8395114cf31fc97206c0d8746d0e3f4b48e7dd7a5e577193a7c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 26651e28f9885f3f1a4817f54e47db06ba1c2f5acad0c2a03a95729164a330c76a2801068d91b50e5d2da706fa2b1fc7e41bdc414d636f9389b370211ceafe0c
         
     | 
    
        data/lib/ibtoolTranslation.rb
    CHANGED
    
    | 
         @@ -7,126 +7,127 @@ $/ 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            module IbtoolTranslation
         
     | 
| 
       9 
9 
     | 
    
         
             
              class Core
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
      
 83 
     | 
    
         
            +
                def translateStringsFile(lproj, fileName, transText)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  translationData = self.translationData("#{lproj}/#{fileName}.strings")
         
     | 
| 
      
 85 
     | 
    
         
            +
                  translationDict = self.translationDict(transText)
         
     | 
| 
       85 
86 
     | 
    
         | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     |