> For the complete documentation index, see [llms.txt](https://help.form.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.form.io/dev/form-development/translations/embedded-translations.md).

# Embedded Translations

Embedded translations rely on hard-coded localization within the application code.

With embedded translations, form developers define each language’s key-value pairs in the `i18n` option when creating the form. Use `form.language` to switch languages at runtime.

In order to provide translations to the renderer, introduce these translations using [**i18Next**](https://www.i18next.com/) configurations. There are also a few methods within the Form.io Renderer that can be used to change the language dynamically. For example, the following HTML code introduces buttons within the application that will trigger a language change:

```markup
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css">
<script src="https://cdn.form.io/js/formio.embed.js"></script>

<div class="btn-group">
  <button type="button" class="btn btn-primary" onclick="setLanguage('es')">Español</button>
  <button type="button" class="btn btn-secondary" onclick="setLanguage('en')">English</button>
  <button type="button" class="btn btn-info" onclick="setLanguage('zh')">中文</button>
  <button type="button" class="btn btn-success" onclick="setLanguage('ar')">العربية</button>
</div>

<div id="formio"></div>
```

After this, provide the following code to define the form, provide the translated text, and then dynamically change the text when the buttons have been clicked. The code will look as follows:

```javascript
Formio.createForm(document.getElementById('formio'), {
    components: [
      {
        type: 'textfield',
        key: 'firstName',
        label: 'First Name',
        tooltip: "Name",
        placeholder: 'Enter your first name',
        input: true
      },
      {
        type: 'textfield',
        key: 'lastName',
        label: 'Last Name',
        placeholder: 'Enter your last name',
        input: true
      },
      {
        label: 'When did you start using the Form.io platform?',
        tableView: false,
        datePicker: {
          disableWeekends: false,
          disableWeekdays: false,
        },
        enableMinDateInput: false,
        enableMaxDateInput: false,
        validateWhenHidden: false,
        placeholder: 'Enter the date',
        key: 'startDate',
        type: 'datetime',
        input: true,
        widget: {
          type: 'calendar',
          displayInTimezone: 'viewer',
          locale: 'en',
          useLocaleSettings: false,
          allowInput: true,
          mode: 'single',
          enableTime: true,
          noCalendar: false,
          format: 'yyyy-MM-dd hh:mm a',
          hourIncrement: 1,
          minuteIncrement: 1,
          time_24hr: false,
          minDate: null,
          disableWeekends: false,
          disableWeekdays: false,
          maxDate: null,
        }
      },
      {
        type: 'survey',
        key: 'questions',
        label: 'Survey',
        values: [
          { label: 'Great', value: 'great' },
          { label: 'Good', value: 'good' },
          { label: 'Poor', value: 'poor' }
        ],
        questions: [
          { label: 'How would you rate the Form.io platform?', value: 'howWouldYouRateTheFormIoPlatform' },
          { label: 'How was Customer Support?', value: 'howWasCustomerSupport' },
          { label: 'Overall Experience?', value: 'overallExperience' }
        ]
      },
      {
        type: 'button',
        action: 'submit',
        label: 'Submit',
        theme: 'primary'
      }
    ]
  }, {
    language: 'en',
    i18n: {
      es: {
        'First Name': 'Nombre de pila',
        'Name': 'Nombre',
        'Last Name': 'Apellido',
        'Enter your first name': 'Ponga su primer nombre',
        'Enter your last name': 'Introduce tu apellido',
        'When did you start using the Form.io platform?': '¿Cuándo empezaste a utilizar la plataforma Form.io?',
        'Enter the date': 'Introduce la fecha',
        'How would you rate the Form.io platform?': '¿Cómo calificaría la plataforma Form.io?',
        'How was Customer Support?': '¿Cómo fue el servicio de atención al cliente?',
        'Overall Experience?': '¿Experiencia general?',
        Survey: 'Encuesta',
        Excellent: 'Excelente',
        Great: 'Estupendo',
        Good: 'Bueno',
        Average: 'Promedio',
        Poor: 'Pobre',
        'Submit': 'Enviar',
        complete: 'Presentación Completa'
      },
      zh: {
        'First Name': '名字',
        'Last Name': '姓',
        'Enter your first name': '输入你的名字',
        'Enter your last name': '输入你的姓氏',
        'When did you start using the Form.io platform?': '您是什麼時候開始使用 Form.io 平台？',
        'Enter the date': '輸入日期',
        'How would you rate the Form.io platform?': '你如何评价Form.io平台？',
        'How was Customer Support?': '客户支持如何？',
        'Overall Experience?': '总体体验？',
        Survey: '调查',
        Excellent: '优秀',
        Great: '大',
        Good: '好',
        Average: '平均',
        Poor: '错',
        'Submit': '提交',
        complete: '提交完成'
      },
      ar: {
        'First Name': 'الاسم الأول',
        'Last Name': 'اسم العائلة',
        'Enter your first name': 'أدخل اسمك الأول',
        'Enter your last name': 'أدخل اسم عائلتك',
        'When did you start using the Form.io platform?': 'متى بدأت باستخدام منصة Form.io؟',
        'Enter the date': 'أدخل التاريخ',
        'How would you rate the Form.io platform?': 'كيف تقيم منصة Form.io؟',
        'How was Customer Support?': 'كيف كان دعم العملاء؟',
        'Overall Experience?': 'التجربة العامة؟',
        Survey: 'استبيان',
        Excellent: 'ممتاز',
        Great: 'رائع',
        Good: 'جيد',
        Average: 'متوسط',
        Poor: 'ضعيف',
        'Submit': 'إرسال',
        complete: 'تم الإرسال'
      }
    }
  }).then(function(form) {
    window.setLanguage = function(lang) {
      form.language = lang;
      document.body.setAttribute("dir", lang === "ar" ? "rtl" : "ltr"); // Switch direction
    };
  });
```

{% hint style="info" %}
**Right-to-left language support**

In the above example, note the `setAttribute()` element used to accommodate languages rendered in a right-to-left direction. Include any additional language codes that may need to be rendered this way.
{% endhint %}

This code within a JSFiddle will work as follows:

{% embed url="<https://jsfiddle.net/TanyaFormio/buyht194/>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.form.io/dev/form-development/translations/embedded-translations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
