-
Hello. I've had to add a method resetDefaultLocale() to Locale that sets $defaultLocale = null and then: Locale::resetDefaultLocale();
Locale::clearCache();
Translator::forgetInstance(); Is there a better solution? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 3 replies
-
What EXACTLY are you trying to do here? |
Beta Was this translation helpful? Give feedback.
-
You do realize there is a public function setAttributeTranslated($key, $value, $locale = null) |
Beta Was this translation helpful? Give feedback.
-
I'm trying to load the initial data needed for an application to work. A list of locales (default is non-English) and some translatable data. This executes in one console command. I'm using setAttributeTranslated() passing the respective locale. But this method uses a value $this->translatableDefault that is obtained from Locale::getDefault(). This static property (defaultLocale) from Locale is protected and hasn't got accessor. The script then uses old defaultLocale (English) even though the default locale in the database has changed. |
Beta Was this translation helpful? Give feedback.
-
Before inserting the initial data, you should create the different locales using the use Winter\Translate\Models\Locale;
$locale = new Locale;
$locale->code = 'fr';
$locale->code = 'Francais';
$locale->is_enabled = 1;
$locale->makeDefault();
$locale->save(); Add as many as you need, but only one should be the default, of course. |
Beta Was this translation helpful? Give feedback.
-
The problem is that: $locale->makeDefault(); doesn't change Executing this command on a fresh install: public function handle()
{
$locale = new Locale;
$locale->code = 'fr';
$locale->name = 'Francais';
$locale->is_enabled = 1;
$locale->makeDefault();
$locale->save();
$this->line(Locale::getDefault()->code);
} gives output en instead fr. |
Beta Was this translation helpful? Give feedback.
-
Sorry, try saving the new locale first, then calling |
Beta Was this translation helpful? Give feedback.
-
No, that's not it either... I had to call |
Beta Was this translation helpful? Give feedback.
-
Can you try latest dev-develop version of the plugin, that should help with your use case. |
Beta Was this translation helpful? Give feedback.
Can you try latest dev-develop version of the plugin, that should help with your use case.