1 package be
.nikiroo
.jvcard
.i18n
;
3 import java
.util
.HashMap
;
6 import com
.googlecode
.lanterna
.input
.KeyStroke
;
8 import be
.nikiroo
.jvcard
.tui
.UiColors
;
11 * This class manages the translation of {@link Trans#StringId}s into
12 * user-understandable text.
18 static private Object lock
= new Object();
19 static private Trans instance
= null;
21 private Map
<StringId
, String
> map
= null;
24 * An enum representing information to be translated to the user.
29 public enum StringId
{
30 DUMMY
, // <-- TODO : remove
31 KEY_ACTION_BACK
, KEY_ACTION_HELP
, // MainWindow
32 KEY_ACTION_VIEW_CARD
, // FileList
33 KEY_ACTION_VIEW_CONTACT
, KEY_ACTION_EDIT_CONTACT
, KEY_ACTION_SAVE_CARD
, KEY_ACTION_DELETE_CONTACT
, KEY_ACTION_SEARCH
, // ContactList
34 DEAULT_FIELD_SEPARATOR
, DEAULT_FIELD_SEPARATOR_NOUTF
, // MainContentList
35 KEY_ACTION_INVERT
, KEY_ACTION_FULLSCREEN
, // ContactDetails
36 KEY_ACTION_SWITCH_FORMAT
, // multi-usage
37 NULL
; // Special usage
39 public String
trans() {
40 return Trans
.getInstance().trans(this);
45 * Get the (unique) instance of this class.
47 * @return the (unique) instance
49 static public Trans
getInstance() {
52 instance
= new Trans();
59 * Translate the given {@link StringId} into user text.
64 * @return the translated text
66 public String
trans(StringId stringId
) {
67 StringId id
= stringId
;
68 if (!UiColors
.getInstance().isUnicode()) {
70 id
= StringId
.valueOf(stringId
.toString() + "_NOUTF");
71 } catch (IllegalArgumentException iae
) {
72 // no special _NOUTF version found
76 if (map
.containsKey(id
)) {
84 * Translate the given {@link KeyStroke} into a user text {@link String} of
88 * the key to translate
90 * @return the translated text
92 public String
trans(KeyStroke key
) {
95 switch (key
.getKeyType()) {
97 if (UiColors
.getInstance().isUnicode())
103 if (UiColors
.getInstance().isUnicode())
110 keyTrans
= " " + key
.getCharacter() + " ";
113 keyTrans
= "" + key
.getKeyType();
115 if (keyTrans
.length() > width
) {
116 keyTrans
= keyTrans
.substring(0, width
);
117 } else if (keyTrans
.length() < width
) {
119 + new String(new char[width
- keyTrans
.length()])
129 map
= new HashMap
<StringId
, String
>();
131 // TODO: get from a file instead?
132 map
.put(StringId
.NULL
, "");
133 map
.put(StringId
.DUMMY
, "[dummy]");
134 // we could use: " ", "┃", "│"...
135 map
.put(StringId
.DEAULT_FIELD_SEPARATOR
, "┃");
136 map
.put(StringId
.DEAULT_FIELD_SEPARATOR_NOUTF
, "|");
137 map
.put(StringId
.KEY_ACTION_BACK
, "Back");
138 map
.put(StringId
.KEY_ACTION_HELP
, "Help");
139 map
.put(StringId
.KEY_ACTION_VIEW_CONTACT
, "Open");
140 map
.put(StringId
.KEY_ACTION_VIEW_CARD
, "Open");
141 map
.put(StringId
.KEY_ACTION_EDIT_CONTACT
, "Edit");
142 map
.put(StringId
.KEY_ACTION_DELETE_CONTACT
, "Delete");
143 map
.put(StringId
.KEY_ACTION_SWITCH_FORMAT
, "Change view");
144 map
.put(StringId
.KEY_ACTION_INVERT
, "Invert colours");
145 map
.put(StringId
.KEY_ACTION_FULLSCREEN
, "Fullscreen");
146 map
.put(StringId
.KEY_ACTION_SEARCH
, "Search");