Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[L 5.2] locale prefix not detected #37

Closed
thku opened this issue Mar 15, 2016 · 3 comments
Closed

[L 5.2] locale prefix not detected #37

thku opened this issue Mar 15, 2016 · 3 comments

Comments

@thku
Copy link
Contributor

thku commented Mar 15, 2016

The browser is correctly redirected (e.g. /en) but laravel throws an NotFoundHttpException error. Maybe I just did a misconfiguration, but \Log::debug($localizer->localeFromRequest()) returns an empty value.

routes.php

// bug fix for Waavi…::localeFromRequest() problem
$localizer = \App::make(\Waavi\Translation\UriLocalizer::class);

Route::group(['prefix' => $localizer->localeFromRequest(), 'middleware' => 'web'], function () {
    Route::get('/', function () {
        return view('welcome');
     });
});

I added the localize middleware to the web middleware group.
As soon as I change the following

Repositories/LanguageRepository.php

/**
 *  Returns a list of all available locales.
 *
 *  @return array
 */
public function availableLocales()
{
    /*if ($this->config->has('translator.locales')) {
        return $this->config->get('translator.locales');
    }
    if ($this->tableExists()) {
        $locales = $this->model->distinct()->get()->lists('locale')->toArray();
        $this->config->set('translator.locales', $locales);
        return $locales;
    }*/
    return $this->defaultAvailableLocales;
}

Everything seems to work…

@sildraug
Copy link
Contributor

Have you loaded your available languages into the database? You need to have at least the default language entry for the package to work. Since you are using english, please check your translator_languages table has at least one entry like so:

id 1
locale en
name English

Let me know if this helps!

@thku
Copy link
Contributor Author

thku commented Mar 16, 2016

Did throw SQL error with 2.1.4 but works now with 2.1.4.1

@sildraug
Copy link
Contributor

Perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants