7.2.xでカスタムフラグメントを書くと、イメージフラグメントのダウンロードURLがローカライズされます。
knowledge-article-header-disclaimer-how-to
knowledge-article-header-disclaimer
legacy-article
learn-legacy-article-disclaimer-text
ご覧のページは、お客様の利便性のために一部機械翻訳されています。また、ドキュメントは頻繁に更新が加えられており、翻訳は未完成の部分が含まれることをご了承ください。最新情報は都度公開されておりますため、必ず英語版をご参照ください。翻訳に問題がある場合は、こちら までご連絡ください。
問題
ドキュメントライブラリでホストされている各言語の異なるドキュメントをダウンロードするために、フラグメントイメージのリンクを翻訳することはできません。
解決策
以下の手順で、サイト内で利用可能な各言語のURLの翻訳を可能にする、カスタマイズ可能な独自のフラグメントイメージを作成することができます。 なお、これはあくまでこの機能を実現するための提案であり、特定のユースケースごとに適合させ、テストする必要があります。
このフィールドはローカライズ可能であるため、テキスト型フィールド <lfr-editable id="text-href-editable"
type="text">
を使用してカスタムフラグメントを作成する必要があります。
まず、現在のイメージフラグメントのソースコードを Site Builder > Page fragments > Collections > Default > Basic components > Image fragment の 3-dot menu > Copy to and select your collection からコピーしてください。
このフラグメントがコピーされたら、編集可能なテキスト用のコンテナ <div id="text-href-content"
style="display:none;">
を追加する必要があります。デフォルトでは、編集モードになるまで非表示になります。 これには、URLの値( <lfr-editable
id="text-href" type="text">
)を翻訳するための要素が含まれています。 ビューモードになると、翻訳されたURLテキストが <div id="text-href">
の中に入り、ダウンロードリンクの href
属性にコピーされます <a id="localized-href"
href="#">
。 その結果、HTMLフラグメントの構造は次のようになります:
<div class="component-image pb-${configuration.bottomSpacing} overflow-hidden text-${configuration.imageAlign}"> <div id="text-href-content" style="display:none;"> Translate URL: <div id="text-href"> <lfr-editable id="text-href" type="text"></lfr-editable> </div> </div> <a id="localized-href" href="#"> <lfr-editable id="image-square" type="image"> <img id="custom-img" alt="Responsive Image" class="${configuration.imageSize}" src="" /> </lfr-editable> </a> </div>
このHTMLを動作させるためには、JavaScriptセクションに以下のコードスニペットが必要です:
const queryString = window.location.search; const hrefContent = document.getElementById("text-href-content"); if (hrefContent) { hrefContent.style.display = "none"; } if(queryString && URLSearchParams) { const urlParams = new URLSearchParams(queryString); const p_l_mode = urlParams.get('p_l_mode'); if (p_l_mode === "edit") { if (hrefContent) { hrefContent.style.display = "block"; } } } else if (!queryString) { console.log("queryString not found"); } else if (!URLSearchParams) { console.log("Method URLSearchParams not supported"); } const hrefEl = document.getElementById("text-href"); const href = hrefEl.textContent || hrefEl.innerText; document.getElementById("localized-href").href = href;
このコードは、ナビゲーションURLに p_l_mode
というパラメータが存在するかどうかを読み取り、編集モードかどうかを検出します。存在する場合は、要素ID text-href-content
を表示して、ユーザーが編集してローカライズできるようにし、表示モードになったら要素ID text-href
がリンクID localized-href
に翻訳テキストを提供します。
did-this-article-resolve-your-issue