X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=inline;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fresources%2FBundles.java;h=e105b7117e64a6aed042b8c22adaf40919c2823a;hb=0b6140e4a200c4952c9dc003d8389f375191564e;hp=76c471f6efddda0ed97a6dddae6e99363a646ca0;hpb=2a96e7b2cf3f155cccc633272b2f547ffd8f4672;p=jvcard.git
diff --git a/src/be/nikiroo/jvcard/resources/Bundles.java b/src/be/nikiroo/jvcard/resources/Bundles.java
index 76c471f..e105b71 100644
--- a/src/be/nikiroo/jvcard/resources/Bundles.java
+++ b/src/be/nikiroo/jvcard/resources/Bundles.java
@@ -10,6 +10,12 @@ import java.util.ResourceBundle;
*
*/
public class Bundles {
+ static private String confDir = getConfDir();
+
+ // TODO: rename to bundle, use it as base for i18n.Trans, create one for
+ // each resource
+ private int TODO;
+
/**
* Return the non-localised bundle of the given name.
*
@@ -20,7 +26,7 @@ public class Bundles {
*/
static public ResourceBundle getBundle(String name) {
return ResourceBundle.getBundle(Bundles.class.getPackage().getName()
- + "." + name, new FixedResourceBundleControl());
+ + "." + name, new FixedResourceBundleControl(confDir));
}
/**
@@ -34,8 +40,47 @@ public class Bundles {
* @return the localised bundle
*/
static public ResourceBundle getBundle(String name, Locale locale) {
-
return ResourceBundle.getBundle(Bundles.class.getPackage().getName()
- + "." + name, locale, new FixedResourceBundleControl());
+ + "." + name, locale, new FixedResourceBundleControl(confDir));
+ }
+
+ /**
+ * Set the primary configuration directory to look for .properties
+ * files in.
+ *
+ * All {@link ResourceBundle}s returned by this class after that point will
+ * respect this new directory.
+ *
+ * @param confDir
+ * the new directory
+ */
+ static public void setDirectory(String confDir) {
+ Bundles.confDir = confDir;
}
+
+ /**
+ * Return the configuration directory where to try to find the
+ * .properties files in priority.
+ *
+ * @return the configuration directory
+ */
+ static private String getConfDir() {
+ // Do not override user-supplied config directory (see --help)
+ if (Bundles.confDir != null)
+ return Bundles.confDir;
+
+ try {
+ ResourceBundle bundle = ResourceBundle.getBundle(Bundles.class
+ .getPackage().getName() + "." + "jvcard",
+ Locale.getDefault(), new FixedResourceBundleControl(null));
+
+ String configDir = bundle.getString("CONFIG_DIR");
+ if (configDir != null && configDir.trim().length() > 0)
+ return configDir;
+ } catch (Exception e) {
+ }
+
+ return null;
+ }
+
}