移动端APP 多语言文件格式转换 Localizable.strings2Excel 的使用

最近在做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,如涉及侵权请告知删帖。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
创建多语言本地化的步骤如下: 1. 确保你已经在项目设置中添加了需要本地化的语言。可以在项目的Info选项卡中,选择Localizations,然后点击"+"按钮,添加需要本地化的语言。 2. 在Xcode中找到需要本地化的文字、图片等资源文件,将其提取为可本地化字符串。 3. 使用NSLocalizedStringFromTable函数来为每个需要本地化的字符串创建一个特定的本地化文件。这个函数的参数包括字符串的键值、本地化表名和注释。本地化表名可以是你自己命名的,不必使用系统默认的"Localizable.strings"文件名。 4. 在项目中创建一个名为"Localizable.strings"的文件,用于存储字符串的本地化翻译。你可以为每种语言创建一个对应的本地化文件,命名规则为"Localizable.strings"加上对应的语言标识后缀。例如,"Localizable.strings"可以是英文的本地化文件,"Localizable.strings"可以是法语的本地化文件。 5. 在每个本地化文件中,使用键值对的方式将原始字符串和翻译后的字符串对应起来。例如,"key"="value",其中"key"是原始字符串的键值,"value"是对应语言的翻译字符串。 6. 重复步骤4和步骤5,为每种语言创建一个对应的本地化文件,并在其中添加相应的翻译。 7. 在代码中使用 NSLocalizedStringFromTable 函数来获取本地化后的字符串。这个函数会根据用户的语言设置自动加载对应的本地化文件,并返回相应的翻译字符串。 通过以上步骤,你可以创建多语言本地化,使你的应用程序能够适应不同语言的用户需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iOS首席贴膜师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值