📘 公式リファレンス🔧 リファレンス/フィルター初級
translate フィルター(翻訳キーから取得)
ロケールファイルに定義した翻訳キーを指定して、対応言語のテキストを返すフィルター。エイリアス `t` のほうがよく使われる。
用途
テーマ内のボタンラベル、メッセージ、見出しなどを多言語対応させたいとき。ロケールファイルで各言語の訳文を一元管理し、Liquid テンプレートから参照する。
設置場所
Liquid テンプレート内で `{{ 'translation_key' | t }}` または `{{ 'translation_key' | translate }}` の形で使う。ロケールファイル(locales/ ディレクトリの JSON または section schema 内の locales オブジェクト)に翻訳キーと訳文を定義しておくことが前提。
注意点
翻訳キーはロケールファイルに存在している必要があり、存在しないキーを指定するとキー名そのものが表示される。テーマ共通の翻訳はテーマの locales/ ディレクトリに、セクション固有の翻訳はセクションの schema 内の locales オブジェクトに置き分けると管理しやすい。セクション schema 内の locales 以外の翻訳は管理画面向けのテキストなので、フロントエンド表示には `t` フィルターを使わない。
仕様
40 行 / json{
"category": "localization",
"deprecated": false,
"deprecation_reason": "",
"description": "The `translate` filter has an alias of `t`, which is more commonly used.\n\n> Tip:\n> To learn more about using the `t` filter, refer to [storefront locale file usage](/themes/architecture/locales/storefront-locale-files#usage)\n> or [schema locale file usage](/themes/architecture/locales/schema-locale-files#usage).",
"parameters": [],
"return_type": [
{
"type": "string",
"name": "",
"description": "",
"array_value": ""
}
],
"examples": [
{
"name": "",
"description": "",
"syntax": "",
"path": "",
"raw_liquid": "",
"parameter": false,
"display_type": "text",
"show_data_tab": true
},
{
"name": "Section locales vs. theme locales",
"description": "The `t` filter can also reference keys defined in the [`locales` object](/themes/architecture/sections/section-schema#locales) of section file's `schema` tag. Content that you put in the `schema` under the `locales` object is only accessible to that section. This is useful if you need to make a standalone section that you want to share between themes.\n\nContent that is global to a theme should be placed in the theme's `locales` directory. For example, you could include the expression \"See more\" in your `locales` directory to create a single translation. You could then use the translation in a blog post and on the product details page.\n\n> Note:\n> Translations in the section's `schema` tag that aren't part of the `locales` object are used for merchant-facing text shown in the theme editor. These translations don't use the `t` filter.\n",
"syntax": "",
"path": "",
"raw_liquid": "",
"parameter": false,
"display_type": "text",
"show_data_tab": true
}
],
"summary": "Returns a string of translated text for a given translation key from a [locale file](/themes/architecture/locales).",
"syntax": "string | t",
"name": "translate"
}出典・ライセンス
- Repository:
- https://github.com/Shopify/theme-liquid-docs
- License:
- MIT
このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。
関連項目
📘 公式リファレンス🔧 リファレンス/フィルター初級
avatar フィルター(顧客アバター画像HTML生成)
顧客アバターが存在する場合、それを表示する HTML タグを生成するフィルター。customer オブジェクトに対して使用する。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
default_errors フィルター(フォーム送信エラーを日本語化)
form.errors の各エラーコードに対応する既定のエラーメッセージを自動生成するフィルター。フォーム送信時の入力値不正や必須項目空白などのエラーを言語別に出力する。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
date フィルター(日付を指定形式でフォーマット)
日付値を指定されたフォーマット文字列に従って整形する。フォーマット文字列が空の場合は元の値がそのまま返される。入力が日付に変換できない場合も元の値が返される。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
payment_terms フィルター(Shop Pay分割払いバナーを生成)
product フォームまたは cart フォームに対して使用し、Shop Pay の分割払いオプションを表示するための HTML を生成するフィルター。顧客が購入時に分割払いプランを選択できるようにする。
📁 theme-liquid-docs·MIT·19 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
abs フィルター(数値の絶対値を取得)
負の数を正の数に変換する。数値の絶対値(ゼロからの距離)を返すフィルター。
📁 theme-liquid-docs·MIT·30 行
📘 公式リファレンス🔧 リファレンス/フィルター初級
append フィルター(文字列の末尾に追加)
文字列の末尾に別の文字列を連結するフィルター。URL パスの結合やテキストの接尾辞追加に使う。
📁 theme-liquid-docs·MIT·30 行