We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Internationalization: I18n for Processing. UPDATED
Page Index Toggle Pages: 1
Internationalization: I18n for Processing. UPDATED (Read 2928 times)
Internationalization: I18n for Processing. UPDATED
Sep 15th, 2009, 1:38am
 
In today’s Internet world it is important to have your users pleased with language support for them. That’s Internatinalization, in a few letters: I18n there are 18 letters between the first “I” and the last “N“.

I18n for Processing is a java library for P5 aimed to integrating external ResourceBundle (.properties) files into your applications in order to be able to add multilanguage support to your Processing programs. The code was written by PhiLho while answering a question from me, here in the Processing Discourse.

After a while using the code in my app, I realized it could be encapsulated out of the sketch into a jar file and used as a Library in Processing Smiley

So I did.

I18n for Processing detects automatically the language of the computer your application is being executed on. I18n is recommended for those wishing to distribute their software in diferent languages in order to have more people testing or using their app.

You can catch it here >>>.

It's super easy to use and comes with two three flavors of constructor: basic, "custom" and advanced.

check it out and send some feedback, fixes, optimizations, they are most welcome Cheesy

Enjoy!

History:

Sep 15th, 2009, FIRST RELEASE.

Sep 16th, 2009, UPDATED TO VERSION 0.2

December 18th, 2009, Merry X-mas!!! UPDATED TO VERSION 0.3
Better encapsulation, bundled with useful and detailed Javadoc. Source code included.
Re: Internationalization: I18n for Processing.
Reply #1 - Sep 15th, 2009, 4:43am
 
Good idea to wrap that in a library. Thanks for doing the work for me! Wink Particularly the documentation process.

Some little suggestions:
- Put the library in a package, so we import com.0p0media.i18n.I18n; (for example) instead: it is cleaner and might reduce risks of clashes. (or just import com.0p0media.I18n; if you prefer and don't plan to have lot of libraries...).
- Remind in your Working with the ResourceBundle page that the properties files must be encoded in UTF-8. Perhaps change the name of this page, since ResourceBundle class is actually hidden... Smiley
- Note you can even put spaces at the start of the continuation lines (multiline strings), they are gobbled up.
- Maybe add an option to the I18n class to display the key instead of Xxx, like I did, as you often have incomplete translations (lagging behind current version of software) and giving the key might hint of the original meaning.
- You mention a folder called “Localization.properties”, I suppose it is a file, no?
- The fact the translations files are not packaged when exporting the application is only an half problem: most applications just give these files separately, allowing easier update (or editing) and selecting only the files useful to a user (no need to get dozens of languages when you really need a couple of them).
- Actually, in my sketch, the localization files in the data folder are packaged in the jar, so I wonder what problem you have. I will investigate. It would be useful at least for applets.
- It might be interesting, for flexibility, to expose a way to choose the locale (can be done with Locale.setDefault, though).
Re: Internationalization: I18n for Processing.
Reply #2 - Sep 15th, 2009, 8:01am
 
I haven't looked before about my hack working on applets or exported application. I knew the files being located in the data folder would be exported to jar, and I vaguely hoped Processing would automagically go there even in jar form, but I was wrong.
I needed an additional hack. Here is the modified class loader routine:
Code:
  public URL getResource(String name)
{
String textPath = m_pa.dataPath(name);
// System.out.println("getResource " + textPath);
File textFile = new File(textPath);
URL url = null;
if (textFile.exists())
{
try
{
url = textFile.toURI().toURL();
}
catch (java.net.MalformedURLException e)
{
System.out.println("ProcessingClassLoader - Incorrect path: " + textPath);
}
}
else
{
ClassLoader cl = getClass().getClassLoader();
url = cl.getResource("data/" + name);
// System.out.println("Using URL: " + url);
}
return url;
}

If the requested file cannot be physically found, I get the URL as a resource URL. Works fine in application on Windows and in applet form, although it looks like we need to sign the applet in order to use a class loader... Sad

Side note: I had an issue running the Windows application version. The problem was the application was stuck, not displaying a window nor console data.
Actually, the generated .exe just runs javaw.exe with the generated jars. I found a dumb workaround to see what is going, if somebody has a better idea, just share!
The workaround: go to C:\WINDOWS\system32, rename javaw.exe to javaw-.exe (for example) and java.exe to javaw.exe! Thus we force the generated .exe to run the console Java and we have standard output.
Re: Internationalization: I18n for Processing.
Reply #3 - Sep 15th, 2009, 11:28am
 
Thanks!

I'll work in your suggestions Smiley

I think I'll add the new ClassLoader code. But that of signing the applet kinda sucks...

I wish I was more experienced in this stuff Tongue

An update soon Smiley
Re: Internationalization: I18n for Processing.
Reply #4 - Sep 15th, 2009, 6:11pm
 
I worked in the Lib through the afternoon and added the new code and it works great, hoever there is a problem. Remember my app APL? it doesn't work in that project for some reason I don't know...

On other small sketches it imports the Bundles just perfect, but not in this huge project... weird... I'll see if I can find the problem. Help is welcome Smiley
Re: Internationalization: I18n for Processing.
Reply #5 - Sep 16th, 2009, 7:44pm
 
Uploaded an update, includes the new ClassLoader code, extended examples, source code and updated documentation in PDF format.

Enjoy:

http://0p0media.com/i18n

version 0.2, fixed import in the .jar file of .properties files for exported applications. not working for applets yet (at least on Windows XP). Under unknown circumstances, import into really large Processing applications can fail. EDIT: it works perfectly on application export Cheesy
Re: Internationalization: I18n for Processing. UPDATED
Reply #6 - Dec 18th, 2009, 7:37pm
 
Updated to version 0.3:

December 18th, 2009, Merry X-mas!!! UPDATED TO VERSION 0.3
Better encapsulation, bundled with useful and detailed Javadoc. Source code included.


I18n for P5, v0.3 >>>
Re: Internationalization: I18n for Processing. UPDATED
Reply #7 - Dec 27th, 2009, 5:20pm
 
You can now browse the SVN repository here:
http://i18np5library.svn.sourceforge.net/viewvc/i18np5library/
Page Index Toggle Pages: 1