I want to use translation strings as key, how to do it in laravel modules?
https://laravel.com/docs/6.x/localization#using-translation-strings-as-keys
I've tried adding the json file to modules lang folder. e.g. Modules\ModuleName\Resources\lang\id.json but laravel doesn't read it.
Does laravel modules support Translation Strings As Keys? (Not short key translation).
Thanks
Hi @dexcell,
This package can help you => laravel-json-translation-loader
@JamesHemery
Thank you! i will have a look at it
I'll close this as there hasn't been a reply in a while, feel free to comment if needed.
Unfortunately there is still no solution for this.
This is not related to this package as far as I can see. Users can choose to do this however they prefer.
Hi thank you for the reply,
I'm sorry i have to a bit disagree, i think laravel modules should support default laravel translation out of the box.
Since default laravel offers translation strings as keys, then i want to use it inside the modules just like normal laravel app. (isn't that the purpose of laravel modules?).
For now i managed to load the json translation manually by adding loadJsonTranslationsFrom inside registerTranslation function in service provider file.
I hope the generator would done this automatically (e.g php artisan module:make ModuleName)
````
/**
* Register translations.
*
* @return void
*/
public function registerTranslations()
{
$langPath = resource_path('lang/modules/modulename');
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, 'modulename');
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path('ModuleName', 'Resources/lang'), 'modulename');
$this->loadJsonTranslationsFrom(module_path('ModuleName', 'Resources/lang'));
}
}
````
This package supports laravel translations out of the box. Both json and the PHP array way.
Unfortunately on my test it doesn't load the json translation file, only the PHP array way.
(On laravel v6) i haven't tried the v7 yet.
After i added loadJsonTranslationsFrom then it does read the json file correctly.
Looks like loadTranslationsFrom only load php array translation.
Sorry, i mean json translation file without prefixing.
I use this
$this->loadJsonTranslationsFrom(__DIR__.'/../Resources/Lang');
Most helpful comment
I use this
$this->loadJsonTranslationsFrom(__DIR__.'/../Resources/Lang');