View on GitLab

Translations

Many parameters provide a translatable alternative: when populated with an identifier for the native Laravel's localization functions, those assign a translated string to the reference attribute.

@php
App::setLocale('it');
@endphp

<x-ls::button tlabel="example.label" />
<button id="button-e6410fbd" class="btn btn-primary">Questa è una etichetta</button>

t

  • tcontent translates content
  • tcontentfrom translates contentfrom . This is a bit of exception: the string is not directly translated, but used to refer another (custom and arbitrary) parameter from which retrieve the identifier for the translation..
Parametro da controllare Nome
[
    'customs' => [
        'errorbadge' => [
            'extends' => 't',
            'params' => [
                'node' => 'span',
                'classes' => ['d-flex'],
                'innerAppendNodes' => [
                    [
                        'extends' => 't',
                        'params' => [
                            'node' => 'span',
                            'tcontent' => 'example.check',
                            'classes' => ['badge', 'text-bg-danger', 'rounded-start-pill'],
                        ],
                    ],
                    [
                        'extends' => 't',
                        'params' => [
                            'node' => 'span',
                            'classes' => ['badge', 'text-bg-secondary', 'rounded-end-pill'],
                            'tcontentfrom' => 'status'
                        ],
                    ],
                ]
            ],
        ],
    ],
]
<x-ls::errorbadge status="example.name" />
<span id="basenode-29b79507" class="d-flex" status="example.name"><span id="basenode-db36945a" class="badge text-bg-danger rounded-start-pill" status="example.name">Parametro da controllare</span> <span id="basenode-8ecd17db" class="badge text-bg-secondary rounded-end-pill" status="example.name">Nome</span></span>

button

  • tlabel translates label
  • ttitle translates title

field

Those attributes are inherited by all Inputs and other components usually used in Forms.

  • tlabel translates label
  • thelp translates help
  • tpophelp translates pophelp
@php
App::setLocale('it');
@endphp

<x-ls::text tlabel="example.name" />
<x-ls::email tlabel="example.email" />
<div class="row mb-3">
  <label for="input-cd22d0fe" class="col-4 col-form-label">Nome</label>
  <div class="col-8">
    <input id="input-cd22d0fe" type="text" class="form-control" name="q0gzBiwBzd" value="">
  </div>
</div>
<div class="row mb-3">
  <label for="input-f8d3c4e2" class="col-4 col-form-label">Indirizzo E-Mail</label>
  <div class="col-8">
    <input id="input-f8d3c4e2" type="email" class="form-control" name="GFkf0gx9Zn" value="">
  </div>
</div>

input

  • tplaceholder translates placeholder
  • ttextprepend translates textprepend
  • ttextappend translates textappend

checks, radios, select

Within the "options" parameter of Select, Checks and other similar widgets, it is possible to use dedicated attributes for strings to be translated.

  • options.tlabel translates options.label

pophelp

  • ttext translates text

accordionitem

  • tlabel translates label

tabpane

  • tlabel translates label

Custom function

Optionally you can define your own function to resolve translations starting from the identifier passed as parameter to each component, instead of native __() Laravel function.

Add a translate key to the global configuration array in config/larastrap.php.

[
    'translate' => function($identifier) {
        return myOwnFunction($identifier);
    }
]