Issue
- Translating static text with the help of fragments and language overrides
Environment
- Liferay DXP 7.4 [all updates]
- Liferay DXP 2023.Q1
- Liferay DXP 2024.Q1
Resolution
Step 1:
a) Navigate to Applications Menu -> Control Panel -> and click Instance Setting (under the Configuration tab).
b) Click on Localisation in the Platform Section.
c) Select the languages you like from the available languages in the Current field and click Save.
Step 2:
a) Navigate to Applications Menu -> Control Panel -> and click Language Override (under the Configuration tab).
b) In the Language Override click the "New" button.
c) In the Language Key information, give a language key for the Static Text you wish to translate.
d) Now, enter the text you wish to use for English in the English field and translated texts in the other fields respectively, and click save.
Please note that the languages that are added in Step 1 will be listed here, so If want to add more languages, users need to first repeat Step 1.
e) Note down the language key given in the above step.
Step 3:
a) Inside the HTML tag in the Fragment, add the
[@liferay.language key="your-static-text-language-key" /]
Replace the key within quotes for the respective static texts.
b) Add a Language Selector Fragment to the pages that users wish to translate, then add the Fragments respectively and click publish.
c) Now click on the Language selector fragment and select a language.
Observed Behavior: Upon completion, users should observe the translated static texts.
If certain texts remain untranslated, consider removing editable attributes in the fragment, such as data-lfr-editable-id and data-lfr-editable-type.
Here is a video for reference: Drive Link