最近在做app的多语言功能,这翻译文件实在是不好整,幸好有大神做了个py工具实现 string文件转exl,作者:CatchZeng,https://github.com/CatchZeng/Localizable.strings2Excel
不多说介绍如下
特性
- 支持将 iOS strings 文件转换成 excel 文件
- 支持将 excel 文件转换成 iOS strings 文件
- 支持将 android xml 文件转换成 excel 文件
- 支持将 excel 文件转换成 android xml 文件
- 支持将 iOS strings 文件转换成 android xml 文件
所需环境
1.检查 python 版本
python 版本必须是 2.x
$ python --version
Python 2.7.10
2.检查 pip(python 包管理器)
$ pip --version
pip 19.0 from /Library/Python/2.7/site-packages/pip (python 2.7)
如果没有安装 pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
3.安装 pyexcelerator
sudo pip install pyExcelerator
4.安装 xlrd
sudo pip install xlrd
使用说明
安装好py环境之后,下载Git上的工具
https://github.com/CatchZeng/Localizable.strings2Excel
下载解压完了,将当前有的多语言文件放到examples目录下面去替换现有的文件,然后选择下面的对应py命令去转换
1.将 iOS strings 文件转换成 excel 文件
$ python python/Strings2Xls.py -f examples/ios/ -t examples/output
Start converting
Convert examples/ios/ successfully! you can see xls file in examples/output/strings-files-to-xls_20190129_165830
2.将 excel 文件转换成 iOS strings 文件
$ python python/Xls2Strings.py -f examples/output/strings-files-to-xls_20190129_165830/ -t examples/ou
tput/
options: {'fileDir': 'examples/output/strings-files-to-xls_20190129_165830/', 'targetDir': 'examples/output/', 'excelStorageForm': 'multiple', 'additional': None
}, args: []
Start converting
Convert examples/output/strings-files-to-xls_20190129_165830/ successfully! you can see strings file in examples/output//xls-files-to-strings_20190129_171146
3.将 android xml 文件转换成 excel 文件
$ python python/Xml2Xls.py -f examples/android/ -t examples/output
options: {'fileDir': 'examples/android/', 'targetDir': 'examples/output', 'excelStorageForm': 'multiple'}, args: []
Start converting
Convert examples/android/ successfully! you can see xls file in examples/output/xml-files-to-xls_20190129_172938
4.将 excel 文件转换成 android xml 文件
$ python python/Xls2Xml.py -f examples/output/xml-files-to-xls_20190129_172938/ -t examples/output/
options: {'fileDir': 'examples/output/xml-files-to-xls_20190129_172938/', 'targetDir': 'examples/output/', 'excelStorageForm': 'multiple', 'additional': None}, args
: []
Start converting
Convert examples/output/xml-files-to-xls_20190129_172938/ successfully! you can xml files in examples/output//xls-files-to-xml_20190129_174207
5.将 iOS strings 文件转换成 android xml 文件
$ python python/Strings2Xml.py -f examples/ios/en.lproj/ -t examples/output/
options: {'fileDir': 'examples/ios/en.lproj/', 'targetDir': 'examples/output/', 'additional': None}, args: []
Creating android file:examples/output//strings-files-to-xml_20190129_164122/Localizable.xml
Creating android file:examples/output//strings-files-to-xml_20190129_164122/InfoPlist.xml
Convert successfully! you can see xml files in examples/output//strings-files-to-xml_20190129_164122
不是那么懂Python的兄弟们注意
1.Python 版本必须是2.**
2.要转换的多语言文件要替换 Localizable.strings2Exce 里面对应的文件
最后感谢作者:CatchZeng,如涉及侵权请告知删帖。