Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Here is the yaml template definition file:

Code Pro
languagejsyml
firstline1
titlefoobar/templates/pages/dilberts-page .yaml (fragment)
linenumberstrue
templateScript: /foobar/templates/pages/dilberts-page.ftl
renderType: freemarker
visible: true
dialog: foobar:pages/dilberts-page-properties
#title: foobar.customlabels.page.dilbert.title 
  • The key for the title property is created automatically by Magnolia, you do not have to provide it. In fact Magnolia will recognize two keys, one with module name and one without it:

foobar.templates.pages.dilberts-page

templates.pages.dilberts-page

  • Line 5: If desired, you can assign a custom key.

...

Note that Magnolia provides many so called "generic keys" which are already translated and which may fit to your items. See generic i18n keys and their list for further details.

Key generators

...

Code Pro
languagejava
titleinfo.magnolia.rendering.template.RenderableDefinition (simplified)
linenumberstrue
@I18nable(keyGenerator = RenderableDefinitionKeyGenerator.class)
public interface RenderableDefinition extends NamedDefinition {

    String getId();

    @Override
    String getName();

    String getRenderType();

    @I18nText
    String getTitle();

    @I18nText
    String getDescription();

    @Deprecated
    String getI18nBasename();

    String getTemplateScript();

    Map<String, RenderableDefinition> getVariations();
}
  • Line 1:
    Javadoc
    0info.magnolia.i18nsystem.I18nable
    annotation specifes specifies the key generator class.
  • Lines 11, 14:
    Javadoc
    0info.magnolia.i18nsystem.I18nText
    annotation marks methods that return text which should be translated.
Info

Use

Javadoc
0info.magnolia.i18nsystem.I18nable
and
Javadoc
0info.magnolia.i18nsystem.I18nText
for custom definition classes which should be i18n-ized.(warning) For all methods

(info) From Magnolia 6.2.1, any method annotated with

Javadoc
0info.magnolia.i18nsystem.I18nText

...

 uses NO_FALLBACK by default if no translation is found

...

.

...

Code Block
languagejava
titleinfo.magnolia.i18nsystem.I18nText
public @interface I18nText {

    /**
     * Without {@link #fallback()} explicitly specified, {@link info.magnolia.i18nsystem.TranslationServiceImpl} use the longest i18n key if translation key is not found as fallback.
     */
    String NO_FALLBACK = "<no-fallback>";

    /**
     * @return Value to be used if no translation is found.
     */
    String fallback() default NO_FALLBACK;
}

SimpleTranslator – using i18n in Java classes

...