Improve UI, take "dirty" check into account, move launcher to Main.java
[jvcard.git] / src / be / nikiroo / jvcard / i18n / Trans.java
CommitLineData
a3b510ab
NR
1package be.nikiroo.jvcard.i18n;
2
3import java.util.HashMap;
4import java.util.Map;
5
6/**
7 * This class manages the translation of {@link Trans#StringId}s into
8 * user-understandable text.
9 *
10 * @author niki
11 *
12 */
13public class Trans {
14 static private Object lock = new Object();
15 static private Trans instance = null;
16
17 private Map<StringId, String> map = null;
18
19 /**
20 * An enum representing information to be translated to the user.
21 *
22 * @author niki
23 *
24 */
25 public enum StringId {
0b0b2b0f
NR
26 DUMMY, // <-- TODO : remove
27 KEY_ACTION_BACK, KEY_ACTION_HELP, KEY_ACTION_VIEW_CONTACT, KEY_ACTION_VIEW_CARD, KEY_ACTION_EDIT_CONTACT, KEY_ACTION_SWITCH_FORMAT, NULL;
a3b510ab
NR
28
29 public String trans() {
30 return Trans.getInstance().trans(this);
31 }
32 };
33
34 /**
35 * Get the (unique) instance of this class.
36 *
37 * @return the (unique) instance
38 */
39 static public Trans getInstance() {
40 synchronized (lock) {
41 if (instance == null)
42 instance = new Trans();
43 }
44
45 return instance;
46 }
47
48 public String trans(StringId stringId) {
49 if (map.containsKey(stringId)) {
50 return map.get(stringId);
51 }
52
53 return stringId.toString();
54 }
55
56 private Trans() {
57 map = new HashMap<StringId, String>();
58
59 // TODO: get from a file instead?
60 map.put(StringId.NULL, "");
0b0b2b0f 61 map.put(StringId.DUMMY, "[dummy]");
a3b510ab 62 map.put(StringId.KEY_ACTION_BACK, "Back");
a3b510ab
NR
63 map.put(StringId.KEY_ACTION_VIEW_CONTACT, "view");
64 map.put(StringId.KEY_ACTION_EDIT_CONTACT, "edit");
0b0b2b0f 65 map.put(StringId.KEY_ACTION_SWITCH_FORMAT, "Change view");
a3b510ab
NR
66 }
67}