Fix FN when empty (with a configurable option) + some i18n
[jvcard.git] / src / be / nikiroo / jvcard / resources / Trans.java
index 537b3a3cfb38877363a0159835eeb501001d2ad9..1fa0f116aba7fc93d55a2640da7ecf528771304e 100644 (file)
@@ -19,6 +19,7 @@ import java.util.ResourceBundle;
 public class Trans {
        private ResourceBundle map;
        private boolean utf = true;
+       private Locale locale;
 
        /**
         * Create a translation service with the default language.
@@ -43,11 +44,16 @@ public class Trans {
         * 
         * @param stringId
         *            the ID to translate
+        * @param values
+        *            the values to insert instead of the place holders in the
+        *            translation
         * 
-        * @return the translated text
+        * @return the translated text with the given value where required
         */
-       public String trans(StringId stringId) {
+       public String trans(StringId stringId, String... values) {
                StringId id = stringId;
+               String result = null;
+
                if (!isUnicode()) {
                        try {
                                id = StringId.valueOf(stringId.name() + "_NOUTF");
@@ -57,18 +63,19 @@ public class Trans {
                }
 
                if (id == StringId.NULL) {
-                       return "";
-               }
-
-               if (id == StringId.DUMMY) {
-                       return "[dummy]";
-               }
-
-               if (map.containsKey(id.name())) {
-                       return map.getString(id.name());
+                       result = "";
+               } else if (id == StringId.DUMMY) {
+                       result = "[dummy]";
+               } else if (map.containsKey(id.name())) {
+                       result = map.getString(id.name());
+               } else {
+                       result = id.toString();
                }
 
-               return id.toString();
+               if (values != null && values.length > 0)
+                       return String.format(locale, result, (Object[]) values);
+               else
+                       return result;
        }
 
        /**
@@ -98,7 +105,8 @@ public class Trans {
         *            instance
         */
        private void setLanguage(String language) {
-               map = Bundles.getBundle("resources", getLocaleFor(language));
+               locale = getLocaleFor(language);
+               map = Bundles.getBundle("resources", locale);
        }
 
        /**
@@ -246,7 +254,10 @@ public class Trans {
                                builder.append("FORMAT: " + format);
                        }
 
-                       builder.append(")\n# ");
+                       builder.append(")");
+                       if (info.length() > 0) {
+                               builder.append("\n# ");
+                       }
                }
 
                builder.append(info);
@@ -272,31 +283,39 @@ public class Trans {
                KEY_TAB, // keys
                @Meta(what = "a key to press", where = "action keys", format = "MUST BE 3 chars long", info = "Enter key")
                KEY_ENTER, //
-               @Meta(what = "", where = "", format = "", info = "")
-               KEY_ACTION_BACK, // MainWindow
-               @Meta(what = "", where = "", format = "", info = "")
+               @Meta(what = "Action key", where = "All screens except the first (KEY_ACTION_QUIT)", format = "", info = "Go back to previous screen")
+               KEY_ACTION_BACK, //
+               @Meta(what = "Action key", where = "MainWindow", format = "", info = "Get help text")
                KEY_ACTION_HELP, //
-               @Meta(what = "", where = "", format = "", info = "")
-               KEY_ACTION_VIEW_CARD, // FileList
-               @Meta(what = "", where = "", format = "", info = "")
-               KEY_ACTION_VIEW_CONTACT, // ContactList
-               @Meta(what = "", where = "", format = "", info = "")
+               @Meta(what = "Action key", where = "FileList", format = "", info = "View the selected card")
+               KEY_ACTION_VIEW_CARD, //
+               @Meta(what = "Action key", where = "ContactList", format = "", info = "View the selected contact")
+               KEY_ACTION_VIEW_CONTACT, //
+               @Meta(what = "Action key", where = "ContactDetails", format = "", info = "Edit the contact")
                KEY_ACTION_EDIT_CONTACT, //
-               @Meta(what = "", where = "", format = "", info = "")
+               @Meta(what = "Action key", where = "ContactDetails", format = "", info = "Edit the contact in RAW mode")
+               KEY_ACTION_EDIT_CONTACT_RAW, //
+               @Meta(what = "Action key", where = "ContactList", format = "", info = "Save the whole card")
                KEY_ACTION_SAVE_CARD, //
-               @Meta(what = "", where = "", format = "", info = "")
+               @Meta(what = "", where = "ContactList", format = "", info = "Delete the selected contact")
                KEY_ACTION_DELETE_CONTACT, //
-               @Meta(what = "", where = "", format = "", info = "")
+               @Meta(what = "Action key", where = "ContactList", format = "", info = "Filter the displayed contacts")
                KEY_ACTION_SEARCH, //
-               @Meta(what = "", where = "", format = "", info = "we could use: ' ', ┃, │...")
+               @Meta(what = "", where = "", format = "we could use: ' ', ┃, │...", info = "Field separator")
                DEAULT_FIELD_SEPARATOR, // MainContentList
-               @Meta(what = "", where = "", format = "", info = "")
-               DEAULT_FIELD_SEPARATOR_NOUTF, //
-               @Meta(what = "", where = "", format = "", info = "")
-               KEY_ACTION_INVERT, // ContactDetails
-               @Meta(what = "", where = "", format = "", info = "")
+               @Meta(what = "Action key", where = "ContactDetails", format = "", info = "Invert the photo's colours")
+               KEY_ACTION_INVERT, //
+               @Meta(what = "Action key", where = "ContactDetails", format = "", info = "Show the photo in 'fullscreen'")
                KEY_ACTION_FULLSCREEN, //
-               @Meta(what = "", where = "", format = "", info = "")
+               @Meta(what = "Action key", where = "ContactList, ContactDetails, ContactDetailsRaw", format = "", info = "Switch between the available display formats")
                KEY_ACTION_SWITCH_FORMAT, // multi-usage
+               @Meta(what = "Action key", where = "Contact list, Edit Contact", format = "", info = "Add a new contact/field")
+               KEY_ACTION_ADD, //
+               @Meta(what = "User question: TEXT", where = "Contact list", format = "", info = "New contact")
+               ASK_USER_CONTACT_NAME, //
+               @Meta(what = "User question: [Y|N]", where = "Contact list", format = "%s = contact name", info = "Delete contact")
+               CONFIRM_USER_DELETE_CONTACT, //
+               @Meta(what = "Error", where = "Contact list", format = "%s = contact name", info = "cannot delete a contact")
+               ERR_CANNOT_DELETE_CONTACT, //
        };
 }