You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using the Astrotomic\Translatable package, I encountered an issue where the model's translatable fields are being created in the wrong locale, despite explicitly setting the locale via app()->setLocale().
To Reproduce
Set the Accept-Language header in the request to "en".
In the application logic, set the locale to English using: app()->setLocale('fr');
Create a translatable model like this:
$skill = Skill::create(array_merge($skillData, [
'is_original' => 1,
'original_language' => app()->getLocale(),
]));
Expected behavior
The model's translatable attributes should be saved in all languages defined in the config file same as the second screenshot.
The original_language field in the translation table should correctly reflect 'fr' as true, since the locale was set with app()->setLocale('fr') before the model creation.
Actual Behavior
A translation is created in English (en) instead of French, despite the locale being set to 'fr'.
Additionally, sometimes only one language is being created other times both French and English translations are being created, with Englsih (en) set as the original language, even though it should be French (fr).
Troubleshooting Attempts
Manually setting the default locale using setDefaultLocale() did not resolve the issue.
Attempted to explicitly set the translation using translateOrNew(app()->getLocale()), but this is not scalable for my case and will be redundant since my app supports 5 languages for now
Screenshots
with header having Accept-Language 'en' and before creating the model setting the app()->setLocale('fr')
without changing the locale in the app using app()->setLocale():
Versions (please complete the following information)
PHP: 8.1
Database: postgres
Laravel: 10.10
Package: 11.12
The text was updated successfully, but these errors were encountered:
Describe the bug
While using the Astrotomic\Translatable package, I encountered an issue where the model's translatable fields are being created in the wrong locale, despite explicitly setting the locale via app()->setLocale().
To Reproduce
$skill = Skill::create(array_merge($skillData, [
'is_original' => 1,
'original_language' => app()->getLocale(),
]));
Expected behavior
Actual Behavior
Troubleshooting Attempts
Screenshots
with header having Accept-Language 'en' and before creating the model setting the app()->setLocale('fr')
without changing the locale in the app using app()->setLocale():
Versions (please complete the following information)
The text was updated successfully, but these errors were encountered: