I'm trying to translate text inside a Transformer class. The page's locale is coming out at de but I'm never getting the German string. My i18n libraries are correct because I can get the translated string out via the groovy console. Any idea why the resourceBundle isn't loading the translations?
... class TranslationTransformer extends AbstractSAXPipe implements Transformer { ... @Override public void init(final ProcessingContext context, final ProcessingComponentConfiguration config) throws IOException { this.request = context.request Page page = this.request.resource.parent.adaptTo(Page.class) if (page) { Locale locale = page.getLanguage(false) ResourceBundle resourceBundle = this.request.getResourceBundle(locale) this.i18n = new I18n(resourceBundle) LOG.debug("... Locale is $locale") String temp = "Contact Us" String output = i18n.getVar(temp) LOG.debug("... Contact Us is $output") } } ... }
Solved! Go to Solution.
Views
Replies
Total Likes
The solution was to inject a ResourceBundle Provider then use that to find the resourceBundle. The request wouldn't find it for some reason.
@Reference(target="(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)")private ResourceBundleProvider resourceBundleProvide
ResourceBundle resourceBundle = resourceBundleProvider.getResourceBundle(locale)
Views
Replies
Total Likes
are you using the same name for the page locale and i18N locale
ex: If you have create a language node called 'de' in page, i18N should also have a same node name 'de' and not de_DE
Views
Replies
Total Likes
I've been banging my head on this for a while. Our i18n node is just 'de' not de_DE. I believe the issue is with the request coming from the ProcessingContext. I've moved the code above to a servlet and it works just fine.
Views
Replies
Total Likes
The solution was to inject a ResourceBundle Provider then use that to find the resourceBundle. The request wouldn't find it for some reason.
@Reference(target="(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)")private ResourceBundleProvider resourceBundleProvide
ResourceBundle resourceBundle = resourceBundleProvider.getResourceBundle(locale)
Views
Replies
Total Likes