Liferay.Language.get method is no longer working with string variables as of DXP 7.3
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
Issue
- Pieces of code which contain calls to
Liferay.Language.get using string variables and not literal strings as their argument return the argument passed instead of the corresponding translation.
Resolution
- In previous versions, this works since there is a fallback to retrieve the translations located in the core through a blocking HTTP request in case that the first attempt to find the requested translation was not available within the module at render time.
- This fallback mechanism was removed as of DXP 7.3 because it uses a blocking HTTP request and that only covered one of the possible scenarios.
- There is no direct replacement. As a workaround, literal strings should be passed instead of variable strings, since the former ones can be preprocessed by
LanguageFilter when this filter is enabled. As an example of adapted code:
// Previous code
let myStatus = 'draft-status';
if (myCondition) {
myStatus = 'published-status';
}
let myStatusLocalized = Liferay.Language.get(myStatus);
// Adapted code
let myStatusLocalized = Liferay.Language.get('draft-status');
if (myCondition) {
myStatusLocalized = Liferay.Language.get('published-status');
}
Did this article resolve your issue ?