i18n

Since this discussion was taking place in the Android build thread, I've decided to create a topic instead of replying there as suggested.
Here's the start of the conversation if you'd like to follow along: http://www.slightlymagic.net/forum/viewtopic.php?f=26&t=14534&start=420#p156709
--
I did some work not too long ago on the Starbound Mod Manager (see here and here) that involved making sure the entire program could be localized easily. All anyone has to do to add a new language is translate the strings file and put in a pull request to add it to the repo.
To achieve this, I used icu4j. This class I wrote should be able to be copied almost verbatim to Forge to add the functionality, then all we'd need to do is find every place in the program that uses a hard coded string that's visible to the user and replace them with getMessage(key) or formatMessage(key, replacement values).
getMessage(...) in the code linked above grabs a String from the localizer and presents it as is (plus behind-the-scenes localization, of course).
formatMessage(...) works in much the same way String.format(...) does. It takes a string from the localizer and replaces temporary values with the arguments provided.
A sample localization file looks like this:
To use the first line, just use:
To use the second line, you'll need to use:
Finally, the third line also uses formatMessage(...), but it instead applies pluralization rules to the text based on the number given.
That would look like:
I'm sure you're all very bored with the above, but based on simplicity, I'd propose that we use icu4j for localization and I could add in the code to handle that in no time at all. We'd just need someone to go change everything else; I don't have time at the moment.
I'll be happy to be in charge of maintaining this feature, but I would like some help replacing the current code. If no one wants to, I'll get to it in a couple weeks or so—it depends on when I can get my housing situation sorted out.
Here's the start of the conversation if you'd like to follow along: http://www.slightlymagic.net/forum/viewtopic.php?f=26&t=14534&start=420#p156709
--
I did some work not too long ago on the Starbound Mod Manager (see here and here) that involved making sure the entire program could be localized easily. All anyone has to do to add a new language is translate the strings file and put in a pull request to add it to the repo.
To achieve this, I used icu4j. This class I wrote should be able to be copied almost verbatim to Forge to add the functionality, then all we'd need to do is find every place in the program that uses a hard coded string that's visible to the user and replace them with getMessage(key) or formatMessage(key, replacement values).
getMessage(...) in the code linked above grabs a String from the localizer and presents it as is (plus behind-the-scenes localization, of course).
formatMessage(...) works in much the same way String.format(...) does. It takes a string from the localizer and replaces temporary values with the arguments provided.
A sample localization file looks like this:
- Code: Select all
inputdialogue.starboundpath = Please locate your Starbound directory:
mod.badarchive = The file "{0}" could not be read correctly. Please see the log for more information.
mainview.addmods = Add {0, plural, one{Mod}other{Mods}}:
To use the first line, just use:
- Code: Select all
getMessage("inputdialogue.starboundpath");
To use the second line, you'll need to use:
- Code: Select all
formatMessage("mod.badarchive", "Example Mod") //Returns "The file "Example Mod" could not be read correctly. Please see the log for more information."
Finally, the third line also uses formatMessage(...), but it instead applies pluralization rules to the text based on the number given.
That would look like:
- Code: Select all
formatMessage("mainview.addmods", 1) //Add Mod:
formatMessage("mainview.addmods", 3) //Add Mods:
I'm sure you're all very bored with the above, but based on simplicity, I'd propose that we use icu4j for localization and I could add in the code to handle that in no time at all. We'd just need someone to go change everything else; I don't have time at the moment.
I'll be happy to be in charge of maintaining this feature, but I would like some help replacing the current code. If no one wants to, I'll get to it in a couple weeks or so—it depends on when I can get my housing situation sorted out.