1 package be
.nikiroo
.jvcard
.resources
;
3 import java
.util
.Locale
;
4 import java
.util
.ResourceBundle
;
7 * This class help you get UTF-8 bundles for this application.
12 public class Bundles
{
13 static private String confDir
= getConfDir();
15 // TODO: create "Trans" like classes for all .properties file, always get it
16 // them from here, including Trans (create a new one each time like
17 // currently) + update Main to call trans again when chaning dir
21 * Return the non-localised bundle of the given name.
24 * the name of the bundle to load
28 static public ResourceBundle
getBundle(String name
) {
29 return ResourceBundle
.getBundle(Bundles
.class.getPackage().getName()
30 + "." + name
, new FixedResourceBundleControl(confDir
));
34 * Return the localised bundle of the given name and {@link Locale}.
37 * the name of the bundle to load
39 * the {@link Locale} to use
41 * @return the localised bundle
43 static public ResourceBundle
getBundle(String name
, Locale locale
) {
44 return ResourceBundle
.getBundle(Bundles
.class.getPackage().getName()
45 + "." + name
, locale
, new FixedResourceBundleControl(confDir
));
49 * Set the primary configuration directory to look for <tt>.properties</tt>
52 * All {@link ResourceBundle}s returned by this class after that point will
53 * respect this new directory.
58 static public void setDirectory(String confDir
) {
59 Bundles
.confDir
= confDir
;
63 * Return the configuration directory where to try to find the
64 * <tt>.properties</tt> files in priority.
66 * @return the configuration directory
68 static private String
getConfDir() {
69 // Do not override user-supplied config directory (see --help)
70 if (Bundles
.confDir
!= null)
71 return Bundles
.confDir
;
74 ResourceBundle bundle
= ResourceBundle
.getBundle(Bundles
.class
75 .getPackage().getName() + "." + "jvcard",
76 Locale
.getDefault(), new FixedResourceBundleControl(null));
78 String configDir
= bundle
.getString("CONFIG_DIR");
79 if (configDir
!= null && configDir
.trim().length() > 0)
81 } catch (Exception e
) {