-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localization support for plugins #1357
Conversation
@sla89 can you please solve the conflicts? Also, can you contact me directly at info at volumio dot org ? |
@volumio I have resolved them and I have sent you a mail. |
@sla89 sorry if I get back so late with this. |
@sla89 Just thought now that we have an issue with this: |
I can confirm the problem volumio pointed out on 6 Feb. The localization files are scanned only when Volumio starts and the plugin is already enabled. Therefore after just installing and enabling the plugin or after booting Volumio with the plugin in disabled state and then enabling it had the effect that localized strings for toasts etc. were not available (toasts did not show up at all then). Workaround is to call the method "self.commandRouter.loadI18nStrings()" on every start of a plugin (onStart method), see PR 187 (volumio/volumio-plugins#187) and 188 (volumio/volumio-plugins#188) in the volumio-plugins repo. |
Sorry for the late response. I don't think that this workaround is a good idea, because you will always load all localizations again and not just the one of the plugin. Further I forgot to cleanup the store for all the terms. I guess a better approach would be to extend my PR by moving the code for loading the terms of a plugin into a method and call this method in What do you think about that? I guess that should fix all the problems. I would do the loading of the terms after the plugin manager successfully loaded/disabled the plugin. |
Yes, I fully agree. It is not a nice solution at all, but I did not find another one ;-) I am all for handling it in While we are at it. I extended your suggested implementation of
Let me know what you think about it. |
@sla89 Did you have the opportunity to have a look at this issue? |
Closing for inactivity... |
Currently the plugins have to implement localization support by their own. The
CoreCommandRouter
called the methodloadI18NStrings
on each plugin if the method exists. But this was not documented at all so the method is not used so far.I have replaced this method by a new method called
getI18nFile
. The idea is that each plugin returns the i18n filename that should be loaded into volumio on startup. Then volumio reads that file and merges the locales into the variablei18nStrings
. Now the plugins can callself.commandRouter.getI18nString('MY_LOCALE_KEY')
and they get the localized string for it.With this feature we can now provide localized toast messages in the spotify, qobuz and youtube plugin.
When you accept the PR I will update the docs accordingly where we also have to setup some guidelines so that we have no merge issues. My code already takes aware of duplicated keys and only adds new keys to
i18nStrings
.The implementation of
getI18nFile
could look like this and could be part of the example plugin too: