forked from CatchZeng/Localizable.strings2Excel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support convert Localizable.strings to android strings.xml (Localizab…
…leToStringXml.py)
- Loading branch information
Showing
12 changed files
with
808 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# -*- coding:utf-8 -*- | ||
|
||
import codecs | ||
import pyExcelerator | ||
import sys | ||
import os | ||
from optparse import OptionParser | ||
|
||
#Add command option | ||
def addParser(): | ||
parser = OptionParser() | ||
|
||
parser.add_option("-f", "--filePath", | ||
help="Localizable.strings file path.", | ||
metavar="filePath") | ||
|
||
parser.add_option("-t", "--targetFilePath", | ||
help="strings.xml file Path.", | ||
metavar="targetFilePath") | ||
|
||
parser.add_option("-a", "--additionalInfo", | ||
help="Additional info.", | ||
metavar="additionalInfo") | ||
|
||
(options, args) = parser.parse_args() | ||
|
||
return options | ||
|
||
|
||
# Start convert Localizable.strings to android strings.xml | ||
def startConvert(options): | ||
filePath = options.filePath | ||
targetFilePath = options.targetFilePath | ||
additionalInfo = options.additionalInfo | ||
|
||
if filePath is not None: | ||
# ------------------------------ iOS --------------------------- | ||
print "Read Localizable.strings file from %s" % (filePath) | ||
|
||
# 1.Read localizable.strings | ||
file = codecs.open(filePath, 'r', 'utf-8') | ||
string = file.read() | ||
file.close() | ||
|
||
# 2.Split by "; | ||
localStringList = string.split('\";') | ||
list = [x.split(' = ') for x in localStringList] | ||
|
||
print "Read Localizable.strings finish" | ||
|
||
if targetFilePath is not None: | ||
filePath = targetFilePath | ||
if (not targetFilePath.endswith(".xml")): | ||
filePath = targetFilePath + "/strings.xml" | ||
|
||
# ------------------------------ Android --------------------------- | ||
print "Writing data to target file" | ||
|
||
# 1.open file | ||
fo = open(filePath, "wb") | ||
|
||
# 2.write header data | ||
xmlHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n" | ||
fo.write(xmlHeader) | ||
|
||
# Add two columns data | ||
for x in range(len(list)): | ||
keyValue = list[x]; | ||
if len(keyValue) > 1: | ||
string0 = keyValue[0] | ||
string1 = keyValue[1] | ||
string0 = string0.split('\"')[1] | ||
string1 = string1[1:] | ||
stringcontent = " <string name=\"" + string0 + "\">" + string1 + "</string>\n" | ||
fo.write(stringcontent.encode('utf-8')); | ||
|
||
# Save to target file path | ||
if additionalInfo is not None: | ||
fo.write(additionalInfo) | ||
|
||
fo.write("</resources>"); | ||
|
||
# Close file | ||
fo.close() | ||
|
||
print "Convert successfully! you can see strings.xml in %s" % (filePath) | ||
|
||
else: | ||
print "Target file path can not be empty! try -h for help." | ||
|
||
else: | ||
print "File path can not be empty! try -h for help." | ||
|
||
return | ||
|
||
|
||
# Mian | ||
def main(): | ||
options = addParser() | ||
startConvert(options) | ||
|
||
return | ||
|
||
|
||
#Start | ||
main() | ||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="PLAY">运行</string> | ||
<string name="PAUSED">暂停</string> | ||
<string name="DESIGN">编辑</string> | ||
<string name="Feedback">反馈</string> | ||
<string name="Groups">社区</string> | ||
<string name="Comment">评论</string> | ||
<string name="Instruction">说明</string> | ||
<string name="Send Feedback">发送反馈</string> | ||
<string name="Wechat">微信</string> | ||
<string name="Enter your comment">请写上您的反馈意见</string> | ||
<string name="Email">电子邮件地址</string> | ||
<string name="Information Needed">需要您的信息</string> | ||
<string name="Please fill in both your email and your feedback">请填写您的电子邮件和反馈信息</string> | ||
<string name="Give your project a new name">请为项目命名</string> | ||
<string name="Delete">删除</string> | ||
<string name="No Name">未命名</string> | ||
</resources> |