> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 動的変数を使用してカスタムフォーム要素を多言語対応にする

> 動的変数を使用して、ローカライズされたUniversal Loginのサインアップおよびログインプロンプトをレンダリングする方法を学びます。

コンテキストデータに応じて、[サインアッププロンプトのカスタマイズ](/docs/docs/ja-jp/customize/login-pages/universal-login/customize-signup-and-login-prompts)を異なる形でレンダリングできます。`locale` 変数を使うことで、フォーム入力を条件付きでレンダリングし、バリデーションの動作を定義できます。

次のユースケースでは、`locale` 変数を使用して、Terms of Service のメッセージとチェックボックスをレンダリングします。[ページテンプレート](/docs/docs/ja-jp/customize/login-pages/universal-login/customize-templates#available-variables)で公開されている任意の変数に置き換えることができます。

### 前提条件

* テナントで[カスタムドメイン](/docs/docs/ja-jp/customize/custom-domains)が検証済みである
* テナントにページテンプレートが設定されている

### fr と es のロケールを有効にする

Auth0 Dashboard (Auth0 Dashboard: サービスを設定するための Auth0 の主要な製品。) に移動し、Settings > General を開いて、ロケールを有効にします。

![](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/cdy7uua7fh8z/4yCGYTZ3RDyeULWIFcyHSv/01ce1985b1f8655aff0a0a2b4db6bee0/Language_Picker_-_EN.png)

### Custom Fields を条件付きでレンダリングする

Management API (Management API: お客様が管理タスクを実行できるようにする製品。) を使用して、`form-content-end` のサインアッププロンプトにある Universal Login (Universal Login: ユーザーのアイデンティティを確認するために、アプリケーションは Auth0 の認可サーバーでホストされる Universal Login にリダイレクトされます。) Prompt コンテナーに template partial を追加します。ロケール が `es` または `fr` の場合は、Terms of Service のメッセージとチェックボックスをレンダリングするとよいでしょう。

```liquid lines theme={null}
{% if locale == 'fr' %}
  <div class="ulp-field">
    <input
      type="checkbox"
      name="ulp-terms-of-service"
      id="terms-of-service">
    <label for="terms-of-service">
      J'accepte les
      <a href="https://fr.example.com/tos">termes et conditions</a>
    </label>
  </div>
{% endif %}
{% if locale == 'es' %}
  <div class="ulp-field">
    <input
      type="checkbox"
      name="ulp-terms-of-service"
      id="terms-of-service">
    <label for="terms-of-service">
      Estoy de acuerdo con los
      <a href="https://es.example.com/tos">términos y condiciones</a>
    </label>
  </div>
{% endif %}
```

次のリクエストは、[Management API](/docs/docs/ja-jp/api/management/v2/prompts/put-custom-text-by-language)の**特定のプロンプトにカスタムテキストを設定する**エンドポイントに送信されます。

```javascript lines theme={null}
// PUT prompts/signup/partials

{
  "signup": {
    "form-content-end": "{% if locale..."
  }
}
```

サインアッププロンプトでは、ロケールが`fr`または`es`に設定されている場合にのみ、ToSメッセージとチェックボックスが表示されるようになりました。

![](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/cdy7uua7fh8z/3zBadIHnkl9bIWP9BH1lLj/b2a6d9932be3bbb150b4dbbf76bc6599/2024-01-31_16-17-04.png)

![](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/cdy7uua7fh8z/3rwVd1h1Av7QzOEEWoCHhF/519a2eb5ac99c3801861c3372b81c0b9/2024-01-31_16-17-16.png)

![](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/cdy7uua7fh8z/2qYzAI6QVBLmqCW2FTAiGj/f19c59d79c67c63782b70995dbd223c3/2024-01-31_16-17-24.png)

表示をテストするには、**Manage Dashboard** に移動し、[Branding > Universal Login > Customization Options](https://manage.auth0.com/dashboard/us/dev-6endizjt/universal-login/customizations/colors) に進みます。次に、**「試す」ボタン** を右クリックしてリンク先のアドレスをコピーします。コピーしたURLに次のクエリパラメータを追加し、新しいURLに移動します: `&screen_hint=signup&ui_locales=fr` (または `es`) 。

### バリデーションを追加

ロケールが `fr,` の場合は、続行する前にチェックボックスが選択されていることをバリデーションできます。次のバリデーションコードを使って、template partial を更新します。

```liquid lines expandable theme={null}
{% if locale == 'fr' %}
  <div class="ulp-field">
    <input
      type="checkbox"
      name="ulp-terms-of-service"
      id="terms-of-service">
    <label for="terms-of-service">
      J'accepte les
      <a href="https://fr.example.com/tos">termes et conditions</a>
    </label>

    <!-- 新規 -->
    <div
      class="ulp-error-info"
      data-ulp-validation-function="requiredFunction"
      data-ulp-validation-event-listeners="change">
      Vous devez accepter les termes et conditions pour continuer
    </div>
    <!-- 新規ここまで -->
  </div>
{% endif %}
{% if locale == 'es' %}
  <div class="ulp-field">
    <input
      type="checkbox"
      name="ulp-terms-of-service"
      id="terms-of-service">
    <label for="terms-of-service">
      Estoy de acuerdo con los
      <a href="https://es.example.com/tos">términos y condiciones</a>
    </label>
  </div>
{% endif %}

<!-- 新規 -->
<script>
  function requiredFunction(element, formSubmitted) {
    if (! formSubmitted) {
      return true;
    }
    return element.checked;
  }
</script>
<!-- 新規ここまで -->
```

このバリデーションを適用すると、ToS への同意が必要になるのは `fr` ロケールのユーザーだけです。

![](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/cdy7uua7fh8z/7jBPuIe62PDNiIPUYzVVix/74de519659de4a8b4329165e799b1815/2024-01-31_16-20-54.png)

このユースケースのバリデーションはクライアントサイドで行われ、ユーザーの利便性を高めるためのものです。必ず実行されるとは限りません。たとえば、ユーザーのブラウザーで Javascript が無効になっている場合があります。さらに、バリデーションは好奇心からでも悪意をもってでも改変される可能性があります。バリデーションロジックの完全性を確保するには、クライアントサイドのバリデーションをサーバーサイドのバリデーションと組み合わせる必要があります。
