txt2xml is a python script for converting an Excel table to strings.xml
file in Android. An Excel table is easy to manage the translations of strings while strings.xml
is used by Android system to get the strings.
Let's say we have an Excel table as bellow:
zh | fr | es | de | |
Main.MenuShowHistory | 历史 | Historique | Historial | Verlauf |
Main.MenuShowDownloads | 下载 | Téléchargements | Descargas | Downloads |
Main.MenuPreferences | 配置 | Préférences | Preferencias | Einstellungen |
PreferencesActivity.EnableJavascriptPreferenceSummary | 如果不支持JavaScript,很多网站效果不能打开,建议打开. | Active ou désactive le JavaScript. | Activar o desactivar JavaScript. | JavaScript ein-/ausschalten. |
Note: The contents in first row of the table are language shortcode. The contents in first column of other rows are the name of strings in Android.
Save the table as a Unicode text(*.txt)
file, for example, strings.txt
.
Run the script:
python txt2xml.py strings.txt
Now, you will see it automatically created four new directories(values-zh/
, values-fr/
, values-es/
, values-de/
) with a separate strings.xml
inside.
The contents of strings.xml
in values-zh/
:
<?xml version="1.0" ?>
<resources>
<string name="Main.MenuShowHistory">历史</string>
<string name="Main.MenuShowDownloads">下载</string>
<string name="Main.MenuPreferences">配置</string>
<string name="PreferencesActivity.EnableJavascriptPreferenceSummary">如果不支持JavaScript,很多网站效果不能打开,建议打开.</string>
</resources>