X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fi18n%2FTrans.java;h=069f81ca90bf6bb6299870e04da915c52059717b;hp=603050489461412f11c9a9c6a1dc30fd8fc1d1e2;hb=296a0b75515b3a7424b98292c87cbbf2272b73f9;hpb=bcb54330afff6a443ab43ee3d38cc7f863c701b7 diff --git a/src/be/nikiroo/jvcard/i18n/Trans.java b/src/be/nikiroo/jvcard/i18n/Trans.java index 6030504..069f81c 100644 --- a/src/be/nikiroo/jvcard/i18n/Trans.java +++ b/src/be/nikiroo/jvcard/i18n/Trans.java @@ -3,6 +3,10 @@ package be.nikiroo.jvcard.i18n; import java.util.HashMap; import java.util.Map; +import com.googlecode.lanterna.input.KeyStroke; + +import be.nikiroo.jvcard.tui.UiColors; + /** * This class manages the translation of {@link Trans#StringId}s into * user-understandable text. @@ -27,6 +31,7 @@ public class Trans { KEY_ACTION_BACK, KEY_ACTION_HELP, // MainWindow KEY_ACTION_VIEW_CARD, // FileList KEY_ACTION_VIEW_CONTACT, KEY_ACTION_EDIT_CONTACT, KEY_ACTION_SAVE_CARD, KEY_ACTION_DELETE_CONTACT, KEY_ACTION_SWITCH_FORMAT, // ContactList + DEAULT_FIELD_SEPARATOR, DEAULT_FIELD_SEPARATOR_NOUTF, // MainContentList NULL; // Special usage public String trans() { @@ -48,12 +53,74 @@ public class Trans { return instance; } + /** + * Translate the given {@link StringId} into user text. + * + * @param stringId + * the ID to translate + * + * @return the translated text + */ public String trans(StringId stringId) { - if (map.containsKey(stringId)) { - return map.get(stringId); + StringId id = stringId; + if (!UiColors.getInstance().isUnicode()) { + try { + id = StringId.valueOf(stringId.toString() + "_NOUTF"); + } catch (IllegalArgumentException iae) { + // no special _NOUTF version found + } + } + + if (map.containsKey(id)) { + return map.get(id); + } + + return id.toString(); + } + + /** + * Translate the given {@link KeyStroke} into a user text {@link String} of + * size 3. + * + * @param key + * the key to translate + * + * @return the translated text + */ + public String trans(KeyStroke key) { + String keyTrans = ""; + + switch (key.getKeyType()) { + case Enter: + if (UiColors.getInstance().isUnicode()) + keyTrans = " ⤶ "; + else + keyTrans = "ENT"; + break; + case Tab: + if (UiColors.getInstance().isUnicode()) + keyTrans = " ↹ "; + else + keyTrans = "TAB"; + + break; + case Character: + keyTrans = " " + key.getCharacter() + " "; + break; + default: + keyTrans = "" + key.getKeyType(); + int width = 3; + if (keyTrans.length() > width) { + keyTrans = keyTrans.substring(0, width); + } else if (keyTrans.length() < width) { + keyTrans = keyTrans + + new String(new char[width - keyTrans.length()]) + .replace('\0', ' '); + } + break; } - return stringId.toString(); + return keyTrans; } private Trans() { @@ -62,6 +129,9 @@ public class Trans { // TODO: get from a file instead? map.put(StringId.NULL, ""); map.put(StringId.DUMMY, "[dummy]"); + // we could use: " ", "┃", "│"... + map.put(StringId.DEAULT_FIELD_SEPARATOR, "┃"); + map.put(StringId.DEAULT_FIELD_SEPARATOR_NOUTF, "|"); map.put(StringId.KEY_ACTION_BACK, "Back"); map.put(StringId.KEY_ACTION_HELP, "Help"); map.put(StringId.KEY_ACTION_VIEW_CONTACT, "Open");