Android多国语言转换Excel及Excel转换为string详解
作者:夏至的稻穗 时间:2022-10-30 08:07:02
前言
在实际的开发中,当我们完成了一个apk,一般都是英语和中文简体这两种语语言,如果发布了,则需要把字符转换给翻译公司,让他们帮忙翻译,一般提供一个 Excel 表格,如下:
当翻译完成之后,我们希望能把它快速转换成 value-xx 文件下对应的 string 或者 arrays ,如:
我只要复制粘贴即可。当然网上也有很多大神用 Python 或者其他语言写了,但是我们用 Android 的,所以肯定用 Java 了。于是我写了个 EasyTransLib 用来方便翻译。因为 studio 对 pc 端的支持并友好,所以这个工程是用 eclipse 开发。
工程如下:https://github.com/LillteZheng/EasyTranalte
String 转换成 Excel
首先,在工程的根目录,写一个文件夹,比如 Test:
values 比较简单,就一个 string 和 arrays ,目前也就支持这两个。
其中 strings 如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">OtaService</string>
<string name="anim_time">200</string>
<string name="system_update">System upgrade</string>
<string name="check_new_version">Find a new version. Download it?</string>
</resources>
arrays 如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="test_array">
<item>one</item>
<item>two</item>
<item>three</item>
</string-array>
<string-array name="test2_array">
<item>hour</item>
<item>min</item>
<item>second</item>
</string-array>
</resources>
开始转换
找到工程下的 WriteXmlToXls
需要添加 文件夹的名字:
效果如下 gif 图:
刷新一下,就会看到生成 string 和 arrays strings
arrays
arrays 的样式丑了点,但这都是为了接下来住转换 strings 准备的。
Excel 转 strings.xml 和 arrays
上面,我们已经把 strings 和 arrays 转换成 Excel 了,那么接下来就是对 Excel 传承我们最喜欢 的string 和 arrays 了。
把 test.xlsx 的 strings 添加多几个字符,和新增一个中文繁体的
其中首行的 国家名称必须写,否则无法识别成对应的文件夹的名称
arrays 也加一个:
然后把 test.xlsl 放在根目录下,并找到 ReadXlsToXml 这个类
ReadXlsToXml 可以配置一些信息:
看下面的 动图:
按 F5 刷新一下,就可以看到 也生成了 value-zh-rTW 的繁体字符了。
来源:https://juejin.im/post/5c37120551882525a50bc0dc
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
AJAX中Get请求报错404的原因以及解决办法
![](https://img.aspxhome.com/file/2023/2/67442_0s.jpg)
c# 类成员的可访问性代码详解
![](https://img.aspxhome.com/file/2023/8/87018_0s.png)
Android 自定义dialog的实现代码
![](https://img.aspxhome.com/file/2023/3/137893_0s.jpg)
Android Monkey压力测试详细介绍
![](https://img.aspxhome.com/file/2023/0/137790_0s.png)
Winform控件优化之圆角按钮1
![](https://img.aspxhome.com/file/2023/2/106402_0s.png)
java实现打砖块小游戏
C#实现航班预订系统
![](https://img.aspxhome.com/file/2023/5/70445_0s.jpg)
C# 生成随机数的代码
Java中的装箱和拆箱深入理解
![](https://img.aspxhome.com/file/2023/1/115981_0s.png)
OpenGL Shader实现阴影遮罩效果
![](https://img.aspxhome.com/file/2023/2/137822_0s.jpg)
Android自定义ViewGroup实现淘宝商品详情页
![](https://img.aspxhome.com/file/2023/5/125415_0s.gif)
c#创建Graphics对象的三种方法
JVM类加载机制原理及用法解析
![](https://img.aspxhome.com/file/2023/3/68173_0s.jpg)
解析JAVA深度克隆与浅度克隆的区别详解
springboot结合websocket聊天室实现私聊+群聊
![](https://img.aspxhome.com/file/2023/9/67609_0s.jpg)
Java发送post方法详解
通过FancyView提供 Android 酷炫的开屏动画实例代码
![](https://img.aspxhome.com/file/2023/4/139494_0s.gif)
RocketMQ NameServer架构设计启动流程
![](https://img.aspxhome.com/file/2023/8/80938_0s.png)
Android中通知栏跳动问题解决方法
Unity2D实现游戏回旋镖
![](https://img.aspxhome.com/file/2023/8/66118_0s.gif)