Corona – An approach to translations
This post outlines the approach I used to deal with translations in my game “Brain Distraction” using Corona. I wanted to create an approach that;
- Enabled me to easily update translations.
- Could be easily scaled if I decided to add more languages.
- Could be used across different projects.
What I ended with was a Google Sheet that you can easily add columns to for each translation and a small app that takes the CSV generated from this spreadsheet and produces a module that can be included in your project.
If you are interested in using my solution, below is a step by step guide of how it can be achieved.
1. Create a copy of the following Google Sheet
2. Update the sheet with your translations.
Description – Description of what the phrase/word is, helpful if you share the spreadsheet with someone.
Include – Should the phrase/word be included in the output file. In the example above I also have translations for the store listing, I don’t want this information included.
Word/Phrase – The actual phrase/word that is being translated. This needs to be the exact same phrase that will be displayed in your app.
“Chinese”, “Korean” etc – The translations. You can create as many columns as you need e.g. the example spread sheet has 3 different translations (these were generated using Google Translate, so if they may not be accurate).
- Row 1 – The text displayed in Row 1 of these columns will be the text that is used in the output file for commenting purposes.
- Row 2 – This is the code that will be used in the output file to select the appropriate translation.
3. Download the spreadsheet as a CSV file.
One of the things that makes Google Sheets useful is the ability to share your work with other people and work collaboratively with them. This means you could share your spreadsheet with someone else and easily have them translate your work. You can even lock the sheet so that certain people can only edit certain parts of the document i.e. the person translating the Chinese can only access the Chinese column and the same for the Korean translator etc..
Video link: https://youtu.be/uK-pgmvl_8Y
4. Download the Corona App
You can download the zip file “CSVToTable.zip” containing the app from here https://github.com/riceburgerlabs/CSVtoTable. This tutorial does not cover the code itself. I believe the code should be commented enough, but if you have any questions please ask.
5. Copy the CSV file to the apps folder.
6. Edit main.lua of the app
Edit line 132 so that it is using the correct filename.
-- call main function
readCSVtoTable("For Example - All.csv") -- change this line so it points correctly to the CSV file
7. Run the program.
If the program runs correctly then you should see the following screen.
8. Click on “Show Project Sandbox”
9. Copy the output file from the “Documents” directory to your project.
You can download the zip file “TranslationExample.zip” which contains a working example here https://github.com/riceburgerlabs/CSVtoTable.
10. Require the file
In your project, require the file at the top of each file where you need to include a translation.
-- Require the translation file
local t = require("translation")
11. Translate your text
Use the “t” method of the file you required to translate the text. The text you pass across needs to be exactly the same as the text you included in the original Google Sheet.
t.t("Text to be translated goes here")
-- Display text on the screen. Text will be translated if a translation exists
local nameText = display.newText( t.t("What is your name?"), centerX, 100, native.systemFont, 16 )
local ageText = display.newText( t.t("How old are you?"), centerX, 200, native.systemFont, 16 )
12. Video showing it in action
Download Code – https://github.com/riceburgerlabs/CSVtoTable
Google Sheet – https://docs.google.com/spreadsheets/d/1w0mIvjB1IaWndKN_f3U4RrVjiLrRrHBSYJMWS7y05pA/edit?usp=sharing
Video in action – https://youtu.be/N2X4FMTBIr4