Multi language fields and localized filter

The purpose of this case is to give a practical example of the localized filter, allowing to add multiple languages in one and the same input field. This field is referred to as a multilanguage field.

Imagine that you want to make a legal document in a reconciliation ‘legal_document’ where we give an overview of all persons with an intrest in the company and the nature of their shares. This nature can be described in multiple languages:

{% t= "Nature" nl:"Aard" fr:"Nature" en:"Nature" de:"Art" %}
{% t= "Full ownership" nl:"Volle eigendom" fr:"Pleine propriété" en:"Full ownership" de:"Volleigentum" %}
{% t= "Bare ownership" fr:"Nue-propriété" en:"Bare ownership" nl:"Naakte eigendom" de:"Bloßes Eigentum" %}
{% t= "Usufruct" nl:"Vruchtgebruik" fr:"Usufruit" en:"Usufruct" de:"Nießbrauch" %}
{% t= "Indivisibility" nl:"Onverdeeldheid" fr:"Indivisibilité" en:"Indivisibility" de:"Unteilbarkeit" %}
{% t= "Name"  nl:"Naam" fr:"Nom"  en:"Last name" de:"Name" %}
{% t= "Amount of votes" nl:"Aantal stemrechten" fr:"Nombre de droits de vote" en:"Amount of votes" de:"Stimmrechte verbunden mit Wertpapieren" %}

We start with calling the period.people drop, which contains all shareholders and directors.

{% for person in period.people %}
| **{% t "Name" %}**
| {% input person.custom.name default:person.name placeholder:'Naam' %}

Imagine that you have a variable person.custom.kind_of_shares, coming from the the company details, filled with data about the stock type. {% assign stock_type = person.custom.kind_of_shares %}
This data serves as a default for your local input field person.custom.aard

| **{% t "Nature" %}** {% input person.custom.aard localized:true default:stock_type placeholder:"Nature" %}

Due to the fallback procedure, we want to keep a fallback to the default of the stock type for further usage of this variable.
Be aware, when you assign the localized variable, you have to make sure that the localized filter is directly after the custom and not after the default. Otherwise, liquid will try to localize the default and this will throw a liquid error.

{% assign kind_share = person.custom.aard | localized | default:stock_type %}

You can now use the localized kind_share in further logic, for instance if the nature is filled in, we also want an input field appearing where we can enter the amount of votes:

{% if kind_share != blank %}
  | {% input person.custom.amount_votes placeholder:'Amount of votes' %}
{% endif %}

For further usage of the stock_type, we also want to be able to catch the result. We also want ofcourse that the nature of the stock type is linked to the right person. therefor, we will use dynamic variables and results.

To create a dynamic result, we will capture an unique locale variable name per person by using the unique person.id:

{% capture stock_type_key %}person_{{ person.id }}_stock_type{% endcapture %}

This unique dynamic variable name can be used to assign the right stock type to the right person:

{% assign [stock_type] = kind_share %}}

Now we will fill the stock_type_key, with the dynamic kind of shares

{% result stock_type_key [stock_type] %}

Calling up the result on another reconciliation template, can be done by creating the same stock_type_key from the original reconciliation (legal_document) into the destination reconciliation and calling up the dynamic result behind the key [stock_type_key]:

{% capture stock_type_key %}person_{{ person.id }}_stock_type{% endcapture %}
{% assign kind_share = period.reconciliations.legal_document.results.[stock_type_key] %}

Full code:

{% t= "Nature" nl:"Aard" fr:"Nature" en:"Nature" de:"Art" %}
{% t= "Full ownership" nl:"Volle eigendom" fr:"Pleine propriété" en:"Full ownership" de:"Volleigentum" %}
{% t= "Bare ownership" fr:"Nue-propriété" en:"Bare ownership" nl:"Naakte eigendom" de:"Bloßes Eigentum" %}
{% t= "Usufruct" nl:"Vruchtgebruik" fr:"Usufruit" en:"Usufruct" de:"Nießbrauch" %}
{% t= "Indivisibility" nl:"Onverdeeldheid" fr:"Indivisibilité" en:"Indivisibility" de:"Unteilbarkeit" %}
{% t= "Name"  nl:"Naam" fr:"Nom"  en:"Last name" de:"Name" %}
{% t= "Amount of votes" nl:"Aantal stemrechten" fr:"Nombre de droits de vote" en:"Amount of votes" de:"Stimmrechte verbunden mit Wertpapieren" %}

{% stripnewlines %}
| {% t "Name" %}
| 
| {% t "Nature" %}
|
| {% t "Amount of votes" %}
{% newline %}
|---20%----
|---20%-----
|---20%-----
|---20%-----
|---20%----#
{% newline %}

{% for person in period.people %}
| **{% t "Name" %}**
| {% input person.custom.name default:person.name placeholder:'Naam' %}

{% assign stock_type = person.custom.kind_of_shares %}.
  
| **{% t "Nature" %}** 
| {% input person.custom.aard localized:true default:stock_type placeholder:"Nature" %}

    {% assign kind_share = person.custom.aard | localized | default:stock_type %}

{% if kind_share != blank %}
    | {% input person.custom.amount_votes placeholder:'Amount of votes' %}
{% endif %}
{% newline %}

{% comment %}Create dynamic result {% endcomment %}
  {% capture stock_type_key %}person_{{ person.id }}_stock_type{% endcapture %}
  {% assign [stock_type] = kind_share %}
  {% result stock_type_key [stock_type] %}
  {% result 'name' content %}

{% endfor %}
{% endstripnewlines %}  

  {% capture stock_type_key %}person_{{ person.id }}_stock_type{% endcapture %}
  {% assign kind_share = period.reconciliations.vkt_8.results.[stock_type_key] %}