not existing i18n keys

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

not existing i18n keys

Postby jdbruijn » Fri Jun 11, 2021 1:53 pm

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!'
Jos de Bruijn
Focus Feedback BV
Servoy Certified Developer
Image
jdbruijn
 
Posts: 492
Joined: Sun Apr 11, 2010 6:34 pm

Re: not existing i18n keys

Postby steve1376656734 » Tue Jun 22, 2021 3:30 pm

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;
}


Thanks
Steve
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 326
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: not existing i18n keys

Postby jdbruijn » Tue Jun 22, 2021 4:00 pm

Hi Steve,

I was already thinking about that, but was hoping a setting in the i18n plugin would accomplish the same.
Jos de Bruijn
Focus Feedback BV
Servoy Certified Developer
Image
jdbruijn
 
Posts: 492
Joined: Sun Apr 11, 2010 6:34 pm


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 13 guests

cron