Add internationalization (i18n) to document types
The Hippo CMS 7 user may login with different languages. You can add translations for every document type so the users can edit in their own language.
- Add a mixin type "hippo:translated" to your document type.
- Add a node "hippo:translation" of primary type "hippo:translation"
- Add a property "hippo:language" of type "String" and fill in the language abbreviation ("nl" or "en").
- Add a property "hippo:message" of type "String" and fill in the translated document type
- If you are editing from the console, don't forget to click the button "Write changes to repository"
In XML it looks like:
<sv:node sv:name="newsitem" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hippo:templatetype</sv:value> </sv:property> <sv:property sv:name="jcr:mixinTypes" sv:type="Name"> <sv:value>mix:referenceable</sv:value> <sv:value>hippo:translated</sv:value> </sv:property> <sv:node sv:name="hippo:translation"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hippo:translation</sv:value> </sv:property> <sv:property sv:name="hippo:language" sv:type="String"> <sv:value>nl</sv:value> </sv:property> <sv:property sv:name="hippo:message" sv:type="String"> <sv:value>Nieuws</sv:value> </sv:property> </sv:node> <sv:node sv:name="hippo:translation"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hippo:translation</sv:value> </sv:property> <sv:property sv:name="hippo:language" sv:type="String"> <sv:value>en</sv:value> </sv:property> <sv:property sv:name="hippo:message" sv:type="String"> <sv:value>News</sv:value> </sv:property> </sv:node> <!-- the rest of the document type definition --> </sv:node>
Internationalization of field captions
Above goes for the names of the document types, but what about the field captions? They can be internationalized by providing a translator service to subclasses of RenderPlugin, which are the plugin classes configured below the editor node in the template. The steps are:
- Add a translator node below editor:templates/_default with primary type frontend:plugin, mixin type hippostd:translated and plugin class ConfigTraversingPlugin. It must have also a translator.id property.
- Below it, add named nodes with multiple hippo:translation like above. The name of the node should match the field name that is to be translated.
- In the field configurations below it, remove the caption property and add a translator.id property that references the above translator.
In CMS 7.2 the XML looks like:
<sv:node sv:name="editor:templates"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>editor:templateset</sv:value> </sv:property> <sv:node sv:name="_default_"> <!-- skipped properties --> <!-- the translator --> <sv:node sv:name="translator"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>frontend:plugin</sv:value> </sv:property> <sv:property sv:name="jcr:mixinTypes" sv:type="Name"> <sv:value>hippostd:translated</sv:value> </sv:property> <sv:property sv:name="plugin.class" sv:type="String"> <sv:value>org.hippoecm.frontend.i18n.ConfigTraversingPlugin</sv:value> </sv:property> <sv:property sv:name="translator.id" sv:type="String"> <sv:value>${cluster.id}.translator</sv:value> </sv:property> <sv:node sv:name="hippostd:translations"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hippostd:translations</sv:value> </sv:property> <sv:node sv:name="title"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>nt:base</sv:value> </sv:property> <sv:property sv:name="jcr:mixinTypes" sv:type="Name"> <sv:value>hippo:translated</sv:value> </sv:property> <sv:node sv:name="hippo:translation"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hippo:translation</sv:value> </sv:property> <sv:property sv:name="hippo:language" sv:type="String"> <sv:value>nl</sv:value> </sv:property> <sv:property sv:name="hippo:message" sv:type="String"> <sv:value>Titel</sv:value> </sv:property> </sv:node> <sv:node sv:name="hippo:translation"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hippo:translation</sv:value> </sv:property> <sv:property sv:name="hippo:language" sv:type="String"> <sv:value>en</sv:value> </sv:property> <sv:property sv:name="hippo:message" sv:type="String"> <sv:value>Title</sv:value> </sv:property> </sv:node> </sv:node> </sv:node> </sv:node> <!-- skipped ListViewPlugin node etc. --> <sv:node sv:name="title"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>frontend:plugin</sv:value> </sv:property> <sv:property sv:name="engine" sv:type="String"> <sv:value>${engine}</sv:value> </sv:property> <sv:property sv:name="field" sv:type="String"> <sv:value>title</sv:value> </sv:property> <sv:property sv:name="mode" sv:type="String"> <sv:value>${mode}</sv:value> </sv:property> <sv:property sv:name="plugin.class" sv:type="String"> <sv:value>org.hippoecm.frontend.editor.plugins.field.NodeFieldPlugin</sv:value> </sv:property> <sv:property sv:name="wicket.id" sv:type="String"> <sv:value>${cluster.id}.field</sv:value> </sv:property> <sv:property sv:name="wicket.model" sv:type="String"> <sv:value>${wicket.model}</sv:value> </sv:property> <!-- reference the translator --> <sv:property sv:name="translator.id" sv:type="String"> <sv:value>${cluster.id}.translator</sv:value> </sv:property> <sv:node sv:name="cluster.options"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>frontend:pluginconfig</sv:value> </sv:property> </sv:node> </sv:node> </sv:node> </sv:node>
Note: above solution concerns one embedded translation service per document type. If you want to use same translations over multiple types, a global translator may be added to the main CMS configuration (/hippo:configuration/hippo:frontend/cms/cms-static) or the services node when available (/hippo:configuration/hippo:frontend/cms/cms-services)
| Editing translations from the console Captions that are based on translations, will not automically be updated when edited from the console. The changes will be reflected after a CMS restart. |