New launcher class to start all 3 modes:
[jvcard.git] / src / be / nikiroo / jvcard / resources / Bundles.java
CommitLineData
2a96e7b2
NR
1package be.nikiroo.jvcard.resources;
2
3import java.util.Locale;
4import java.util.ResourceBundle;
5
6/**
7 * This class help you get UTF-8 bundles for this application.
8 *
9 * @author niki
10 *
11 */
12public class Bundles {
7f82bf68
NR
13 static private String confDir = getConfDir();
14
7da41ecd
NR
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
1c03abaf
NR
18 private int TODO;
19
2a96e7b2
NR
20 /**
21 * Return the non-localised bundle of the given name.
22 *
23 * @param name
24 * the name of the bundle to load
25 *
26 * @return the bundle
27 */
28 static public ResourceBundle getBundle(String name) {
29 return ResourceBundle.getBundle(Bundles.class.getPackage().getName()
7f82bf68 30 + "." + name, new FixedResourceBundleControl(confDir));
2a96e7b2
NR
31 }
32
33 /**
34 * Return the localised bundle of the given name and {@link Locale}.
35 *
36 * @param name
37 * the name of the bundle to load
38 * @param locale
39 * the {@link Locale} to use
40 *
41 * @return the localised bundle
42 */
43 static public ResourceBundle getBundle(String name, Locale locale) {
2a96e7b2 44 return ResourceBundle.getBundle(Bundles.class.getPackage().getName()
7f82bf68 45 + "." + name, locale, new FixedResourceBundleControl(confDir));
2a96e7b2 46 }
7f82bf68
NR
47
48 /**
49 * Set the primary configuration directory to look for <tt>.properties</tt>
50 * files in.
51 *
52 * All {@link ResourceBundle}s returned by this class after that point will
53 * respect this new directory.
54 *
55 * @param confDir
56 * the new directory
57 */
58 static public void setDirectory(String confDir) {
59 Bundles.confDir = confDir;
60 }
61
62 /**
63 * Return the configuration directory where to try to find the
64 * <tt>.properties</tt> files in priority.
65 *
66 * @return the configuration directory
67 */
68 static private String getConfDir() {
69 // Do not override user-supplied config directory (see --help)
70 if (Bundles.confDir != null)
71 return Bundles.confDir;
72
73 try {
74 ResourceBundle bundle = ResourceBundle.getBundle(Bundles.class
75 .getPackage().getName() + "." + "jvcard",
76 Locale.getDefault(), new FixedResourceBundleControl(null));
77
78 String configDir = bundle.getString("CONFIG_DIR");
79 if (configDir != null && configDir.trim().length() > 0)
80 return configDir;
81 } catch (Exception e) {
82 }
83
84 return null;
85 }
86
2a96e7b2 87}