LaravelLocalization 无法转换 nwidart laravel 模块的路由
LaravelLocalization failing to translate routes of nwidart laravel modules
我不明白为什么 Laravel本地化无法翻译我在模块的 routes.php (Modules/ModuleName/Http/routes.php) 文件中声明的路由我使用 nwidart laravel-modules 包为 laravel、'localize' (\Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class) 创建的中间件也存在于应用程序的 Kernel.php 和 here 中所述的路由组中。路由未转换并显示为 /en/booking::all.companies.index 而不是 /en/companies(或 /ru/kompanii):
Route::group(
[
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['web', 'auth', 'localize', 'optimizeImages'],
'namespace' => 'Modules\Booking\Http\Controllers',
],
function() {
Route::get(LaravelLocalization::transRoute('booking::all.companies.index'), 'CompanyController@index')->name('booking.companies.index');
});
但是当模块名称空间前缀 "booking::" 从翻译字符串中移除时(LaravelLocalization::transRoute('all.companies.index') 而不是 LaravelLocalization::transRoute('booking::all.companies.index')) 它可以翻译路线。
请帮我解决问题,谢谢。
(我的安装如果有帮助:Laravel Framework 5.5.43,"mcamara/laravel-localization":“1.3”,"nwidart/laravel-modules":“2.7”。除了[之外没有安装其他本地化包=31=])
我遇到了同样的问题,网上没有找到解决方法。这是我解决问题的方法:
在Modules\[MyModule]\Providers\RouteServiceProvider
中:
/**
* Register translations.
*
* @return void
*/
protected function registerTranslations()
{
$module_path = 'MyModule';
$module_slug = 'my-module';
$langPath = resource_path('lang/modules/'.$module_slug);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $module_slug);
} else {
$this->loadTranslationsFrom(module_path(module_path, 'Resources/lang'),$module_slug);
}
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->registerTranslations();
$this->mapApiRoutes();
$this->mapWebRoutes();
}
我不明白为什么 Laravel本地化无法翻译我在模块的 routes.php (Modules/ModuleName/Http/routes.php) 文件中声明的路由我使用 nwidart laravel-modules 包为 laravel、'localize' (\Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class) 创建的中间件也存在于应用程序的 Kernel.php 和 here 中所述的路由组中。路由未转换并显示为 /en/booking::all.companies.index 而不是 /en/companies(或 /ru/kompanii):
Route::group(
[
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['web', 'auth', 'localize', 'optimizeImages'],
'namespace' => 'Modules\Booking\Http\Controllers',
],
function() {
Route::get(LaravelLocalization::transRoute('booking::all.companies.index'), 'CompanyController@index')->name('booking.companies.index');
});
但是当模块名称空间前缀 "booking::" 从翻译字符串中移除时(LaravelLocalization::transRoute('all.companies.index') 而不是 LaravelLocalization::transRoute('booking::all.companies.index')) 它可以翻译路线。
请帮我解决问题,谢谢。
(我的安装如果有帮助:Laravel Framework 5.5.43,"mcamara/laravel-localization":“1.3”,"nwidart/laravel-modules":“2.7”。除了[之外没有安装其他本地化包=31=])
我遇到了同样的问题,网上没有找到解决方法。这是我解决问题的方法:
在Modules\[MyModule]\Providers\RouteServiceProvider
中:
/**
* Register translations.
*
* @return void
*/
protected function registerTranslations()
{
$module_path = 'MyModule';
$module_slug = 'my-module';
$langPath = resource_path('lang/modules/'.$module_slug);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $module_slug);
} else {
$this->loadTranslationsFrom(module_path(module_path, 'Resources/lang'),$module_slug);
}
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->registerTranslations();
$this->mapApiRoutes();
$this->mapWebRoutes();
}