diff --git a/Helpers.md b/Helpers.md index 6185009..cbc20ef 100644 --- a/Helpers.md +++ b/Helpers.md @@ -125,6 +125,24 @@ Provides messages for a given key, translated using the locale of the content no ```handlebars {{{t 'web.patterns.paging.next'}}} ``` +#### placeholders +messages can contain either indexed or mapped placeholders. +##### indexed +```properties +web.patterns.paging.current=current page is {0} +``` +```handlebars +{{{t 'web.patterns.paging.current' 2}}} +``` +--> =current page is 2 +##### map +```properties +web.patterns.paging.current=current page is {currentPagePlaceholder} +``` +```handlebars +{{{t 'web.patterns.paging.current' currentPagePlaceholder=2}}} +``` +--> =current page is 2 ### [If condition](light-development/src/main/java/com/merkle/oss/magnolia/renderer/handlebars/helpers/IfConditionHelper.java) Conditionally renders a block or returns evaluated condition. diff --git a/light-development/src/main/java/com/merkle/oss/magnolia/renderer/handlebars/helpers/I18nHelper.java b/light-development/src/main/java/com/merkle/oss/magnolia/renderer/handlebars/helpers/I18nHelper.java index 37916d5..5fc342e 100755 --- a/light-development/src/main/java/com/merkle/oss/magnolia/renderer/handlebars/helpers/I18nHelper.java +++ b/light-development/src/main/java/com/merkle/oss/magnolia/renderer/handlebars/helpers/I18nHelper.java @@ -1,19 +1,22 @@ package com.merkle.oss.magnolia.renderer.handlebars.helpers; -import com.github.jknack.handlebars.Handlebars; -import com.github.jknack.handlebars.Options; -import com.merkle.oss.magnolia.renderer.handlebars.utils.LocaleProvider; import info.magnolia.i18nsystem.FixedLocaleProvider; import info.magnolia.i18nsystem.SimpleTranslator; import info.magnolia.i18nsystem.TranslationService; import info.magnolia.jcr.util.ContentMap; -import javax.inject.Inject; -import javax.jcr.Node; -import java.io.IOException; import java.util.Locale; import java.util.Set; +import javax.inject.Inject; +import javax.jcr.Node; + +import org.apache.commons.text.StringSubstitutor; + +import com.github.jknack.handlebars.Handlebars; +import com.github.jknack.handlebars.Options; +import com.merkle.oss.magnolia.renderer.handlebars.utils.LocaleProvider; + public class I18nHelper implements NamedHelper { private final TranslationService translationService; private final LocaleProvider localeProvider; @@ -32,7 +35,7 @@ public CharSequence apply(final String key, final Options options) { final Node node = ((ContentMap) options.get("content")).getJCRNode(); final Locale locale = localeProvider.getLocale(node); final SimpleTranslator simpleTranslator = new SimpleTranslator(translationService, new FixedLocaleProvider(locale)); - final String message = simpleTranslator.translate(key, options.params); + final String message = new StringSubstitutor(options.hash, "{", "}").replace(simpleTranslator.translate(key, options.params)); return new Handlebars.SafeString(message); }