Supporting new locales for Adaptive Forms localization

AEM Forms provide out of the box support for English (en), Spanish (es), French (fr), Italian (it), German (de), Japanese (ja), Portuguese-Brazilian (pt-BR), Chinese (zh-CN), Chinese-Taiwan (zh-TW), and Korean (ko-KR) locales. You can add support for more locales also, like Hindi(hi_IN).

Understanding locale dictionaries

The localization of adaptive forms relies on two types of locale dictionaries:

  • Form-specific dictionary Contains strings used in adaptive forms. For example, labels, field names, error messages, help descriptions. It is managed as a set of XLIFF files for each locale and you can access it at [author-instance]/libs/cq/i18n/gui/translator.html.

  • Global dictionaries There are two global dictionaries, managed as JSON objects, in AEM client library. These dictionaries contain default error messages, month names, currency symbols, date and time patterns, and so on. You can find these dictionaries at [author-instance]/libs/fd/xfaforms/clientlibs/I18N. These locations contain separate folders for each locale. Because global dictionaries are not updated frequently, keeping separate JavaScript files for each locale enables browsers to cache them and reduce network bandwidth usage when accessing different adaptive forms on same server.

Add support for new locales

Perform the following to steps add support for a new locale:

  1. Add localization support for non-supported locales
  2. Use added locales in Adaptive Forms

Add localization support for non-supported locales

AEM Forms currently support localization of Adaptive Forms content in English (en), Spanish (es), French (fr), Italian (it), German (de), Japanese (ja), Portuguese-Brazilian (pt-BR), Chinese (zh-CN), Chinese-Taiwan (zh-TW), and Korean (ko-KR) locales.

To add support for a new locale at Adaptive Forms runtime:

  1. Clone your repository
  2. Add a locale to the GuideLocalizationService service
  3. Add locale-name specific folder
  4. Add locale support for the dictionary
  5. Commit the changes in the repository and deploy the pipeline

1. Clone the repository

  1. From the command line, navigate to where you would like to clone the Forms Cloud Service repository.
  2. Execute the command that you retrieved from Cloud Manager. It is similar to git clone https://git.cloudmanager.adobe.com/<my-org>/<my-program>/.
  3. Use the git user name and password to clone the repository.
  4. Open the cloned Forms Cloud Service repository folder in your preferred editor.

2. Add a locale to the Guide Localization service

  1. Locate the Guide Localization Service.cfg.json file and add the locale you want to add to the list of supported locales.

    NOTE

    Create a file with the name as Guide Localization Service.cfg.json file, if already not present.

3. Add locale-name specific folder client library

  1. In UI.content folder, create etc/clientlibs folder.
  2. Further create a folder named as locale-name under etc/clientlibs to serve as a container for xfa and af clientlibs.
3.1 Add XFA client library for a locale in locale-name folder

Create a node named as [locale-name]_xfa and type as cq:ClientLibraryFolder under etc/clientlibs/locale_name, with category xfaforms.I18N.<locale>, and add the following files:

  • I18N.js defining xfalib.locale.Strings for the <locale> as defined in /etc/clientlibs/fd/xfaforms/I18N/ja/I18N.
  • js.txt containing the following:
    /libs/fd/xfaforms/clientlibs/I18N/Namespace.js
    I18N.js
    /etc/clientlibs/fd/xfaforms/I18N/LogMessages.js
3.2. Add Adaptive Form client library for a locale locale-name folder
  1. Create a node named as [locale-name]_af and type as cq:ClientLibraryFolder under etc/clientlibs/locale_name, with category as guides.I18N.<locale> and dependencies as xfaforms.3rdparty, xfaforms.I18N.<locale> and guide.common.

  2. Create a folder named as javascript and add the following files:

    • i18n.js defining guidelib.i18n, having patterns of “calendarSymbols”, datePatterns, timePatterns, dateTimeSymbols, numberPatterns, numberSymbols, currencySymbols, typefaces for the <locale> as per the XFA specifications described in Locale Set Specification.
    • LogMessages.js defining guidelib.i18n.strings and guidelib.i18n.LogMessages for the <locale> as defined in /etc/clientlibs/fd/af/I18N/fr/javascript/LogMessages.js.
  3. Add js.txt containing the following:

      i18n.js
      LogMessages.js
    

