Translate functionality

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kartikbhat
Posts: 40
Joined: 02 Dec 2021, 17:18

Translate functionality

Post by kartikbhat » 16 Feb 2023, 15:51

What is the difference between

Code: Select all

$this->translate( 'admin', 'Basic' )
and

aitrans( 'Top', $params = [], $domain = 'client', $locale = null )

When to use which method?

TIA :)

User avatar
aimeos
Administrator
Posts: 7889
Joined: 01 Jan 1970, 00:00

Re: Translate functionality

Post by aimeos » 19 Feb 2023, 10:27

"aitrans()" is a helper method you can use in Blade templates to access Aimeos translations, "$this->translate()" is a view helper only available in Aimeos views.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kartikbhat
Posts: 40
Joined: 02 Dec 2021, 17:18

Re: Translate functionality

Post by kartikbhat » 20 Feb 2023, 06:15

What to pass for the parameters of the aitrans() function

Code: Select all

aitrans( 'Top', $params = [], $domain = 'client', $locale = null )

$params...
$domain...
$locale...

can I get a information on what these parameters indicate and how to pass language key in this function call ?

TIA :)

User avatar
aimeos
Administrator
Posts: 7889
Joined: 01 Jan 1970, 00:00

Re: Translate functionality

Post by aimeos » 21 Feb 2023, 08:30

The documentation for aitrans() is available here:
https://aimeos.org/docs/latest/laravel/ ... anslations

The parameters are:
- $singular : Text to translate
- $params : Array of values if $singular contains sprintf() placeholders (e.g. %1$s)
- $domain : Translation domain (same as first parameter for $this->translate())
- $locale : Language code if different from the one for the page

For your example:

Code: Select all

aitrans('Top')
With placeholders:

Code: Select all

aitrans('%1$s results found', [10])
With different domain:

Code: Select all

aitrans('price:default', [], 'client/ext')
Output French translation in e.g. a page with English texts:

Code: Select all

aitrans('Top', [], 'client', 'fr)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kartikbhat
Posts: 40
Joined: 02 Dec 2021, 17:18

Re: Translate functionality

Post by kartikbhat » 21 Feb 2023, 08:42

Thank you for the detailed explaination

I didn't got the value 'client' - a third parameter

is it a index present in shop.php ?

Code: Select all

'client' => [
  'en'=>[
      'header'=>[
          'key1'=>'value2',
          'key2'=>'value2',
        ],
      'footer'=>[
            'key3'=>'value3',
            'key4'=>'value4',
       ]
   ],
   'fr'=>[
      'header'=>[
          'key1'=>'value2',
          'key2'=>'value2',
        ],
      'footer'=>[
            'key3'=>'value3',
            'key4'=>'value4',
       ]
   ],
   'de'=>[
      'header'=>[
          'key1'=>'value2',
          'key2'=>'value2',
        ],
      'footer'=>[
            'key3'=>'value3',
            'key4'=>'value4',
       ]
   ]
]
how these values can be access from aitrans() function

Please let me know...

TIA :)

User avatar
aimeos
Administrator
Posts: 7889
Joined: 01 Jan 1970, 00:00

Re: Translate functionality

Post by aimeos » 22 Feb 2023, 15:39

Yes, the third parameter matches e.g. the

Code: Select all

'i18n' => ['client' => []]
// or
'i18n' => ['client/ext' => []]
key in your ./config/shop.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kartikbhat
Posts: 40
Joined: 02 Dec 2021, 17:18

Re: Translate functionality

Post by kartikbhat » 25 Apr 2023, 11:09

How to maintain separate files for multiple language keys, as I have huge set of translative sentences/words, as we do in Laravel, separate folder for each languages.
Is it possible in Aimeos ? how we can access from either $translate or aitrans() functions ?

User avatar
aimeos
Administrator
Posts: 7889
Joined: 01 Jan 1970, 00:00

Re: Translate functionality

Post by aimeos » 29 Apr 2023, 07:18

For a large list of translations, use the Gettext files instead where you have one file per language in an optimized binary format:
https://aimeos.org/docs/latest/developer/translations/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply