i18n key exists?

How do I check if a i18n key is present or not?

I think you can use i18n.getI18NMessage(‘mykey’) and check the returned value.

Regards,
Andrei

yes, I can do that but then the return value is ‘!mykey!’. Do I know for sure that those exclamation marks will be always there. The returned value should be null.

udrescu_bogdan,

Why do you need to know if a key exists?
Normally you would define a base definition for each key that your solution uses (usually in english) and overwrite some or all for each other language that you support.

The exclamation mark is more a signal that a key is missing, but normally this should never happen.

Rob

Does it matter why I need it if I already asked? :)

I allow users to setup a particular message. That message need to be displayed at some point. At that point in the app I just have a String which I don’t know if it’s the key for another message or the message user set himself. So I need to see if the String is an existing key, otherwise show it as it is. I don’t care for the language here because the it the user’s message, it’s his and his fellows language.

When keys are prefixed with ‘i18n:’ the prefix is removed, so i18n.getI18NMessage(‘mykey’) is the same as i18n.getI18NMessage(‘i18n:mykey’).
You can use that to distinguish between the two cases in your logic.
Just make sure that real keys are prefixed and user messages are not.

Rob

This is a nice tip! Thanks!

Didn’t knew that i18n: will be removed when provided to i18n object.