Rosetta is a very simple module that makes it easy to include multiple languages (or just one) in your app or game.
Languages are stored in external files which allow your designers/translators to edit them without requiring the help of a programmer.
Example usage
-- Load Rosetta local rosetta = require("rosetta").new() -- Initiate Rosetta - this will load all languages and settings rosetta:initiate() -- Print the value of "hello" from the current language (currently it is specified in language.settings as default) print(rosetta:getString("hello")) -- Change the language to french rosetta:setCurrentLanguage("french") -- Now print out hello again but in french print(rosetta:getString("hello")) -- Print out hello in german without changing the language print(rosetta:getString("hello", "german"))
Example language.settings file
{ "default":"english", "languages": [ "english", "french", "german" ] }
Example language file (english.language)
{ "hello":"Hello", "goodbye":"Goodbye" }
Example language file (french.language)
{ "hello":"Bonjour", "goodbye":"Au revoir" }
Hope it helps :-)
Exactly what I was looking for.
Thank you very much for sharing.
No problem! It's pretty basic but gets the job done. If there are any ideas you have for it I will gladly add them.
Hi Graham, thanks a lot for this! :)
You're most welcome!
When I build the sample application for android the language file does not seems to be attached to the .apk is there anything i need to do for those file to be attach ?
thanks
Hi,
The solution is to rename all the .langauge file to .settings files...
so
english.language
becomes
english.settings
french.language
becomes
french.settings
etc.
Then go into rosetta.lua and replace this line
1 | local contents = loadFileContents(name .. ".language") |
1 | local contents = loadFileContents(name .. ".settings") |
Enjoy :)
Thanks for fixing that! When building for Android does it ignore certain file extensions?
Useful stuff, thank you much for sharing.
I have an idea and I want to take further using this file.
How can I include sound and also be able to scroll from left to right (transition screen) and be able to press a "Play Sound" button?
If you can help, I will appreciate.
That's out of scope really for the purpose of Rosetta, what you will want to do is look into Audio - http://developer.anscamobile.com/reference/audio - Buttons - http://developer.anscamobile.com/content/button-events - and Director - http://developer.anscamobile.com/code/director-class-10
Thanks much for your quick response. i will check the leads.
Anyone know where the source for this went ?
Seems very useful but also unavailable.
Whoops my bad, I uploaded a new version of my site yesterday and forgot to put up the links to my libs. Will be updating today and will put the links back up. I will most likely upload it to GitHub.
It is now hosted on GitHub - https://github.com/GrahamRanson/Rosetta
Hey Graham,
Thank you so much for your nice work and PLUS sharing it with the Corona Community.
I am glad you have said about your Rosetta lib for localizations as it looks like "easy" to get into and also done! Am I right? ;)
PS: I`ll look into your lib and try to get it working out for my 4 languages translations. If I fall in trouble I may ask you help again. :)
Regards,
Rodrigo.
No worries, just ask away if you have any questions.
Looks awesome! Thanks for sharing it!
You're very welcome!
How would I display it on text for the language instead of in print on the terminal
This should do it - http://developer.anscamobile.com/content/displaynewtext
Amazing module! But how I can switch language automatically, without any buttons?
You could probably use the system.getPreference() function:
1 | system.getPreference( "locale", "language" ) |
Or
1 | system.getPreference( "ui", "language" ) |
You would need to associate the values returned from those functions to languages stored in Rosetta.
Hi!
I have a problem with rosetta,
In the simulator works, but when compiling for my android device 4 does not work. Displays a message "this application is corrupted"
I tried to compile only the original version of rosetta is to download but does not work either
Thank you very much!
I purchased LIME and will continue to support your ongoing efforts. More please! (I don't mind if you need to charge for your excellent efforts).
Thanks, Graham. Very useful.