I have a Java (JSF) web application that needs to be localized, including text, images and etc (numbers, dates). I'm trying to have programmers to only use
<h:graphicImage value="#{images['i_print.png']}" ... />
... and have the correct localized image automatically picked in the background, according to the user's locale.
One approach is to have resource bundles property files with different image paths for a certain image key. Is there a way this can be done without property files at all?
I mean.. the images directory having the following structure:
-Images
--en
---en_US
---en_CA
--fr
---fr_FR
Is it possible to create resource bundles where the lookup would go through the most localized directory first and going up the tree until the image name is found?
So far I have the following:
(1) An images handler.
<resource-bundle>
<base-name>com.example.ImageResourcesHandler</base-name>
<var>images</var>
</resource-bundle>
(2) The handler implementation, which extends resource bundle and handles the call by overriding getObject
public class ImageResourcesHandler extends ResourceBundle {
@Override
protected Object handleGetObject(String key) {...}
}
(3) An Images Control that extends ResourceBundle.Control and is supposed to the the BundleLoading and control
public class ImageControl extends ResourceBundle.Control { ... }
Right now I go through the images root directory and create a map with the names of images as the key and their path as values.
The problem is I don't have a Bundle structure, meaning that if I have the key in two different locales, my map clearly doesn't work (two+ paths are mapped to the same key).
Do you have any ideas on how to accomplish this? I wouldn't like to maintain properties files.
TL;DR: I would like to implement a mechanism that gets images according to the user's locale from the file system without using properties files.
Any ideas are highly appreciated. Thanks!