Giter Club home page Giter Club logo

Comments (5)

BAKTETE avatar BAKTETE commented on July 23, 2024 1

@Gummibeer the solution is to update a line in translatable.php file inside config
'locale' => null,
to
'locale' => 'fr',
your approach of

dump($this->config->get('translatable.locale'));
dd($this->translator->getLocale());

lead to that solution all works fine now thank you

from laravel-translatable.

BAKTETE avatar BAKTETE commented on July 23, 2024

The session locale was empty that's what's triggering the error i managed to solve by adding the following code in AppServiceProvider.php inside method boot() :

public function boot() {
        Schema::defaultStringLength(400);
        
       //check if current locale is empty if so a default locale must be provided 
        if(!Session::has('locale')) {
            session(['local' => 'fr']);
        }
        setlocale(LC_ALL, config('app.locale') . '.utf8');
        Carbon::setLocale(config('app.locale'));
}

any other suggestions will be appreciated

from laravel-translatable.

Gummibeer avatar Gummibeer commented on July 23, 2024

Hey @BAKTETE ,

by default Laravel should have a locale at every time - except you set the locale to null. The config('app.locale') is used by default for the whole app - this includes the translator which is used in Locales::current().

public function current()
{
return $this->config->get('translatable.locale') ?: $this->translator->getLocale();
}

So we have two things:

  1. the Locales::current() is missing the return type-hint string
  2. in your app the translator doesn't have a locale

Could you debug/dump the two possible return values of the Locales::current() method? Just put a dump() with both values inside the method.

public function current() 
{ 
     dump($this->config->get('translatable.locale'));
     dd($this->translator->getLocale());
     return $this->config->get('translatable.locale') ?: $this->translator->getLocale(); 
} 

from laravel-translatable.

BAKTETE avatar BAKTETE commented on July 23, 2024

@Gummibeer
dump($this->config->get('translatable.locale')); output : "fr"
dd($this->translator->getLocale()); output : null

i have a lang switcher based on sessions when the sesssion expires it leaves the locale empty
as for the package config('translatable.locale')
so the Default locale is covering that up when change from null to desire locale (that's the solution)

from laravel-translatable.

Gummibeer avatar Gummibeer commented on July 23, 2024

Ok, so you found a solution for your app or do we have to change something in the package?
If I understood it right everything fine now?

from laravel-translatable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.