From: Lars G. <la...@wo...> - 2005-07-15 19:23:10
|
Hi, Has someone of you written a parser for standard Java properties files, ie. so we can use .properties files to read in as templates? I am interested to get a i18n framework going where the actual content is stored in properties files for easy localization. But I do not want to use the ResourceBundle framework of Java, which is clunky and a bit cumbersome. I rather would like to include those .properties directly into a template and have WebMacro parse it into context variables. For example: hello.wm: --------- #include "/res/$languagecode/hello.properties" Hello $msg1! hello.properties: ----------------- msg1=World This is very simple example, this could be extended to have the properties include figure out what is available and fall back to default file as performed by the ResourceBundle class, eg. #include-res "res/hello.properties" $languagecode Assume $languagecode="FR", then it would try to load and parse hello_fr.properties, if that is missing it is using hello.properties. The advantage is to rely on Webmacro for caching and reloads, while the ResourceBundle cannot reload files ones they are loaded. A parser could simply use a Properties class to read the file and add it to the context, even as a hashmap, so access would be like this $hello.msg1 or the include directive could allow for a name that is given to the hashmap. My main question is what to watch out for writing my own directive. Especially in terms of efficiency and caching. Any pointers? Thanks, Lars |