Commit | Line | Data |
---|---|---|
a3b510ab NR |
1 | package be.nikiroo.jvcard.i18n; |
2 | ||
3 | import java.util.HashMap; | |
4 | import 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 | */ | |
13 | public 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 { | |
bcb54330 NR |
26 | DUMMY, // <-- TODO : remove |
27 | KEY_ACTION_BACK, KEY_ACTION_HELP, // MainWindow | |
28 | KEY_ACTION_VIEW_CARD, // FileList | |
29 | KEY_ACTION_VIEW_CONTACT, KEY_ACTION_EDIT_CONTACT, KEY_ACTION_SAVE_CARD, KEY_ACTION_DELETE_CONTACT, KEY_ACTION_SWITCH_FORMAT, // ContactList | |
30 | NULL; // Special usage | |
a3b510ab NR |
31 | |
32 | public String trans() { | |
33 | return Trans.getInstance().trans(this); | |
34 | } | |
35 | }; | |
36 | ||
37 | /** | |
38 | * Get the (unique) instance of this class. | |
39 | * | |
40 | * @return the (unique) instance | |
41 | */ | |
42 | static public Trans getInstance() { | |
43 | synchronized (lock) { | |
44 | if (instance == null) | |
45 | instance = new Trans(); | |
46 | } | |
47 | ||
48 | return instance; | |
49 | } | |
50 | ||
51 | public String trans(StringId stringId) { | |
52 | if (map.containsKey(stringId)) { | |
53 | return map.get(stringId); | |
54 | } | |
55 | ||
56 | return stringId.toString(); | |
57 | } | |
58 | ||
59 | private Trans() { | |
60 | map = new HashMap<StringId, String>(); | |
61 | ||
62 | // TODO: get from a file instead? | |
63 | map.put(StringId.NULL, ""); | |
0b0b2b0f | 64 | map.put(StringId.DUMMY, "[dummy]"); |
a3b510ab | 65 | map.put(StringId.KEY_ACTION_BACK, "Back"); |
bcb54330 NR |
66 | map.put(StringId.KEY_ACTION_HELP, "Help"); |
67 | map.put(StringId.KEY_ACTION_VIEW_CONTACT, "Open"); | |
68 | map.put(StringId.KEY_ACTION_VIEW_CARD, "Open"); | |
69 | map.put(StringId.KEY_ACTION_EDIT_CONTACT, "Edit"); | |
70 | map.put(StringId.KEY_ACTION_DELETE_CONTACT, "Delete"); | |
0b0b2b0f | 71 | map.put(StringId.KEY_ACTION_SWITCH_FORMAT, "Change view"); |
a3b510ab NR |
72 | } |
73 | } |