i18n plugin was introduced some time ago: Add i18n-maven-plugin to make internationalization easier by wborn · Pull Request #2544 · openhab/openhab-core · GitHub.
I’ve done some work with handlebars where I embedded translation provider in following way:
@Component
public class HandlebarsTranslateHelper implements TranslateHelper {
@Activate
public HandlebarsTranslateHelper(@Reference TranslationProvider translationProvider,
@Reference LocaleProvider localeProvider) {
this.translationProvider = translationProvider;
this.localeProvider = localeProvider;
}
@Override
public Object apply(Object context, Options options) throws IOException {
String scope = options.hash("scope", null);
String key = options.hash("key", null);
if (scope == null || key == null) {
return null;
}
String fallback = options.hash("fallback", null);
String lookupKey = scope + "." + key;
return translationProvider.getText(null, lookupKey, fallback == null ? null : "" + fallback, localeProvider.getLocale());
}
}
My calls were going like this: {{translate scope="item" key=name fallback=label}}
from YAML templates used to generate main ui widgets and pages.
In your case you can use also BundleResolver
which will mask use of FrameworkUtil
and simplify testing of the code and feed first argument of getText
call. The lookup key will come out of i18n plugin execution which assumes reasonable defaults for keys. You might need to tweak resources manually to avoid duplicate definitions of same text label.