Rosetta

Posted by GrahamRanson, Posted on January 4, 2011, Last updated August 27, 2011

8 votes
GitHub URL: 
https://github.com/GrahamRanson/Rosetta

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"
}

More info and the download can be found here - http://grahamranson.co.uk/lib.php?id=3

Compatibility: 
Corona 2.0


Replies

Dotnaught's picture
Dotnaught
User offline. Last seen 3 days 3 hours ago. Offline
Joined: 7 Jul 2009

Thanks, Graham. Very useful.

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

Hope it helps :-)

0x90
User offline. Last seen 1 day 14 hours ago. Offline
Joined: 19 Oct 2010

Exactly what I was looking for.
Thank you very much for sharing.

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

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.

elgenaro's picture
elgenaro
User offline. Last seen 23 weeks 3 days ago. Offline
Joined: 9 Apr 2011

Hi Graham, thanks a lot for this! :)

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

You're most welcome!

fstrudelbenoit's picture
fstrudelbenoit
User offline. Last seen 1 week 5 days ago. Offline
Joined: 27 May 2011

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

indiegamepod
User offline. Last seen 1 day 8 hours ago. Offline
Joined: 16 Dec 2010

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")

with
1
local contents = loadFileContents(name .. ".settings")

Enjoy :)

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

Thanks for fixing that! When building for Android does it ignore certain file extensions?

anzask
User offline. Last seen 40 weeks 8 hours ago. Offline
Joined: 1 Jun 2011

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.

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

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

anzask
User offline. Last seen 40 weeks 8 hours ago. Offline
Joined: 1 Jun 2011

Thanks much for your quick response. i will check the leads.

rene9
User offline. Last seen 38 weeks 3 days ago. Offline
Joined: 15 Jun 2011

Anyone know where the source for this went ?

Seems very useful but also unavailable.

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

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.

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

It is now hosted on GitHub - https://github.com/GrahamRanson/Rosetta

@RSCdev's picture
@RSCdev
User offline. Last seen 1 hour 42 min ago. Offline
Joined: 6 Sep 2011

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.

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

No worries, just ask away if you have any questions.

Mitaten
User offline. Last seen 3 hours 27 min ago. Offline
Joined: 11 Jan 2011

Looks awesome! Thanks for sharing it!

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

You're very welcome!

sebitttas's picture
sebitttas
User offline. Last seen 16 hours 27 min ago. Offline
Joined: 17 Jan 2011

How would I display it on text for the language instead of in print on the terminal

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010
AndyDev's picture
AndyDev
User offline. Last seen 2 weeks 2 days ago. Offline
Joined: 8 Dec 2011

Amazing module! But how I can switch language automatically, without any buttons?

GrahamRanson's picture
GrahamRanson
User offline. Last seen 6 days 8 hours ago. Offline
Joined: 29 Mar 2010

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.

pgutierrez
User offline. Last seen 1 week 2 days ago. Offline
Joined: 28 Mar 2012

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!

rdytmire
User offline. Last seen 3 days 1 hour ago. Offline
Joined: 11 Apr 2012

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).