legacy-knowledge-base
公開されました Jul. 2, 2025

Liferay.Language.get メソッドは、DXP 7.3 以降、文字列変数で機能しなくなりました

written-by

Daniel Couso

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

learn-legacy-article-disclaimer-text

問題

  • 引数としてリテラル文字列ではなく文字列変数を使用して Liferay.Language.get への呼び出しを含むコードは、対応する翻訳の代わりに渡された引数を返します。

Environment

  • DXP 7.3+

解決策

  • 以前のバージョンでは、要求された翻訳を見つけるための最初の試みがレンダリング時にモジュール内で利用できなかった場合に、ブロッキング HTTP 要求を通じてコアにある翻訳を取得するためのフォールバックがあるため、これは機能します。
  • このフォールバック メカニズムは DXP 7.3 の時点で削除されました。これは、ブロッキング HTTP 要求を使用し、考えられるシナリオの 1 つしかカバーしていないためです。
  • 直接の置換はありません。 回避策として、変数文字列の代わりにリテラル文字列を渡す必要があります。これは、このフィルターが有効になっている場合、前者の文字列は LanguageFilter によって前処理される可能性があるためです。 適応されたコードの例として:
    // 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

legacy-knowledge-base