I was working at Rentalia
were we used 7 languages in the mobile application and also in the web. So the process of translating those languages and embed them into the app wasn’t automatic, in fact it was done manually when I’ve arrived. They were using a CSV file where we could find all of the translated text and then the values were created in the app, copy pasting. Yes, what? are we from the past? this was prone errors, and also we were developing an Android app at the same time which would require to add them into an XML file (ewww)
So, why are we developers and engineers? and lazy ones too? to automate things of course, doh!
Obviously, I’ve searched the web to see if someone have had the same problem. I found nothing, at least open source. So yeah, next step was build it by myself.
We needed to have the text in a CSV and we also needed to support plurals files:
iOS
CSV
-> .strings o .stringsDict
Android
CSV -> .xml
So I thought this was a good time to apply the little I knew of JavaScript and learn more at the same time.
What I did?
I used Node.js and Express.js to build it. It takes a CSV file as input, but this CSV must have certain structure for the programm to work.
- We will need a column header for the key that we’ll use later to refer to the translated text inside the application. Always as lower case.
- Another column for each language, in his ISO code. For example, for english is EN, for spanish ES. Always in capital letters.
- If we need to add variables, we need to specify the type and they need to be between double asterisk, for example: The user is **ld** years old
Type | Wildcard |
---|---|
String | s |
Double | d |
Long Double | ld |
Float | f |
- Also it support scaping symbols if we need them adding a % before the symbol.
Symbol | Escaping |
---|---|
20% | **ld**% |
- Having plurals is the other supported feature. We just need to add a new column with the header PLS and now the KEY will have the different plural types
PLS | KEY | EN | ES |
---|---|---|---|
app_people | one | **ld** traveller | **ld** viajero |
app_people | other | **ld** travellers | **ld** viajeros |
app_night | one | **ld** night | **ld** noche |
app_night | other | **ld** nights | **ld** noches |
Basically that’s about it.
To check the app, this is the github repository:
https://github.com/rentalia/honyaku
If you want to use it, go ahead! it’s free. Just leave a comment on the blog to know it works for you.