Languages usage

Current and default languages are stored inside globally available .Session object. There is 2 possible language codes available at the moment, - 2-letter and 3-letter code. 2-letter code is an iso code, but 3-letter is an internal erply api language code, please check erply api for more information.

  • {{ .Session.Language.Code }} - 2-letter iso code
  • {{ .Session.Language.LegacyCode }} - 3-letter erply legacy code
  • {{ .Session.DefaultLanguage.Code }} - 2-letter iso code of default language
  • {{ .Session.DefaultLanguage.LegacyCode }} - 3-letter erply legacy code of default language

Samples

Read translatable fields

Dynamic sample:

<input type="hidden" name="PIMApi.Api.Get.products" value="v1/product" data-preset-val="v1/product">
<ul>
    {{ range $row := .Data.PIMApi.Api.Requests.products.Response.Array }}
    <li>{{ $row.Get "id" }} | {{ $row.Get (printf "name.%s" $.Session.Language.Code) }}</li>
    {{ end }}
</ul>

Models sample:

{{ range $row := .Data.PIMApi.ProductList }}
  <!-- Print name value in the selected/default language -->
  <!-- Will print empty string if value under language code not found -->
  <p>Name in current lang: {{ index $row.Name $.Session.Language.Code }}</p>
  <p>Name in default lang: {{ index $row.Name $.Session.DefaultLanguage.Code }}</p>
{{ end }}

Display in tables

Dynamic sample:

{{ range $row := .Data.PIMApi.Api.Requests.products.Response.Array }}
<tr>
  <td>{{ $row.Get "id" }}</td>
  <td>{{ $row.Get (printf "name.%s" $.Session.Language.Code) }}</td>
</tr>
{{ end }}

Models sample:

<table>
  <thead>
  <tr>
    <th>Id</th>
    <th>Name</th>
  </tr>
  </thead>
  <tbody>
  
  {{ range $row := .Data.PIMApi.ProductList }}
  <tr>
    <td>{{ $row.ID }}</td>
    <td>{{ index $row.Name $.Session.Language.Code }}</td>
  </tr>
  {{ end }}
  
  </tbody>
</table>

Dynamic sample:

<select>
  {{ range $row := .Data.PIMApi.Api.Requests.products.Response.Array }}
  <!-- Print name value in the selected/default language  -->
  <option value='{{ $row.Get "id" }}'>{{ $row.Get (printf "name.%s" $.Session.Language.Code) }}</option>
  {{ end }}
</select>

Models sample:

<select>
  {{ range $row := .Data.PIMApi.ProductList }}
   <!-- Print name value in the selected/default language  -->
   <option value="{{$row.ID}}">{{ index $row.Name $.Session.Language.Code }}</option>
  {{ end }}
</select>

Write (create/update) translatable fields in multiple languages

Dynamic sample:

<form method="post">
  <input type="hidden" name="PIMApi.Api.Post.saveProd" value="v1/product">
  {{ range .Data.ErplyApi.LanguageList }}
  <div class="form-field">
    <label for="formInputName{{ .IsoCode }}">Name ({{ .IsoCode }}):</label>
    <input type="text" id="formInputName{{ .IsoCode }}"
           name='PIMApi.Api.Json.saveProd.string.name.{{ .IsoCode }}'
           value='{{ $.Data.PIMApi.Api.Requests.saveProd.Json.Get (printf "name.%s" .IsoCode) }}'>
  </div>
  {{ end }}

  <button type="submit">Send</button>
</form>

Models sample:

{{ range.Data.ErplyApi.LanguageList }}
<div class="form-field">
  <label for="formInputName{{ .IsoCode }}">Name ({{ .IsoCode }}):</label>
  <input type="text" id="formInputName{{ .IsoCode }}"
         name="AccountAdminApi.WarehouseInput.Name.{{ .IsoCode }}"
         value="{{ index $.Data.AccountAdminApi.WarehouseInput.Name .IsoCode }}">
</div>
{{ end }}