Some changes to support Files
[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 {
9c8baf0c 26 KEY_ACTION_BACK, KEY_ACTION_HELP, KEY_ACTION_VIEW_CONTACT, KEY_ACTION_VIEW_CARD, KEY_ACTION_EDIT_CONTACT, KEY_ACTION_SWITCH_FORMAT, TITLE, NULL;
a3b510ab
NR
27
28 public String trans() {
29 return Trans.getInstance().trans(this);
30 }
31 };
32
33 /**
34 * Get the (unique) instance of this class.
35 *
36 * @return the (unique) instance
37 */
38 static public Trans getInstance() {
39 synchronized (lock) {
40 if (instance == null)
41 instance = new Trans();
42 }
43
44 return instance;
45 }
46
47 public String trans(StringId stringId) {
48 if (map.containsKey(stringId)) {
49 return map.get(stringId);
50 }
51
52 return stringId.toString();
53 }
54
55 private Trans() {
56 map = new HashMap<StringId, String>();
57
58 // TODO: get from a file instead?
59 map.put(StringId.NULL, "");
60 map.put(StringId.KEY_ACTION_BACK, "Back");
61 map.put(StringId.TITLE, "[ jVcard: version 0.9 ]");
62 map.put(StringId.KEY_ACTION_VIEW_CONTACT, "view");
63 map.put(StringId.KEY_ACTION_EDIT_CONTACT, "edit");
64 map.put(StringId.KEY_ACTION_SWITCH_FORMAT, "Change view");
65 }
66}