Comments (5)
@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.
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.
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()
.
laravel-translatable/src/Translatable/Locales.php
Lines 46 to 49 in e3b20df
So we have two things:
- the
Locales::current()
is missing the return type-hintstring
- 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.
@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.
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)
- I want to get the both name in english and arabic in blade HOT 1
- SoftDelete on application translations HOT 1
- How to apply unique validation with locale HOT 1
- SQLSTATE[HY000]: General error: 1364 Field doesn't have a default value HOT 5
- I get unecessary foreach loop over all parent table for create/update translations table HOT 1
- Switch to Laravel Pint HOT 1
- Install phpstan/larastan
- Fix failing GitHub actions
- Add PHP versions to test matrix.
- Add Laravel11 support HOT 2
- Translate multiple model items without using App::setLocale() HOT 2
- Add PHPunit 11 support
- does not save model translations HOT 3
- Translation relation not working with fallback... HOT 6
- scopeOrderByTranslation really slow
- Bug in docs
- Second level relations translations are not lazy loaded
- Next level relations translations like hasMany are not lazy loaded HOT 1
- Route binding HOT 1
- translateOrNew not saving because of deleteTranslations HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-translatable.