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_SWITCH_FORMAT
, // ContactList
34 DEAULT_FIELD_SEPARATOR
, DEAULT_FIELD_SEPARATOR_NOUTF
, // MainContentList
35 NULL
; // Special usage
37 public String
trans() {
38 return Trans
.getInstance().trans(this);
43 * Get the (unique) instance of this class.
45 * @return the (unique) instance
47 static public Trans
getInstance() {
50 instance
= new Trans();
57 * Translate the given {@link StringId} into user text.
62 * @return the translated text
64 public String
trans(StringId stringId
) {
65 StringId id
= stringId
;
66 if (!UiColors
.getInstance().isUnicode()) {
68 id
= StringId
.valueOf(stringId
.toString() + "_NOUTF");
69 } catch (IllegalArgumentException iae
) {
70 // no special _NOUTF version found
74 if (map
.containsKey(id
)) {
82 * Translate the given {@link KeyStroke} into a user text {@link String} of
86 * the key to translate
88 * @return the translated text
90 public String
trans(KeyStroke key
) {
93 switch (key
.getKeyType()) {
95 if (UiColors
.getInstance().isUnicode())
101 if (UiColors
.getInstance().isUnicode())
108 keyTrans
= " " + key
.getCharacter() + " ";
111 keyTrans
= "" + key
.getKeyType();
113 if (keyTrans
.length() > width
) {
114 keyTrans
= keyTrans
.substring(0, width
);
115 } else if (keyTrans
.length() < width
) {
117 + new String(new char[width
- keyTrans
.length()])
127 map
= new HashMap
<StringId
, String
>();
129 // TODO: get from a file instead?
130 map
.put(StringId
.NULL
, "");
131 map
.put(StringId
.DUMMY
, "[dummy]");
132 // we could use: " ", "┃", "│"...
133 map
.put(StringId
.DEAULT_FIELD_SEPARATOR
, "┃");
134 map
.put(StringId
.DEAULT_FIELD_SEPARATOR_NOUTF
, "|");
135 map
.put(StringId
.KEY_ACTION_BACK
, "Back");
136 map
.put(StringId
.KEY_ACTION_HELP
, "Help");
137 map
.put(StringId
.KEY_ACTION_VIEW_CONTACT
, "Open");
138 map
.put(StringId
.KEY_ACTION_VIEW_CARD
, "Open");
139 map
.put(StringId
.KEY_ACTION_EDIT_CONTACT
, "Edit");
140 map
.put(StringId
.KEY_ACTION_DELETE_CONTACT
, "Delete");
141 map
.put(StringId
.KEY_ACTION_SWITCH_FORMAT
, "Change view");