joedixon/laravel-translation 没有更新
joedixon/laravel-translation not updating
我刚刚在 Laravel 版本 8 中安装了一个 Joedixon/Laravel-translation 软件包。
它显示了文字,但是当我想更新时它不起作用。
我做了文档中所说的所有事情,而且我已经阅读了这篇关于它的文章,但它也没有用。
https://github.com/joedixon/laravel-translation/issues/82
备注:
1:我把驱动换成了数据库。
2:添加新语言效果很好
3:在添加新翻译时,它会在 http:///localhost/languages/en 而不是 http:///localhost/project_name/languages/en
中搜索
当我尝试更新一个词时,控制台显示 404 未找到:
路线:
ticate:sanctum |
| | POST | api/login | | App\Http\Controllers\Auth\AuthController@login | api
|
| | POST | api/register | | App\Http\Controllers\Auth\AuthController@register | api
|
| | GET|HEAD | api/user | | Closure | api
|
| | | | | | App\Http\Middleware\Authenticate:sanctum |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web
|
| | | | | | App\Http\Middleware\Authenticate |
| | GET|HEAD | languages | languages.index | JoeDixon\Translation\Http\Controllers\LanguageController@index | web
|
| | POST | languages | languages.store | JoeDixon\Translation\Http\Controllers\LanguageController@store | web
|
| | GET|HEAD | languages/create | languages.create | JoeDixon\Translation\Http\Controllers\LanguageController@create | web
|
| | POST | languages/{language} | languages.translations.update | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@update | web
|
| | GET|HEAD | languages/{language}/translations | languages.translations.index | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@index | web
|
| | POST | languages/{language}/translations | languages.translations.store | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@store | web
|
| | GET|HEAD | languages/{language}/translations/create | languages.translations.create | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@create | web
|
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web
语言翻译控制器
<?php
namespace JoeDixon\Translation\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use JoeDixon\Translation\Drivers\Translation;
use JoeDixon\Translation\Http\Requests\TranslationRequest;
class LanguageTranslationController extends Controller
{
private $translation;
public function __construct(Translation $translation)
{
$this->translation = $translation;
}
public function index(Request $request, $language)
{
// dd($this->translation->getSingleTranslationsFor('en'));
if ($request->has('language') && $request->get('language') !== $language) {
return redirect()
->route('languages.translations.index', ['language' => $request->get('language'), 'group' => $request->get('group'), 'filter' => $request->get('filter')]);
}
$languages = $this->translation->allLanguages();
$groups = $this->translation->getGroupsFor(config('app.locale'))->merge('single');
$translations = $this->translation->filterTranslationsFor($language, $request->get('filter'));
if ($request->has('group') && $request->get('group')) {
if ($request->get('group') === 'single') {
$translations = $translations->get('single');
$translations = new Collection(['single' => $translations]);
} else {
$translations = $translations->get('group')->filter(function ($values, $group) use ($request) {
return $group === $request->get('group');
});
$translations = new Collection(['group' => $translations]);
}
}
return view('translation::languages.translations.index', compact('language', 'languages', 'groups', 'translations'));
}
public function create(Request $request, $language)
{
return view('translation::languages.translations.create', compact('language'));
}
public function store(TranslationRequest $request, $language)
{
if ($request->filled('group')) {
$namespace = $request->has('namespace') && $request->get('namespace') ? "{$request->get('namespace')}::" : '';
$this->translation->addGroupTranslation($language, "{$namespace}{$request->get('group')}", $request->get('key'), $request->get('value') ?: '');
} else {
$this->translation->addSingleTranslation($language, 'single', $request->get('key'), $request->get('value') ?: '');
}
return redirect()
->route('languages.translations.index', $language)
->with('success', __('translation::translation.translation_added'));
}
public function update(Request $request, $language)
{
if (! Str::contains($request->get('group'), 'single')) {
$this->translation->addGroupTranslation($language, $request->get('group'), $request->get('key'), $request->get('value') ?: '');
} else {
$this->translation->addSingleTranslation($language, $request->get('group'), $request->get('key'), $request->get('value') ?: '');
}
return ['success' => true];
}
}
路线列表
<?php
Route::group(config('translation.route_group_config') + ['namespace' => 'JoeDixon\Translation\Http\Controllers'], function ($router) {
$router->get(config('translation.ui_url'), 'LanguageController@index')
->name('languages.index');
$router->get(config('translation.ui_url').'/create', 'LanguageController@create')
->name('languages.create');
$router->post(config('translation.ui_url'), 'LanguageController@store')
->name('languages.store');
$router->get(config('translation.ui_url').'/{language}/translations', 'LanguageTranslationController@index')
->name('languages.translations.index');
$router->post(config('translation.ui_url').'/{language}', 'LanguageTranslationController@update')
->name('languages.translations.update');
$router->get(config('translation.ui_url').'/{language}/translations/create', 'LanguageTranslationController@create')
->name('languages.translations.create');
$router->post(config('translation.ui_url').'/{language}/translations', 'LanguageTranslationController@store')
->name('languages.translations.store');
});
你运行
php artisan optimize
自安装后清除路由缓存并允许它获取您添加到 web.php 的新路由?
我解决了完全在不同地方的问题
它在 public/vendor/translation/js/app.js
methods: {
setActive: function () {
this.isActive = !0, this.$refs.trans.focus()
},
storeTranslation: function () {
var e = this;
this.isActive = !1, this.hasChanged && (this.isLoading = !0, window.axios.post
("/MY_PROJECT_NAME/public".concat("/").concat(this.route, "/").concat(this.language), {
language: this.language,
group: this.group,
key: this.translationKey,
value: this.translation
}).then((function (t) {
e.hasSaved = !0, e.isLoading = !1, e.hasChanged = !1
})).catch((function (t) {
e.hasErrored = !0, e.isLoading = !1
})))
}
},
刚刚添加 ("/MY_PROJECT_NAME/public".concat("/") 问题解决了
我刚刚在 Laravel 版本 8 中安装了一个 Joedixon/Laravel-translation 软件包。 它显示了文字,但是当我想更新时它不起作用。 我做了文档中所说的所有事情,而且我已经阅读了这篇关于它的文章,但它也没有用。 https://github.com/joedixon/laravel-translation/issues/82
备注:
1:我把驱动换成了数据库。
2:添加新语言效果很好
3:在添加新翻译时,它会在 http:///localhost/languages/en 而不是 http:///localhost/project_name/languages/en
中搜索当我尝试更新一个词时,控制台显示 404 未找到:
ticate:sanctum |
| | POST | api/login | | App\Http\Controllers\Auth\AuthController@login | api
|
| | POST | api/register | | App\Http\Controllers\Auth\AuthController@register | api
|
| | GET|HEAD | api/user | | Closure | api
|
| | | | | | App\Http\Middleware\Authenticate:sanctum |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web
|
| | | | | | App\Http\Middleware\Authenticate |
| | GET|HEAD | languages | languages.index | JoeDixon\Translation\Http\Controllers\LanguageController@index | web
|
| | POST | languages | languages.store | JoeDixon\Translation\Http\Controllers\LanguageController@store | web
|
| | GET|HEAD | languages/create | languages.create | JoeDixon\Translation\Http\Controllers\LanguageController@create | web
|
| | POST | languages/{language} | languages.translations.update | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@update | web
|
| | GET|HEAD | languages/{language}/translations | languages.translations.index | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@index | web
|
| | POST | languages/{language}/translations | languages.translations.store | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@store | web
|
| | GET|HEAD | languages/{language}/translations/create | languages.translations.create | JoeDixon\Translation\Http\Controllers\LanguageTranslationController@create | web
|
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web
语言翻译控制器
<?php
namespace JoeDixon\Translation\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use JoeDixon\Translation\Drivers\Translation;
use JoeDixon\Translation\Http\Requests\TranslationRequest;
class LanguageTranslationController extends Controller
{
private $translation;
public function __construct(Translation $translation)
{
$this->translation = $translation;
}
public function index(Request $request, $language)
{
// dd($this->translation->getSingleTranslationsFor('en'));
if ($request->has('language') && $request->get('language') !== $language) {
return redirect()
->route('languages.translations.index', ['language' => $request->get('language'), 'group' => $request->get('group'), 'filter' => $request->get('filter')]);
}
$languages = $this->translation->allLanguages();
$groups = $this->translation->getGroupsFor(config('app.locale'))->merge('single');
$translations = $this->translation->filterTranslationsFor($language, $request->get('filter'));
if ($request->has('group') && $request->get('group')) {
if ($request->get('group') === 'single') {
$translations = $translations->get('single');
$translations = new Collection(['single' => $translations]);
} else {
$translations = $translations->get('group')->filter(function ($values, $group) use ($request) {
return $group === $request->get('group');
});
$translations = new Collection(['group' => $translations]);
}
}
return view('translation::languages.translations.index', compact('language', 'languages', 'groups', 'translations'));
}
public function create(Request $request, $language)
{
return view('translation::languages.translations.create', compact('language'));
}
public function store(TranslationRequest $request, $language)
{
if ($request->filled('group')) {
$namespace = $request->has('namespace') && $request->get('namespace') ? "{$request->get('namespace')}::" : '';
$this->translation->addGroupTranslation($language, "{$namespace}{$request->get('group')}", $request->get('key'), $request->get('value') ?: '');
} else {
$this->translation->addSingleTranslation($language, 'single', $request->get('key'), $request->get('value') ?: '');
}
return redirect()
->route('languages.translations.index', $language)
->with('success', __('translation::translation.translation_added'));
}
public function update(Request $request, $language)
{
if (! Str::contains($request->get('group'), 'single')) {
$this->translation->addGroupTranslation($language, $request->get('group'), $request->get('key'), $request->get('value') ?: '');
} else {
$this->translation->addSingleTranslation($language, $request->get('group'), $request->get('key'), $request->get('value') ?: '');
}
return ['success' => true];
}
}
路线列表
<?php
Route::group(config('translation.route_group_config') + ['namespace' => 'JoeDixon\Translation\Http\Controllers'], function ($router) {
$router->get(config('translation.ui_url'), 'LanguageController@index')
->name('languages.index');
$router->get(config('translation.ui_url').'/create', 'LanguageController@create')
->name('languages.create');
$router->post(config('translation.ui_url'), 'LanguageController@store')
->name('languages.store');
$router->get(config('translation.ui_url').'/{language}/translations', 'LanguageTranslationController@index')
->name('languages.translations.index');
$router->post(config('translation.ui_url').'/{language}', 'LanguageTranslationController@update')
->name('languages.translations.update');
$router->get(config('translation.ui_url').'/{language}/translations/create', 'LanguageTranslationController@create')
->name('languages.translations.create');
$router->post(config('translation.ui_url').'/{language}/translations', 'LanguageTranslationController@store')
->name('languages.translations.store');
});
你运行
php artisan optimize
自安装后清除路由缓存并允许它获取您添加到 web.php 的新路由?
我解决了完全在不同地方的问题
它在 public/vendor/translation/js/app.js
methods: {
setActive: function () {
this.isActive = !0, this.$refs.trans.focus()
},
storeTranslation: function () {
var e = this;
this.isActive = !1, this.hasChanged && (this.isLoading = !0, window.axios.post
("/MY_PROJECT_NAME/public".concat("/").concat(this.route, "/").concat(this.language), {
language: this.language,
group: this.group,
key: this.translationKey,
value: this.translation
}).then((function (t) {
e.hasSaved = !0, e.isLoading = !1, e.hasChanged = !1
})).catch((function (t) {
e.hasErrored = !0, e.isLoading = !1
})))
}
},
刚刚添加 ("/MY_PROJECT_NAME/public".concat("/") 问题解决了