getI18nString returns undefined

Hi together,

I figured out that when I use getI18nString like this

self.commandRouter.pushToastMessage('failure', self.commandRouter.getI18nString('YOUTUBE_CONFIGURATION'), self.commandRouter.getI18nString('YOUTUBE_CONFIGURATION_SAVE_ERROR'));

that an empty message is shown. In my case getI18nString returns undefined but the resource keys definitely exist in i18n/strings_en.json. I used the same resource keys on my configuration page for testing purpose and there everything works as expected.

I had a look into the source code of the spotify and qobuz plugin but both don’t use localized strings when showing toast messages. The webradio plugin calls getI18nString the same way and there it works.

The documentation only explains how localization works for the configuration pages but not for things like toast messages.

Shouldn’t this code load the localization resources into a dictionary when volumio starts and then getI18nString should return the correct localized string?

Please tell me what I am doing wrong here. I really wish to localize my whole plugin and not just the configuration page.

Thank you.


I would say that toast message works only with strings in the main strings.json (not the plugin one).
So you can just use messages already in those files to invoke the toast message.

That seem to be inconsistent. I would suggest to provide localization for toast messages too. Why should somebody want to localize the UI configuration pages but not the toast messages?

Think about the following use case:
The user has entered some invalid configuration parameters and trys to save them. Everything shown to the the user is translated to German but the error toast message that appears because of the invalid configuration parameters is in English.

That’s not very user-friendly I think.

I can concur, only text that stays ‘within’ the plugin is translatable with your own strings.json.

Because a toastmessage is sent from the core, the context is no longer the plugin, but Volumio core, hence you cannot use the ‘normal’ translation method (which uses the calling context). You could work around this by implementing your own translation method in the plugin.

This applies to (at least):

  • Toast messages
  • Console messages
  • Logging
  • Broadcast messages

Agreed it’s easier to just be able to pass along the context as an overload maybe :slight_smile:

self.commandRouter.pushToastMessage(‘failure’, self.commandRouter.getI18nString(‘YOUTUBE_CONFIGURATION’

Note that failure is not a valid message alert. It should be error, alert or info.

We will implement thos in the future, but as of now. You might want to use already defined messages

I can implement it myself that’s not the problem. But think about 100 Volumio plugins and all of them implement translation on their own. :open_mouth:

The code of the qobuz plugin uses ‘failure’ so I thought I use them in my plugin too :slight_smile:
See here: … ex.js#L569 … ex.js#L696 … ex.js#L709

I think it would be not a problem to add full localization support to Volumio. The changes in the app/index.js would be quiet small I think.
Shall I try to implement it and create a PR or is it definitely not wished to be supported?


It would be a great improvement, so thanks if you’ll do a PR!