Add a locale for Adaptive Forms based on Core Components supporting-new-locales-for-adaptive-forms-localization
The Right-to-Left language support feature is available under the early adopter program. You can write to aem-forms-ea@adobe.com from your official email id to join the early adopter program and request access to the capability.
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). You can also present Adaptive Forms in a Right-to-Left (RTL) language like Arabic, Persian, and Urdu by adding these locales.
How Does AEM Forms determine the locale for an Adaptive Form?
Understanding how AEM Forms selects the locale for rendering an Adaptive Form is crucial for proper localization. Here’s a breakdown of the selection process:
Priority-based locale selection
AEM Forms prioritizes the following methods to determine the locale for an Adaptive Form:
-
URL Locale Selector ([locale]):
The system prioritizes the locale specified within the URL using the [locale] selector. This format allows caching for better performance.
Format: The URL follows this format: http:/[AEM Forms Server URL]/content/forms/af/[afName].[locale].html?wcmmode=disabled.
Example: https://[server]/content/forms/af/contact-us.hi.html renders the form in Hindi.
-
afAcceptLang Request Parameter:
To override the user’s browser locale, you can use the
afAcceptLang
parameter in the URL.Example: https://[server]/forms/af/survey.ca-fr.html?afAcceptLang=ca-fr forces the form to render in Canadian French.
-
User’s Browser Locale (Accept-Language Header):
If no other locale is specified, AEM Forms considers the user’s browser locale sent using the
Accept-Language
header.
Fallback Mechanism:
-
If a client library (process to add a new locale, explained later in this document) for the requested locale is unavailable, AEM Forms checks for a library based on the language code within the locale.
Example: If en_ZA (South African English) is requested and there’s no en_ZA library, it uses en (English) if available.
If no suitable client library is found, the default dictionary (mostly
en
) for the form’s authoring language is used.In the absence of any locale information, the Adaptive Form displays in its original language used during development.
Prerequisites for adding a locale
Before you begin adding a new locale for your Adaptive Forms, ensure you have the following:
Software:
-
Plain Text Editor (IDE): While any plain text editor can work, an Integrated Development Environment (IDE) like Microsoft Visual Studio Code offers advanced features for easier editing.
-
Git: This version control system is required for managing code changes. If you don’t have it installed, download it from https://git-scm.com.
Code Repository:
Clone the Adaptive Forms Core Components Repository: You need a client library from this repository for adding a locale. To clone the repository:
-
Open your command line or terminal window.
-
Navigate to the desired location on your machine where you want to store the repository (for example, /adaptive-forms-core-components).
-
Run the following command to clone the repository:
code language-none git clone https://github.com/adobe/aem-core-forms-components.git
This command downloads the repository and create a folder named
aem-core-forms-components
on your machine. Throughout this guide, we refer to this folder as the[Adaptive Forms Core Components repository]
.
Add a locale add-localization-support-for-non-supported-locales
To add support for new locales to an adaptive form based on core components, follow these steps:
Clone your AEM as a Cloud Service Git repository
-
Open the command line and choose a directory to store your AEM as a Cloud Service repository, such as
/cloud-service-repository/
. -
Run the below command to clone the repository:
code language-shell git clone https://git.cloudmanager.adobe.com/<organization-name>/<program id>/
To clone your Git repository, you need some information:
-
Organization name: This identifies your team or project within Adobe Experience Manager as a Cloud Service (AEM as a Cloud Service).
-
Program ID: This specifies the program associated with your repository.
-
Credentials: You need a username and password (or a personal access token) to access the repository securely.
Where to find this information?
For step-by-step instructions on locating these details, refer to the Adobe Experience League article “Accessing Git”.
Your project is ready!
When the command completes successfully, you see a new folder created in your local directory. This folder is named after your program (for example, program-id). This folder contains all the files and code downloaded from your AEM as a Cloud Service Git repository.
Throughout this guide, we refer to this folder as the
[AEMaaCS project directory]
. -
Add the new locale to the Guide Localization Service
-
Open the repository folder in an editor.
-
Locate the
Guide Localization Service.cfg.json
file. This file controls the locales supported by your AEM Forms application. You can edit this file to add a new locale.-
Existing file: If the file already exists, locate it within your AEM Forms project directory. The typical location is:
code language-shell [AEMaaCS project directory]/ui.config/src/main/content/jcr_root/apps/<appid>/osgiconfig/config`.
Replace
<appid>
with your project specific app ID. You can find<appid>
for your AEM Project in thearchetype.properties
file. -
New file: If the file doesn’t exist, you need to create it in the same location mentioned above. Do not copy paste the name of the file from this document, rather manually type the name. The file name
Guide Localization Service.cfg.json
includes spaces. This is intentional and not a typo in the documentation.A sample file with the list of OOTB supported locales is:
code language-none { "supportedLocales":[ "en", "fr", "de", "ja", "pt-br", "zh-cn", "zh-tw", "ko-kr", "it", "es" ] }
-
-
Add the locale code for your desired language to the file.
-
Use the List of ISO 639-1 codes to find the two-letter code representing your desired language.
-
Include the locale code to the
Guide Localization Service.cfg.json
file. Here are some examples:-
Left-to-Right Languages:
- English (United States): en-US
- Spanish (Spain): es-ES
- French (France): fr-FR
-
Right-to-Left Languages:
- Arabic (United Arab Emirates): ar-ae
- Hebrew: he (or iw for historical reference)
- Farsi: fa
-
-
-
After making changes, ensure the
Guide Localization Service.cfg.json
file is formatted correctly as a valid JSON file. Errors in JSON formatting can prevent it from functioning properly. Save the file.
Leverage the sample client library for easy locale addition
AEM Forms provides a helpful sample client library, clientlib-it-custom-locale
, to simplify adding new locales. This library is part of the Adaptive Forms Core Components repository, available on GitHub.
Before we begin, ensure you have a local copy of the [Adaptive Forms Core Components repository]. If not, you can easily clone it using Git with the following command:
git clone https://github.com/adobe/aem-core-forms-components.git
This command downloads the entire repository, including the clientlib-it-custom-locale library, to a directory named aem-core-forms-components on your machine.
Integrate the sample client library
Now, let’s incorporate the clientlib-it-custom-locale
library into your AEM as a Cloud Service, [AEMaaCS project directory]:
-
Locate the sample client library:
Within your local copy of the [Adaptive Forms Core Components repository], navigate to the following path:
code language-none /aem-core-forms-components/it/apps/src/main/content/jcr_root/apps/forms-core-components-it/clientlibs
-
Copy and paste the library:
-
Copy the
clientlib-it-custom-locale
folder. -
Navigate to the following directory within your [AEMaaCS project directory]:
code language-none /ui.apps/src/main/content/jcr_root/apps/<app-id>/clientlib
Important: Replace
<app-id>
with the actual ID of your application. -
Paste the copied
clientlib-it-custom-locale
folder into this directory.
-
-
Update
aemLangUrl
path inlanguageinit.js
-
Navigate to the following directory within your [AEMaaCS project directory]:
code language-none /ui.apps/src/main/content/jcr_root/apps/<app-id>/clientlib/clientlib-it-custom-locale/js
-
Open the
languageinit.js
file in your editor. -
Locate the following line in the
languageinit.js
file:const aemLangUrl = /etc.clientlibs/forms-core-components-it/clientlibs/clientlib-it-custom-locale/resources/i18n/${lang}.json;
-
Replace
forms-core-components-it
with your<app-id>
(actual ID of your application) in the above line.const aemLangUrl = '/etc.clientlibs/<app-id>/clientlibs/clientlib-it-custom-locale/resources/i18n/${lang}.json';
-
forms-core-components-it
with your project name or <app-id>
, the date picker component fails to translate.Create a file for your new locale:
-
Navigate to the Locale Directory:
Within your
[AEMaaCS project directory]
, navigate to the following path:code language-none /ui.apps/src/main/content/jcr_root/apps/<program-id>/clientlibs/clientlib-it-custom-locale/resources/i18n/
Important: Replace
<program-id>
with your actual application ID. -
Locate the sample English language file:
AEM Forms provides a sample English locale file (.json) on GitHub.
The English language file includes the default set of strings for reference. Your locale-specific file should mimic the structure of the English language file.
For languages like Arabic, Hebrew, and Farsi, text reads from right to left (RTL) instead of left to right (LTR) like English. To ensure your forms display correctly in these languages, we recommend using our sample locale files as a guide. These files provide a reference for how to format text, dates, and other elements for RTL languages. You can find the sample locale files for:
By leveraging these sample files, you can ensure your forms provide a seamless experience for users working in RTL languages.
-
Create your locale file:
- Create a new .json file within the
i18n
directory. - Name the file using the appropriate locale code for your desired language (For example, fr-FR.json for French and ar-ae.json for Arabic). The structure of this file should mirror the English locale file.
- Create a new .json file within the
-
Structure and Translation:
-
Open the newly created file in a text editor.
-
Replace the English values with the corresponding translations for your target language.
-
Once you’ve finished translating the strings, save the file.
-
Add locale support to the dictionary
This step applies only to locales other than the following commonly supported ones: English (en), German (de), Spanish (es), French (fr), Italian (it), Brazilian Portuguese (pt-br), Chinese (Simplified - zh_cn), Chinese (Traditional - zh_tw), Japanese (ja), and Korean (ko_kr).
-
Locate the configuration folder:
Navigate to the following directory in your [AEMaaCS project directory]:
code language-none /ui.content/src/main/content/jcr_root/etc
-
Create the necessary folders (if missing):
If the
etc
folder doesn’t exist withinjcr_root
folder, create it. Insideetc
, create another folder namedlanguages
if it’s missing. -
Create the locale configuration file:
Within the
languages
folder, create a new file named.content.xml
. Do not copy paste the name of the file from this document, rather manually type the name.Open this file and paste the following content, replacing [LOCALE_CODE] with the actual locale code (For example, ar-ae for Arabic).
code language-xml <?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="nt:unstructured" languages="[de,es,fr,it,pt-br,zh-cn,zh-tw,ja,ko-kr,hi]"/>
WARNING: Do not replace the existing list. Instead, append your new locale code within square brackets, separated by commas, like this (using ar-ae as an example):
code language-xml languages="[de,es,fr,it,pt-br,zh-cn,zh-tw,ja,ko-kr,hi,ar-ae]"
-
Include the New Folders in filter.xml:
Navigate to the
/ui.content/src/main/content/meta-inf/vault/filter.xml
file in your [AEMaaCS project directory].Open the file and add the following line at the end:
code language-none <filter root="/etc/languages"/>
-
Save the file.
Deploy the newly created locale to your AEM environment
You are now all set to use the new locale with your Adaptive Forms. You can
-
Deploy the AEM as a Cloud Service, [AEMaaCS project directory], to your local development environment to try the new locale configuration on your local machine. To deploy to your local development environment:
-
Ensure that your local development environment is up and running. If you haven’t already set up a local development environment, refer to the guide on Setup local development environment for AEM Forms.
-
Open the terminal window or command prompt.
-
Navigate to the [AEMaaCS project directory]
-
Run the following command:
code language-none mvn -PautoInstallPackage clean install
-
-
Deploy the AEM as a Cloud Service, [AEMaaCS project directory], to your Cloud Service environment. To deploy to your Cloud Service environment:
-
Commit Your Changes:
After adding the new locale configuration, commit your changes with a clear Git message describing the locale addition (For example, “Added support for [Locale Name]”).
-
Deploy the Updated Code:
Trigger a deployment of your code through the existing full-stack pipeline. This automatically builds and deploys the updated code with the new locale support.
If you haven’t already set up a pipeline, refer to the guide on how to set up a pipeline for AEM Forms as a Cloud Service.
-
Preview an Adaptive Form with newly added locale
These steps guide you through previewing an Adaptive Form with the newly added locale:
- Log in to your AEM Forms as a Cloud Service instance.
- Go to Forms > Forms and Documents.
- Select an Adaptive Form and click Add Dictionary and Add Dictionary To Translation Project wizard appears.
- Specify the Project Title and select the Target Languages from the drop-down menu in the Add Dictionary To Translation Project wizard.
- Click Done and execute the created translation project.
- Go to Forms > Forms and Documents.
- Select the Adaptive Form and choose the Preview as HTML option.
- Append
&afAcceptLang=<locale-name>
to the preview URL and press the return key. Replace<locale-name>
with your actual locale code. The adaptive form is displayed in the specified locale.
Best Practices to support for new localization best-practices
-
Adobe recommends creating a translation project after creating an Adaptive Form. This streamlines the localization process.
-
When Numeric Box and Date Picker components are translated into a specific locale, formatting issues may arise. To mitigate this, a Language option has been incorporated into the Configure dialog of Date picker component and Numeric Box component.
-
Handling New Fields:
-
Machine Translation: If using machine translation, you need to recreate the dictionary and re-run the translation project after adding new fields to an existing Adaptive Form. New fields added after the initial translation project remain untranslated.
-
Human Translation: For human translation workflows, export the dictionary using the UI at
[AEM Forms Server]/libs/cq/i18n/gui/translator.html
. Update the dictionary for the new fields and upload the revised version.
-