Another pass at localization, this time using build-time generated xibs for non-English languages.

git-svn-id: http://munki.googlecode.com/svn/trunk@976 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
Greg Neagle
2010-12-14 18:50:23 +00:00
parent 24af18799e
commit f0340d2ddc
5 changed files with 1403 additions and 91 deletions
@@ -2,9 +2,9 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1050</int>
<string key="IBDocument.SystemVersion">10F569</string>
<string key="IBDocument.SystemVersion">10H574</string>
<string key="IBDocument.InterfaceBuilderVersion">804</string>
<string key="IBDocument.AppKitVersion">1038.29</string>
<string key="IBDocument.AppKitVersion">1038.35</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -22,8 +22,8 @@
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="29"/>
<integer value="633"/>
<integer value="511"/>
<integer value="639"/>
<integer value="516"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -617,7 +617,7 @@
<object class="NSTabViewItem" id="705868753">
<string key="NSIdentifier">1</string>
<object class="NSView" key="NSView" id="78996069">
<reference key="NSNextResponder" ref="901524889"/>
<nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -694,7 +694,7 @@
<object class="NSTextField" id="27237567">
<reference key="NSNextResponder" ref="78996069"/>
<int key="NSvFlags">266</int>
<string key="NSFrame">{{97, 429}, {397, 34}}</string>
<string key="NSFrame">{{97, 420}, {397, 43}}</string>
<reference key="NSSuperview" ref="78996069"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<bool key="NSEnabled">YES</bool>
@@ -715,7 +715,7 @@
<object class="NSButton" id="781634923">
<reference key="NSNextResponder" ref="78996069"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{386, 9}, {115, 32}}</string>
<string key="NSFrame">{{357, 9}, {144, 32}}</string>
<reference key="NSSuperview" ref="78996069"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<bool key="NSEnabled">YES</bool>
@@ -740,7 +740,7 @@
<object class="NSButton" id="555704476">
<reference key="NSNextResponder" ref="78996069"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{290, 9}, {96, 32}}</string>
<string key="NSFrame">{{233, 9}, {124, 32}}</string>
<reference key="NSSuperview" ref="78996069"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<bool key="NSEnabled">YES</bool>
@@ -1154,7 +1154,7 @@
<object class="NSButton" id="228247278">
<reference key="NSNextResponder" ref="78996069"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{11, 9}, {165, 32}}</string>
<string key="NSFrame">{{11, 9}, {197, 32}}</string>
<reference key="NSSuperview" ref="78996069"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<bool key="NSEnabled">YES</bool>
@@ -1174,7 +1174,6 @@
</object>
</object>
<string key="NSFrameSize">{512, 512}</string>
<reference key="NSSuperview" ref="901524889"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
</object>
<string key="NSLabel">Updates</string>
@@ -1184,7 +1183,7 @@
<object class="NSTabViewItem" id="311465176">
<string key="NSIdentifier">2</string>
<object class="NSView" key="NSView" id="574199769">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder" ref="901524889"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1481,7 +1480,7 @@
<object class="NSButton" id="1038081598">
<reference key="NSNextResponder" ref="574199769"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{253, 9}, {96, 32}}</string>
<string key="NSFrame">{{146, 9}, {146, 32}}</string>
<reference key="NSSuperview" ref="574199769"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="69127256">
@@ -1501,7 +1500,7 @@
<object class="NSButton" id="194268296">
<reference key="NSNextResponder" ref="574199769"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{349, 9}, {152, 32}}</string>
<string key="NSFrame">{{292, 9}, {209, 32}}</string>
<reference key="NSSuperview" ref="574199769"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="912961390">
@@ -1568,7 +1567,7 @@
<object class="NSTextField" id="404778079">
<reference key="NSNextResponder" ref="574199769"/>
<int key="NSvFlags">266</int>
<string key="NSFrame">{{97, 429}, {397, 34}}</string>
<string key="NSFrame">{{97, 414}, {397, 49}}</string>
<reference key="NSSuperview" ref="574199769"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<bool key="NSEnabled">YES</bool>
@@ -1584,20 +1583,21 @@
</object>
</object>
<string key="NSFrameSize">{512, 512}</string>
<reference key="NSSuperview" ref="901524889"/>
</object>
<string key="NSLabel">Optional software</string>
<reference key="NSColor" ref="204534777"/>
<reference key="NSTabView" ref="901524889"/>
</object>
</object>
<reference key="NSSelectedTabViewItem" ref="705868753"/>
<reference key="NSSelectedTabViewItem" ref="311465176"/>
<reference key="NSFont" ref="901400326"/>
<int key="NSTvFlags">6</int>
<bool key="NSAllowTruncatedLabels">YES</bool>
<bool key="NSDrawsBackground">YES</bool>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="78996069"/>
<reference ref="574199769"/>
</object>
</object>
</object>
@@ -1676,7 +1676,7 @@
<object class="NSButton" id="638537864">
<reference key="NSNextResponder" ref="218108844"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{422, 12}, {96, 32}}</string>
<string key="NSFrame">{{387, 12}, {131, 32}}</string>
<reference key="NSSuperview" ref="218108844"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="837338071">
@@ -3260,11 +3260,11 @@
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="601497213"/>
<reference ref="194268296"/>
<reference ref="1038081598"/>
<reference ref="732680899"/>
<reference ref="631415620"/>
<reference ref="404778079"/>
<reference ref="194268296"/>
<reference ref="1038081598"/>
</object>
<reference key="parent" ref="311465176"/>
</object>
@@ -3998,6 +3998,7 @@
<string>5.ImportedFromIB2</string>
<string>511.IBAttributePlaceholdersKey</string>
<string>511.IBPluginDependency</string>
<string>511.IBViewBoundsToFrameTransform</string>
<string>512.IBPluginDependency</string>
<string>513.IBPluginDependency</string>
<string>513.IBUserGuides</string>
@@ -4005,7 +4006,9 @@
<string>515.IBPluginDependency</string>
<string>516.IBPluginDependency</string>
<string>517.IBPluginDependency</string>
<string>517.IBViewBoundsToFrameTransform</string>
<string>518.IBPluginDependency</string>
<string>518.IBViewBoundsToFrameTransform</string>
<string>519.IBPluginDependency</string>
<string>520.IBPluginDependency</string>
<string>521.IBPluginDependency</string>
@@ -4251,6 +4254,9 @@
</object>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAAAAAAAAxAEAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSMutableArray">
@@ -4260,7 +4266,13 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABDEAAAwhwAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABDkgAAwhwAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.WebKitIBPlugin</string>
@@ -4299,9 +4311,9 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{345, 612}, {532, 123}}</string>
<string>{{277, 612}, {532, 123}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{345, 612}, {532, 123}}</string>
<string>{{277, 612}, {532, 123}}</string>
<boolean value="NO"/>
<string>{{238, 285}, {480, 360}}</string>
<boolean value="YES"/>
@@ -0,0 +1,246 @@
/* Class = "NSMenuItem"; title = "Bring All to Front"; ObjectID = "5"; */
"5.title" = "Alle nach vorne bringen";
/* Class = "NSMenuItem"; title = "Window"; ObjectID = "19"; */
"19.title" = "Fenster";
/* Class = "NSMenuItem"; title = "Minimize"; ObjectID = "23"; */
"23.title" = "Minimieren";
/* Class = "NSMenu"; title = "Window"; ObjectID = "24"; */
"24.title" = "Fenster";
/* Class = "NSMenu"; title = "AMainMenu"; ObjectID = "29"; */
"29.title" = "AMainMenu";
/* Class = "NSMenuItem"; title = "Managed Software Update"; ObjectID = "56"; */
"56.title" = "Geführte Softwareaktualisierung";
/* Class = "NSMenu"; title = "Managed Software Update"; ObjectID = "57"; */
"57.title" = "Geführte Softwareaktualisierung";
/* Class = "NSMenuItem"; title = "About Managed Software Update"; ObjectID = "58"; */
"58.title" = "Über Geführte Softwareaktualisierung";
/* Class = "NSMenu"; title = "Update"; ObjectID = "81"; */
"81.title" = "Aktualisierung";
/* Class = "NSMenuItem"; title = "Update now "; ObjectID = "82"; */
"82.title" = "Jetzt aktualisieren";
/* Class = "NSMenuItem"; title = "Update"; ObjectID = "83"; */
"83.title" = "Aktualisieren";
/* Class = "NSMenuItem"; title = "Help"; ObjectID = "103"; */
"103.title" = "Hilfe";
/* Class = "NSMenu"; title = "Help"; ObjectID = "106"; */
"106.title" = "Hilfe";
/* Class = "NSMenuItem"; title = "Managed Software Update Help"; ObjectID = "111"; */
"111.title" = "Softwareaktualiserung-Hilfe";
/* Class = "NSMenuItem"; title = "Preferences…"; ObjectID = "129"; */
"129.title" = "Einstellungen…";
/* Class = "NSMenu"; title = "Services"; ObjectID = "130"; */
"130.title" = "Dienste";
/* Class = "NSMenuItem"; title = "Services"; ObjectID = "131"; */
"131.title" = "Dienste";
/* Class = "NSMenuItem"; title = "Hide Managed Software Update"; ObjectID = "134"; */
"134.title" = "Softwareaktualiserung ausblenden";
/* Class = "NSMenuItem"; title = "Quit Managed Software Update"; ObjectID = "136"; */
"136.title" = "Softwareaktualisierung beenden";
/* Class = "NSMenuItem"; title = "Hide Others"; ObjectID = "145"; */
"145.title" = "Andere ausblenden";
/* Class = "NSMenuItem"; title = "Show All"; ObjectID = "150"; */
"150.title" = "Alle einblenden";
/* Class = "NSMenuItem"; title = "Stop Speaking"; ObjectID = "195"; */
"195.title" = "Sprachausgabe starten";
/* Class = "NSMenuItem"; title = "Start Speaking"; ObjectID = "196"; */
"196.title" = "Sprachausgabe stoppen";
/* Class = "NSMenuItem"; title = "Copy"; ObjectID = "197"; */
"197.title" = "Kopieren";
/* Class = "NSMenuItem"; title = "Select All"; ObjectID = "198"; */
"198.title" = "Alles auswählen";
/* Class = "NSMenuItem"; title = "Cut"; ObjectID = "199"; */
"199.title" = "Ausschneiden";
/* Class = "NSMenu"; title = "Spelling and Grammar"; ObjectID = "200"; */
"200.title" = "Rechtschreibung und Grammatik";
/* Class = "NSMenuItem"; title = "Check Spelling"; ObjectID = "201"; */
"201.title" = "Dokument jetzt prüfen";
/* Class = "NSMenuItem"; title = "Delete"; ObjectID = "202"; */
"202.title" = "Löschen";
/* Class = "NSMenuItem"; title = "Paste"; ObjectID = "203"; */
"203.title" = "Einfügen";
/* Class = "NSMenuItem"; title = "Show Spelling…"; ObjectID = "204"; */
"204.title" = "Rechtschreibung und Grammatik einblenden";
/* Class = "NSMenu"; title = "Edit"; ObjectID = "205"; */
"205.title" = "Bearbeiten";
/* Class = "NSMenuItem"; title = "Undo"; ObjectID = "207"; */
"207.title" = "Widerrufen";
/* Class = "NSMenuItem"; title = "Find Next"; ObjectID = "208"; */
"208.title" = "Weitersuchen (vorwärts)";
/* Class = "NSMenuItem"; title = "Find…"; ObjectID = "209"; */
"209.title" = "Suchen";
/* Class = "NSMenuItem"; title = "Jump to Selection"; ObjectID = "210"; */
"210.title" = "Auswahl anzeigen";
/* Class = "NSMenuItem"; title = "Speech"; ObjectID = "211"; */
"211.title" = "Sprachausgabe";
/* Class = "NSMenu"; title = "Speech"; ObjectID = "212"; */
"212.title" = "Sprachausgabe";
/* Class = "NSMenuItem"; title = "Find Previous"; ObjectID = "213"; */
"213.title" = "Weitersuchen (rückwärts)";
/* Class = "NSMenuItem"; title = "Redo"; ObjectID = "215"; */
"215.title" = "Wiederholen";
/* Class = "NSMenuItem"; title = "Spelling and Grammar"; ObjectID = "216"; */
"216.title" = "Rechtschreibung und Grammatik";
/* Class = "NSMenuItem"; title = "Edit"; ObjectID = "217"; */
"217.title" = "Bearbeiten";
/* Class = "NSMenuItem"; title = "Find"; ObjectID = "218"; */
"218.title" = "Suchen";
/* Class = "NSMenuItem"; title = "Check Spelling While Typing"; ObjectID = "219"; */
"219.title" = "Rechtschreibung automatisch prüfen";
/* Class = "NSMenu"; title = "Find"; ObjectID = "220"; */
"220.title" = "Suchen";
/* Class = "NSMenuItem"; title = "Use Selection for Find"; ObjectID = "221"; */
"221.title" = "Auswahl suchen";
/* Class = "NSMenuItem"; title = "Zoom"; ObjectID = "239"; */
"239.title" = "Zoomen";
/* Class = "NSMenuItem"; title = "Check Grammar With Spelling"; ObjectID = "346"; */
"346.title" = "Rechtschreib- und Grammatikprüfung";
/* Class = "NSMenuItem"; title = "Substitutions"; ObjectID = "348"; */
"348.title" = "Ersetzungen";
/* Class = "NSMenu"; title = "Substitutions"; ObjectID = "349"; */
"349.title" = "Ersetzungen";
/* Class = "NSMenuItem"; title = "Smart Copy/Paste"; ObjectID = "350"; */
"350.title" = "Intelligentes Kopieren/Einsetzen";
/* Class = "NSMenuItem"; title = "Smart Quotes"; ObjectID = "351"; */
"351.title" = "Intelligente Anführungszeichen";
/* Class = "NSMenuItem"; title = "Smart Links"; ObjectID = "354"; */
"354.title" = "Intelligente Links";
/* Class = "NSWindow"; title = "Managed Software Update"; ObjectID = "371"; */
"371.title" = "Geführte Softwareaktualisierung";
/* Class = "NSTextFieldCell"; title = "Software updates are available for your computer."; ObjectID = "378"; */
"378.title" = "Für Ihren Computer sind Aktualisierungen verfügbar.";
/* Class = "NSTextFieldCell"; title = "Updating your software may take some time. If you're not ready to update now, you can choose to update later."; ObjectID = "380"; */
"380.title" = "Eine Softwareaktualisierung kann etwas dauern. Sie können diese aber auch später ausführen.";
/* Class = "NSButtonCell"; title = "Update now"; ObjectID = "382"; */
"382.title" = "Aktualisieren";
/* Class = "NSButtonCell"; title = "Later"; ObjectID = "384"; */
"384.title" = "Später";
/* Class = "NSTableColumn"; headerCell.title = "Name"; ObjectID = "397"; */
"397.headerCell.title" = "Name";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "398"; */
"398.title" = "Text Cell";
/* Class = "NSTableColumn"; headerCell.title = "Version"; ObjectID = "400"; */
"400.headerCell.title" = "Version";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "401"; */
"401.title" = "Text Cell";
/* Class = "NSTabViewItem"; label = "Updates"; ObjectID = "512"; */
"512.label" = "Aktualisierungen";
/* Class = "NSTabViewItem"; label = "Optional software"; ObjectID = "514"; */
"514.label" = "Optionale Software";
/* Class = "NSButtonCell"; title = "Add or Remove"; ObjectID = "519"; */
"519.title" = "Hinzufügen oder Entfernen";
/* Class = "NSButtonCell"; title = "Cancel"; ObjectID = "520"; */
"520.title" = "Abbrechen";
/* Class = "NSTableColumn"; headerCell.title = "Name"; ObjectID = "527"; */
"527.headerCell.title" = "Name";
/* Class = "NSTableColumn"; headerCell.title = "Version"; ObjectID = "528"; */
"528.headerCell.title" = "Version";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "531"; */
"531.title" = "Text Cell";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "532"; */
"532.title" = "Text Cell";
/* Class = "NSTextFieldCell"; title = "Check an item to have it installed. Uncheck an item to have it removed."; ObjectID = "546"; */
"546.title" = "Elemente markieren um sie zu installieren. Abgewählte werden vom Rechner entfernt.";
/* Class = "NSTextFieldCell"; title = "Add or remove optional software"; ObjectID = "547"; */
"547.title" = "Optionale Software hinzufügen oder entfernen";
/* Class = "NSButtonCell"; title = "Optional software..."; ObjectID = "550"; */
"550.title" = "Optionale Software…";
/* Class = "NSTableColumn"; headerCell.title = "Size"; ObjectID = "581"; */
"581.headerCell.title" = "Größe";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "582"; */
"582.title" = "Text Cell";
/* Class = "NSTableColumn"; headerCell.title = "Size"; ObjectID = "585"; */
"585.headerCell.title" = "Größe";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "586"; */
"586.title" = "Text Cell";
/* Class = "NSTableColumn"; headerCell.title = "Status"; ObjectID = "628"; */
"628.headerCell.title" = "Status";
/* Class = "NSTextFieldCell"; title = "Text Cell"; ObjectID = "629"; */
"629.title" = "Text Cell";
/* Class = "NSWindow"; title = "Managed Software Update"; ObjectID = "633"; */
"633.title" = "Softwareaktualisierung";
/* Class = "BorderlessWindow"; title = "BackdropWindow"; ObjectID = "635"; */
"635.title" = "BackdropWindow";
/* Class = "NSButtonCell"; title = "Stop"; ObjectID = "645"; */
"645.title" = "Stoppen";
File diff suppressed because it is too large Load Diff
+250
View File
@@ -0,0 +1,250 @@
#!/usr/bin/python
'''
Wraps the ibtool commandline to generate nibs from .strings files.
An md5 checksum of the base nibs is stored in a Localize.ini file,
if a checksum for the file does not exist or the check does not match
a new localized nib is created.
Based on Philippe Casgrain's 'Automatically localize your nibs when building'
http://developer.casgrain.com/?p=94
And Wil Shipley's 'Pimp My Code, Part 17: Lost in Translations'
http://wilshipley.com/blog/2009/10/pimp-my-code-part-17-lost-in.html
Written by David Keegan for Murky
http://bitbucket.org/snej/murky
Usage:
Localize.py -help
Localize nibs:
Localize.py --from English --to "French|German" --nibs "MainMenu|Projects|Repo"
Generate Strings:
Localize.py --to English --genstrings "./**/*.[hm]"
Use the '--utf8' flag to convert the strings files from utf-16 to utf-8.
The MIT License
Copyright David Keegan 2009-1010
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
from __future__ import with_statement
import time
import codecs
import os, re
import sys, glob
import subprocess
from optparse import OptionParser
from shutil import copyfile
k_valueParse = re.compile('(?P<key>.+)=(?P<value>.+)$', re.UNICODE)
k_localizePath = os.path.abspath('Localize.ini')
class LocalizationError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return str(self.value)
def detectEncoding(filepath):
'''
Try to detect the file's encoding.
If its not utf-16 assume it's utf-8, this should work for ascii
files becuase the first 128 characters are the same...
'''
f = open(filepath, 'r')
firstBytes = f.read(2)
f.close()
if firstBytes == codecs.BOM_UTF16_BE:
return 'utf_16_be'
elif firstBytes == codecs.BOM_UTF16_LE:
return 'utf_16_le'
#use sig just encase there is a BOM in the file
return 'utf_8_sig'
def fileToUtf8(stringFile):
'''
Convert the .strings file from utf-16 to utf-8
This will allow files diffs
'''
if os.path.isfile(stringFile):
tempStrings = stringFile+'temp'
stringsEncoding = detectEncoding(stringFile)
#if the file is not already utf-8 re-encode it
if stringsEncoding != 'utf_8_sig':
fromFile = codecs.open(stringFile, 'rU', stringsEncoding)
toFile = codecs.open(tempStrings, 'w', 'utf_8')
for eachLine in fromFile:
toFile.write(eachLine)
toFile.close()
fromFile.close()
os.remove(stringFile)
os.rename(tempStrings, stringFile)
def runCommand(command, args):
'''Run shell commands'''
commandAndArgs = '%s %s' % (command, args)
proc = subprocess.Popen(commandAndArgs, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
if stderr != '':
raise LocalizationError(commandAndArgs + ' : ' + stderr)
return stdout
def md5(file):
'''Get the md5 checksum of a file'''
md5Sum = runCommand('/usr/bin/openssl md5', file)
return md5Sum.split('=')[1].strip()
def langProjName(language):
return language.strip()+'.lproj'
def nibToStringFileName(nibFile):
return nibFile.rstrip('.xib')+'.strings'
def ibtoolsGenerateStringsFile(nibFile, utf8=False):
'''
Generate a .strings file from a nib
If utf8 is True the .strings files will be re-encoded as utf-8
'''
nibFileStrings = nibToStringFileName(nibFile)
runCommand('ibtool', '--generate-strings-file %s %s' % (nibFileStrings, nibFile))
if utf8:
fileToUtf8(nibFileStrings)
print ' ', nibFileStrings, 'updated'
def ibtoolsWriteNib(fromFile, toFile, utf8=False):
'''convert one localized nib from one language to another'''
toStrings = nibToStringFileName(toFile)
runCommand('ibtool', '--strings-file %s --write %s %s' % (toStrings, toFile, fromFile))
if utf8:
fileToUtf8(toStrings)
print ' ', toFile, 'updated'
def genStrings(toLangs, globString, utf8=False):
for eachToLang in toLangs:
toLangLproj = langProjName(eachToLang)
runCommand('genstrings', '-o %s %s' % (toLangLproj, globString))
localizableStrings = os.path.join(toLangLproj, 'Localizable.strings')
if utf8:
fileToUtf8(localizableStrings)
print ' ', localizableStrings, 'updated'
def getDict():
'''Read the values from Localize.ini and return a dictionary'''
localizeDict = {}
if not os.path.isfile(k_localizePath):
return localizeDict
with open(k_localizePath, 'rU') as localizeFile:
for line in localizeFile:
line = line.strip()
match = k_valueParse.match(line)
if match:
localizeDict[match.group('key')] = match.group('value')
return localizeDict
def writeDict(dict):
'''Write a dictionary to Localize.ini'''
with open(k_localizePath, 'w') as localizeFile:
for key, value in sorted(dict.iteritems()):
localizeFile.write('%s=%s\n' % (key, value))
def localizeNibs(fromLang, toLangs, nibs=None, utf8=False, ignore=False):
'''Localize nibs from one language to others'''
#get the data from the ini file
iniData = getDict()
fromLangLproj = langProjName(fromLang)
#if nibs is none, get all the nibs in the from language project
if nibs is None:
nibs = []
for eachNib in glob.glob('%s/*.xib' % fromLangLproj):
nibs.append(eachNib.lstrip(fromLangLproj+'/').rstrip('.xib'))
for eachNib in nibs:
eachNib = eachNib.strip()
if not eachNib.endswith('.xib'):
eachNib += '.xib'
fromNib = os.path.join(fromLangLproj, eachNib)
#get md5 and update the ini data
fromNibMd5 = md5(fromNib)
#check if the strings for the fromNib need to the updated
if not os.path.isfile(nibToStringFileName(fromNib)) or fromNib not in iniData or iniData[fromNib] != fromNibMd5:
ibtoolsGenerateStringsFile(fromNib, utf8)
#write the localized nibs
for eachToLang in toLangs:
toLangLproj = langProjName(eachToLang)
toNib = os.path.join(toLangLproj, eachNib)
toStrings = nibToStringFileName(toNib)
#if there is no localized string file for the nib copy it from the 'from language'
if not os.path.isfile(toStrings):
fromStrings = nibToStringFileName(fromNib)
copyfile(fromStrings, toStrings)
toStringsMd5 = md5(toStrings)
if (not os.path.isfile(toNib) or fromNib not in iniData or iniData[fromNib] != fromNibMd5 or
toStrings not in iniData or iniData[toStrings] != toStringsMd5):
ibtoolsWriteNib(fromNib, toNib, utf8)
iniData[toStrings] = toStringsMd5
iniData[fromNib] = fromNibMd5
#update Localize.ini
writeDict(iniData)
if __name__ == '__main__':
'''Command line options'''
startTime = time.time()
opts = OptionParser()
opts.add_option('--from', '-f', dest='fromLang', help='The language to localize from.', metavar='LANG')
opts.add_option('--to', '-t', dest='toLangs', help="An array of languages to localize to, separated by '|'.", metavar='LANGS')
opts.add_option('--nibs', '-n', dest='nibs', help="An array of nibs to localize, separated by '|', .xib can be left off. If this flag is left out all the nibs in the from language will be used.", metavar='NIBS')
opts.add_option('--utf8', '-u', dest='utf8', help='If this flag is present the .strings files will be re-encoded as utf-8.', action="store_true", default=False)
opts.add_option('--ignore', '-i', dest='ignore', help='If this flag is present the md5 checksums will be ignored.', action="store_true", default=False)
opts.add_option('--genstrings', '-g', dest='genstrings', help='File name or glob string. If this argument is present the genstrings command line will be called.', metavar='GLOB', default=None)
options, arguments = opts.parse_args()
if options.genstrings != None:
genStrings(options.toLangs.split('|'), options.genstrings, options.utf8)
print 'Strings updated in %.2f seconds' % (time.time()-startTime)
else:
nibs = options.nibs
if nibs != None:
nibs = options.nibs.split('|')
localizeNibs(options.fromLang, options.toLangs.split('|'), nibs, options.utf8, options.ignore)
print 'Nibs updated in %.2f seconds' % (time.time()-startTime)
@@ -34,7 +34,7 @@
C09D9A2D11E6DC7800B3E573 /* MSUupdatesViewController.py in Resources */ = {isa = PBXBuildFile; fileRef = C09D9A2C11E6DC7800B3E573 /* MSUupdatesViewController.py */; };
C0C548FC12B6E52B002C76CD /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C0C548F612B6E52B002C76CD /* InfoPlist.strings */; };
C0C548FD12B6E52B002C76CD /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C0C548F812B6E52B002C76CD /* Localizable.strings */; };
C0C548FE12B6E52B002C76CD /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0C548FA12B6E52B002C76CD /* MainMenu.xib */; };
C0C5491F12B7F00D002C76CD /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0C5491D12B7F00D002C76CD /* MainMenu.xib */; };
C0E9E82411EFB1EB003CE81A /* Solid Aqua Blue.png in Resources */ = {isa = PBXBuildFile; fileRef = C0E9E82311EFB1EB003CE81A /* Solid Aqua Blue.png */; };
/* End PBXBuildFile section */
@@ -74,7 +74,7 @@
C09D9A2C11E6DC7800B3E573 /* MSUupdatesViewController.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = MSUupdatesViewController.py; sourceTree = "<group>"; };
C0C548F712B6E52B002C76CD /* German */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = German; path = InfoPlist.strings; sourceTree = "<group>"; };
C0C548F912B6E52B002C76CD /* German */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = German; path = Localizable.strings; sourceTree = "<group>"; };
C0C548FB12B6E52B002C76CD /* German */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = German; path = MainMenu.xib; sourceTree = "<group>"; };
C0C5491E12B7F00D002C76CD /* German */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = German; path = MainMenu.xib; sourceTree = "<group>"; };
C0E9E82311EFB1EB003CE81A /* Solid Aqua Blue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Solid Aqua Blue.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -200,9 +200,9 @@
C0C548F512B6E52B002C76CD /* German.lproj */ = {
isa = PBXGroup;
children = (
C0C5491D12B7F00D002C76CD /* MainMenu.xib */,
C0C548F612B6E52B002C76CD /* InfoPlist.strings */,
C0C548F812B6E52B002C76CD /* Localizable.strings */,
C0C548FA12B6E52B002C76CD /* MainMenu.xib */,
);
path = German.lproj;
sourceTree = "<group>";
@@ -214,8 +214,9 @@
isa = PBXNativeTarget;
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "Managed Software Update" */;
buildPhases = (
C0C5491712B7EEBA002C76CD /* Localize */,
8D1107290486CEB800E47090 /* Resources */,
C02BEBB212776D140066DB2C /* ShellScript */,
C02BEBB212776D140066DB2C /* Embed version info */,
8D11072C0486CEB800E47090 /* Sources */,
8D11072E0486CEB800E47090 /* Frameworks */,
);
@@ -281,26 +282,41 @@
C0E9E82411EFB1EB003CE81A /* Solid Aqua Blue.png in Resources */,
C0C548FC12B6E52B002C76CD /* InfoPlist.strings in Resources */,
C0C548FD12B6E52B002C76CD /* Localizable.strings in Resources */,
C0C548FE12B6E52B002C76CD /* MainMenu.xib in Resources */,
C0C5491F12B7F00D002C76CD /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
C02BEBB212776D140066DB2C /* ShellScript */ = {
C02BEBB212776D140066DB2C /* Embed version info */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed version info";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "BASEVERNUM=`/usr/libexec/PlistBuddy -c \"Print :CFBundleShortVersionString\" \"${INFOPLIST_FILE}\"`\nREV=`svnversion -n | cut -d: -f2 | tr -cd '[:digit:]'`\n/usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString $BASEVERNUM.$REV\" \"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $REV\" \"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}\"";
};
C0C5491712B7EEBA002C76CD /* Localize */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = Localize;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# generate localizable strings\n./Localize.py --to English --genstrings \"./**/*.[hm]\" --utf8\n\n# localize nibs\n./Localize.py --from English --to German --utf8";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@@ -349,10 +365,10 @@
name = Localizable.strings;
sourceTree = "<group>";
};
C0C548FA12B6E52B002C76CD /* MainMenu.xib */ = {
C0C5491D12B7F00D002C76CD /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
C0C548FB12B6E52B002C76CD /* German */,
C0C5491E12B7F00D002C76CD /* German */,
);
name = MainMenu.xib;
sourceTree = "<group>";