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!’
Hi Jos,
I wrap all my i18n calls with this function:
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;
}
Thanks
Steve
Hi Steve,
I was already thinking about that, but was hoping a setting in the i18n plugin would accomplish the same.