4. Add locale support for the dictionary

Perform this step only if the <locale> you are adding is not among en, de, es, fr, it, pt-br, zh-cn, zh-tw, ja, ko-kr.

  1. Create a folder languages under etc, if not present already.

  2. Add a multi-valued string property languages to the node, if not present already.

  3. Add the <locale-name> default locale values de, es, fr, it, pt-br, zh-cn, zh-tw, ja, ko-kr, if not present already.

  4. Add the <locale> to the values of the languages property of /etc/languages.

  5. Add the newly created folders in the filter.xml under etc/META-INF/[folder hierarchy] as:

    <filter root="/etc/clientlibs/[locale-name]"/>
    <filter root="/etc/languages"/>
    

Before committing the changes into the AEM Git repository, you need to access your Git repository information.

5. Commit the changes in the repository and deploy the pipeline

Commit the changes to the GIT repository after adding a new locale support. Deploy your code using the full stack pipeline. Learn how to set up a pipeline to add new locale support.
Once the pipeline is complete, the newly added locale appears in the AEM environment.

Use added locale in Adaptive Forms

Perform the following steps to use and render an Adaptive Form using a newly added locale:

  1. Log in to your AEM author instance.
  2. Go to Forms > Forms and Documents.
  3. Select an Adaptive Form and click Add Dictionary and Add Dictionary To Translation Project wizard appears.
  4. Specify the Project Title and select the Target Languages from the drop-down menu in the Add Dictionary To Translation Project wizard.
  5. Click Done and execute the created translation project.
  6. Select an Adaptive Form and click Preview as HTML.
  7. Add &afAcceptLang=<locale-name> in the URL of an Adaptive Form.
  8. Refresh the page and Adaptive Form is rendered in a specified locale.

There are two methods to identify the locale of an Adaptive Form. When an Adaptive Form is rendered, it identifies the requested locale by:

  • Retrieving the [local] selector in the adaptive form URL. The format of the URL is http://host:[port]/content/forms/af/[afName].[locale].html?wcmmode=disabled. Using [local] selector allows caching an Adaptive Form.

  • Retrieving the following parameters in the listed order:

    • Request parameter afAcceptLang
      To override the browser locale of users, you can pass the afAcceptLang request parameter to force the locale. For example, the following URL forces to render the form in Canadian-French locale:
      https://'[server]:[port]'/<contextPath>/<formFolder>/<formName>.html?wcmmode=disabled&afAcceptLang=ca-fr

    • The browser locale set for the user, which is specified in the request using the Accept-Language header.

If a client library for the requested locale doesn’t exist, it checks for a client library for the language code present in the locale. For example, if the requested locale is en_ZA (South African English) and the client library for en_ZA doesn’t exist, the adaptive form uses the client library for en (English) language, if it exists. However, if none of them exist, the Adaptive Form uses the dictionary for en locale.

Once the locale is identified, the Adaptive Form picks the form-specific dictionary. If the form-specific dictionary for the requested locale is not found, it uses the dictionary for language in which Adaptive Form is authored.

If no locale information is present, Adaptive Form is delivered in the original language of the form. The original language is the language used while developing the Adaptive Form.

Get sample client library to add support for new locale. You need to change the content of the folder in the required locale.

Best Practices to support for new localization

  • Adobe recommends creating translation project after creating an Adaptive Form.

  • When new fields are added in an existing Adaptive Form:

    • For machine translation: Re-create the dictionary and run the translation project. Fields added to an Adaptive Form after creating a translation project remain untranslated.
    • For human translation: Export the dictionary through [server:port]/libs/cq/i18n/gui/translator.html. Update the dictionary for the newly added fields and upload it.

On this page