app国际化多语言strings.xml 与 Excel 互相转换的工具,支持iOS和Android

国际化多语言转换工具

方案介绍

当项目涉及到多语言国际化的时候,我们需要把string.xml翻译成其他国家语言,一般翻译公司会需要excel等格式文档,可是这翻译文件实在是不好整,幸好有大神做了个py工具实现 string文件转excel.

目前有两种方式:

  1. Localizable.strings2Excel (下载源码,然后在终端输入命令跑脚本进行文件转换)
    作者:CatchZeng,https://github.com/CatchZeng/Localizable.strings2Excel

  2. LocalizableTool(可视化工具,支持strings.xml 与 Excel 互相转换)
    作者:ParfoisMeng,https://github.com/ParfoisMeng/LocalizableTool
    这个图形化可视化工具的脚本代码也是来自CatchZeng大神的Localizable.strings2Excel项目。

方案1 – Localizable.strings2Excel 脚本工具

支持:

  • iOS 本地化文件(.strings)与 Excel 互相转换
  • Android 的 strings.xml 与 Excel 互相转换
  • iOS 本地化文件(.strings)转换成 android 的 strings.xml 文件

特性

  • 支持将 iOS strings 文件转换成 excel 文件
  • 支持将 excel 文件转换成 iOS strings 文件
  • 支持将 android xml 文件转换成 excel 文件
  • 支持将 excel 文件转换成 android xml 文件
  • 支持将 iOS strings 文件转换成 android xml 文件

当前版本

V1.0.0

所需环境

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/pip/2.7/get-pip.py -o get-pip.py
sudo python get-pip.py

3.安装 pyexcelerator

sudo pip install pyExcelerator

4.安装 xlrd

sudo pip install xlrd

使用说明

1. 下载Localizable.strings2Excel 源码到电脑

下载地址:https://github.com/CatchZeng/Localizable.strings2Excel
下载好源码后,切换到该项目目录下打开命令行终端。

2.将 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

3.将 excel 文件转换成 iOS strings 文件

python python/Xls2Strings.py -f examples/output/strings-files-to-xls_20190129_165830/ -t examples/output/

执行结果:

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

4.将 android xml 文件转换成 excel 文件

python python/Xml2Xls.py -f examples/android/ -t examples/output

执行结果
Start convertingConvert examples/ios/ successfully! you can see xls file in examples/output/strings-files-to-xls_20190129_165830

5.将 excel 文件转换成 android xml 文件

python python/Xls2Xml.py -f examples/output/xml-files-to-xls_20220217_101250/ -t examples/output/

执行结果:
在这里插入图片描述

6.将 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

方案2 – Localizable Tool 使用说明

Android 开发国际化可视化工具,可将 strings.xml 与 Excel 互相转换。

  1. 核心 Python 脚本代码来自 Github 开源项目 Localizable.strings2Excel ,在其基础上做了一定的修改以适配 Python3。
  2. 可视化界面使用 PyQt5 编写。
  3. 本工具的开发是边学边写,所以内部代码写的很渣。

下载:releases


页面说明

App截图

上图各标识点说明:

  1. 选择是 Xml2Xls(strings.xml转Excel) 还是 Xls2Xml(Excel转strings.xml) ,默认为前者。
  2. 选择源文件夹。如果是 Xml2Xls 则选择来源的 Xml 相关文件夹路径(应包含 values/values-en 等文件夹),如果是 Xls2Xml 则选择来源的 Excel 相关文件夹路径(应包含一个或多个文件夹)。
  3. 选择目标文件夹。如果是 Xml2Xls 则选择生成目标 Excel 的路径,如果是 Xls2Xml 则选择生成目标 Xml 的路径。
  4. 选择 Single(单文件) 还是 Multiple(多文件) 模式。Xml2Xls 在 Single 模式下会生成以语种为列名的单个 Excel 文件,在 Multiple 模式下会生成对应语种的多个 Excel 文件;Xls2Xml 与 Xml2Xls 对应,Single 模式需要选择以语种为列名的单个 Excel 文件,Multiple 需要选择对应语种的多个 Excel 文件。
  5. 生成的脚本语言。使用此可视化工具时可以不用关注。
  6. 复制 5 中的脚本语言到剪贴板。使用此可视化工具时可以不用关注。
  7. 执行转换。

结论

  • 第一个方案 功能最全,iOS和Android都支持,但是上手稍微复杂一点,需要下载源码并且在终端输命名跑脚本。iOS多语言文件转换推荐方案一
  • 第二种是图形化软件,傻瓜式操作,但是只支持安卓的 string和excel互转。安卓的多语言文件转换推荐方案二

猜你喜欢

转载自blog.csdn.net/Jackson_Wen/article/details/122978037