why aimeos doesn't save locale

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!
User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

why aimeos doesn't save locale

Post by ahmed31916 » 31 May 2022, 09:33

Hello,

Why aimeos doesn't save the locale of the user?
The locale was changed, but when I go to other page, it returns to the default locale.
this is the locale parameter that I passed to the route : "?locale=ar&currency=ILS".

Note: I didn't activate the multilocale option in the .env file. Is this the problem?

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

Re: why aimeos doesn't save locale

Post by aimeos » 31 May 2022, 09:39

Yes, you have to set SHOP_MULTILOCALE=true in your .env file
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: why aimeos doesn't save locale

Post by ahmed31916 » 31 May 2022, 11:12

I was afraid to turn it on because when I run "php artisan optimize", I got this:

Code: Select all

Route pattern "/{locale}/site/{locale}" cannot reference variable name "locale" more than once.

  at C:\xampp\htdocs\WomenTemplate\vendor\symfony\routing\RouteCompiler.php:144
    140▕             if (preg_match('/^\d/', $varName)) {
    141▕                 throw new \DomainException(sprintf('Variable name "%s" cannot start with a digit in route pattern "%s". Please use a different name.', $varName, $pattern));
    142▕             }
    143▕             if (\in_array($varName, $variables)) {
  ➜ 144▕                 throw new \LogicException(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $pattern, $varName));
    145▕             }
    146▕
    147▕             if (\strlen($varName) > self::VARIABLE_MAXIMUM_LENGTH) {
    148▕                 throw new \DomainException(sprintf('Variable name "%s" cannot be longer than %d characters in router than %d characters in route pattern "%s". Please use a shorter name.', $varName, self::VARIAB;LE_MAXIMUM_LENGTH, $pattern));

  1   C:\xampp\htdocs\WomenTemplate\vendor\symfony\routing\RouteCompiler.php:72                Route), "/{locale}/site/{loca
      Symfony\Component\Routing\RouteCompiler::compilePattern(Object(Symfony\Component\Routing\Route), "/{locale}/site/{locale}")

  2   C:\xampp\htdocs\WomenTemplate\vendor\symfony\routing\Route.php:410                       PS C:\xampp\htdocs\WomenTempl
      Symfony\Component\Routing\RouteCompiler::compile(Object(Symfony\Component\Routing\Route))

cyberdev
Posts: 14
Joined: 06 May 2022, 09:10

Re: why aimeos doesn't save locale

Post by cyberdev » 31 May 2022, 14:41

because you didn't register any local in you're app.
https://github.com/aimeos/aimeos/blob/m ... Locale.php

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: why aimeos doesn't save locale

Post by ahmed31916 » 01 Jun 2022, 06:09

I already added the locale. But the problem is from the format of the route.
All links must start with the locale id, and I have some have not.

It seems is solved.
Attachments
Screenshot 2022-06-01 091120.png
Screenshot 2022-06-01 091120.png (24.59 KiB) Viewed 1496 times

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

Re: why aimeos doesn't save locale

Post by aimeos » 01 Jun 2022, 09:32

In your ./config/shop.php, you've added the "{locale}" placeholder yourself to the routes and it's not allowed to use the same placeholder twice in an URL. Remove the "{locale}" string you've added to the routes and it will work with SHOP_MULTILOCALE=true
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: why aimeos doesn't save locale

Post by ahmed31916 » 04 Jun 2022, 12:38

Thanks, now I have no errors.
But, I have some notes:

- Can I overwrite "airoute" function?
- When I remove this from the url "?currency=USD", it go back to the default currency?
- Why in guest user, It doesn't store the locale in the session?

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

Re: why aimeos doesn't save locale

Post by aimeos » 06 Jun 2022, 06:43

ahmed31916 wrote: 04 Jun 2022, 12:38 - Can I overwrite "airoute" function?
If you define your own function before this code is executed, you can overwrite the function:
https://github.com/aimeos/aimeos-larave ... hp#L10-L33
ahmed31916 wrote: 04 Jun 2022, 12:38 - When I remove this from the url "?currency=USD", it go back to the default currency?
Yes, back the to first locale combination which is matching the language in the URL.
ahmed31916 wrote: 04 Jun 2022, 12:38 - Why in guest user, It doesn't store the locale in the session?
Whenever you save something into the session of a user but your content depends on it, it's impossible to cache the page.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: why aimeos doesn't save locale

Post by ahmed31916 » 06 Jun 2022, 06:51

Yes, back the to first locale combination which is matching the language in the URL.
Why not return the last currency that was traded?
Isn't this link set the locale of the app?

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

Re: why aimeos doesn't save locale

Post by aimeos » 06 Jun 2022, 07:00

You can have several locale combinations with the same language but different currencies. Thus, the currency must be added as well if you don't have only one combination. In that case, you should overwrite the airoute() function to leave out the currency if it's always the same or only depends on the language.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply