|
Tips
|
|
Written by Karel Broer | Wednesday, 16 June 2010 23:10
|
|
For some time a few developers (including me) were struggling getting i18n values, created in Servoy 5 developer into the (development) database.
Before Servoy 5, i18n keys were directly created in the database messages table, but since Servoy 5 the location of the keys changed to files in the eclipse workspace. So in order to get the i18n values into the database, an export and import of a solution was needed.
Too much hassle for me, so I made this little method .
Please login or register to see the full article |
Comments
On a proper ServoyForge perhaps?
@Patrick: Robert, already created such i18n db editor, polyglot I believe? It was one of his first projects on ServoyForge I believe!
Great tip!
Personally, I never use the Servoy build-in i18n editor, but do all the insert/updates directly in the database with my favorite DB admin (if you don't want to do that, building a simple interface for the i18n table is not that hard either in Servoy either). Then all I need to do is right-click on the I18N Resources node and choose 'Create from DB' - it takes no time.
But if you want to do it the other way around, your trick is nice indeed.
I would probably change one thing though:
instead of reading .properties files as Text files, I would use the java.util.Properties class this way:
// starting at line 35 (which is not necessary BTW):
file = x.getAbsolutePath ();
stream = new Packages.java.io.FileInputStream (new Packages.java.io.File(file));
props = new Packages.java.util.Properties();
props.load(stream);
// then loop over the properties:
enumeration = props.propertyNames() ;
while (enumeration.hasMoreElements ()) {
vKey = enumeration.nextElement();
vValue = props.getProperty(vKe y);
// then build your SQL
}
It looks a little bit more complicated but it is more efficient and more robust: because this way, even multi-line properties (you can also have that in a .properties file) will be loaded properly, and Unicode escaped characters (for example \u00E9 for 'é') will also be loaded properly (Properties file are by default iso-8859-1 - see the javadocs for details).
And I would try to do bulk inserts to get a better performance...
I'm sure there are loads of things we could do to make it perform like a snap! :)
But it is a very good basis, I'd even say it would be a good candidate module to put under SVN in a place where people could contribute to make it the i18n killer editor/reloader, don't you think?
RSS feed for comments to this post.