Easily manage localized web content text with parameters

HCL Digital Experience Web Content Management has built-in multilingual support. If you want to manage multilingual texts in your design, like Presentation Templates and Components, but also in Script Applications and externally in other applications, you may use text providers.

These text providers manage all the translation strings, and those strings may contain parameters. This allows you for example to create a welcome text, like ‘Hello, <first name>, you have <number of new messages> new messages’ where first name is replaced by the user’s first name and the number of unread messages by that user’s specific number of unread messages. This message can be translated to any language and the parameters in that message may be in completely different orders for each language. Here is an example of its result in both English and French:

These text providers may be managed by developers using National language support (NLS) files or managed easily as web content.

When managing it in web content, your business users may easily translate and manage them. To manage this in web content, your text provider content or site area items need to have the keyword set to ibm.wcm.TextProvider.

Then create a set of text elements for each language used by your site, using the right language code (e.g. en for English and fr for French). Enter translated text in each field using format keyname=translated-text with consistent key names for each language following the Java Properties File Format.

  • E.g. a content that manages all the translations for the intranet in English and French

Notice the option to use parameters using {} pointing to the parameter numbers.

To use this anywhere in your design, you may use the Content plugin Localize or TextProvider tag (Localize is an alias of TextProvider): [Plugin:Localize provider=”” key=”" defaultValue=“” param.0=“” param.1=“” param.X=“”] or [Plugin:TextProvider provider=“” key=“” defaultValue=“” param.0=“” param.1=“” param.X=“”] with

  • Provider is path of Text Provider content or site area, or UUID
  • Key is the name of key of the translated text
  • defaultValue (optional) used to set a value if no result
    • E.g. [Plugin:Localize key=“welcome” provider=“library/sitearea/contentitem” defaultvalue=”Hi”]
  • And parameters are referred to as numbers, with a format param., like param.0
    • E.g. for the above content [Plugin:Localize key=“welcomeUser” provider=“Global/Texts/MsgTranslations” param.0=“Bob” param.1=”3”] which may give in with the English locale set “Hello Bob, you have 3 new messages” and with French locale “Bonjour Bob, vous avez 3 nouveaux messages”.

The text providers may also be used to localize fields that support localized text . They have a Localizations link next to the field title and by clicking it, you may select the content item or site area where your translated text is stored, and then select a key name. Here is an example to manage the Display title field and get it localized automatically for content authors.

More details in the Help Center