Localization problems

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!
Danny
Posts: 1
Joined: 14 Feb 2019, 11:15

Localization problems

Post by Danny » 14 Feb 2019, 12:14

Hi,
We have created a simple localization management system in Laravel by creating a localization middleware like:
Http/Middleware/Localization.php
Inside there's some simple code to set the locale as Laravel's documentation recommends it.
It takes the first segment of the URI and tries to match either 'en' or 'it' and fallback to 'it' if it cannot match 'en'

Code: Select all

<?php

namespace App\Http\Middleware;
use Closure;

class Localization
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $language_code = \Request::segment(1);
        $locale = '';

        switch ($language_code) {
            case 'en':
                $locale = 'en';
                break;
            case 'it':
                $locale = 'it';
                break;
            default:
                $locale = 'it';
        }
        // 1.  Set Laravel's locale
        \App::setLocale($locale);
        // 2. Set Carbon's locale
        //\Carbon\Carbon::setLocale($locale); // Not enabled at the moment
        return $next($request);
    }
}

Laravel part seems to work ok with it.
The problem that we're having seems to be on one of the the checkout steps
More precisely, the one that has the URI like:
/en/default/checkout/delivery
After passing this steps the shopping cart seems to be empty or not found
If we repeat the checkout process, but in italian language, so this step has the URI like:
/it/default/checkout/delivery
Everything seems to be ok.
Putting some debugging code like:

Code: Select all

\Log::debug("Laravel locale is: " . app()->getLocale());
In ext/ai-controller-frontend/controller/frontend/src/Controller/Frontend/Basket/Base.php
Seems to give back something like:
Laravel locale is: it
Even though the page has the first URI prefix as /en'

So my questions are:
1. Is Aimeos interfering with the locale by Laravel's Localization middleware ?
2. Any idea why Laravel's locale is changed when there's a single setLocale function put in the Localization middleware
3. Is it possible to set the Aimeos locale from Laravel's Localization middleware in a somewhat similar way that we do it for Laravel with:

Code: Select all

\App::setLocale($locale);
4. Does the basket have its own independent locale, if yes, how do we set that ?
5. Can the language be changed independently of the current site or the language is tied in any way with one site ?

We use:
Laravel 5.4
Aimeos 2017.4 plus Market place extension
PHP 7.2.12

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

Re: Localization problems

Post by aimeos » 15 Feb 2019, 13:58

The language in Aimeos frontend should be always the one that's in the URL provided you've set the prefix for Aimeos routes accordingl ('prefix' => '{locale}/{site}' in your case):
- https://github.com/aimeos/aimeos-larave ... hop.php#L5
- https://aimeos.org/docs/Laravel/Configu ... he_routing
- https://aimeos.org/docs/Laravel/Add_loc ... tor#Routes

The languages must be also enabled in the Locale -> Language tab of the admin interface and there must be enabled site/language/currency combinations in the Locale tab.

The basket has items in the site/language/currency combination that has been used when adding the product to the basket. If the combination changes it tries to migrate the basket content to the new combination be refetching the items if possible: https://github.com/aimeos/ai-controller ... e.php#L133

That should all apply to your old (unsupported) version as well.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply