Page 1 of 1

not existing i18n keys

PostPosted: Fri Jun 11, 2021 1:53 pm
by jdbruijn
Is there a way to check if an i18n key exists, or make it so that i18n.getI18nmessage returns an empty string or null value when the key does not exist instead of returning the key surrounding with exclamation marks?
i.e. i18n.getI18NMessage('my.non-existing-i18n.key') == null instead of i18n.getI18NMessage('my.non-existing-i18n.key') == '!my.non-existing-i18n.key!'

Re: not existing i18n keys

PostPosted: Tue Jun 22, 2021 3:30 pm
by steve1376656734
Hi Jos,

I wrap all my i18n calls with this function:

Code: Select all
function getMessage(i18nKey, subs) {
      var result = "";
      if (i18nKey) {
         result = i18nKey;

         if (utils.stringLeft(i18nKey.toLowerCase(), 5) == "i18n:") {
            result = i18n.getI18NMessage(i18nKey, subs);
            if (utils.stringLeft(result, 1) == "!") { //$NON-NLS-1$
               // key not found
               if (subs) result += "[" + subs.join() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ // Replace this line with result = null for your use case.
         } else {
            result = format(i18nKey, subs); // This is another custom function that will do parameter replacement in a message exactly the same as the i18n.getI18NMessage function for for non i18n strings
      return result;


Re: not existing i18n keys

PostPosted: Tue Jun 22, 2021 4:00 pm
by jdbruijn
Hi Steve,

I was already thinking about that, but was hoping a setting in the i18n plugin would accomplish the same.