1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-24 19:33:07 +01:00

Allow translation strings in different case

This commit is contained in:
FreeScout 2019-12-05 10:00:44 -08:00
parent 6acd19977c
commit 3adde31a47
3 changed files with 210 additions and 5 deletions

View File

@ -118,6 +118,7 @@
"vendor/nwidart/laravel-modules/src/Json.php",
"vendor/codedge/laravel-selfupdater/src/SourceRepositoryTypes/GithubRepositoryType.php",
"vendor/barryvdh/laravel-translation-manager/src/Manager.php",
"vendor/barryvdh/laravel-translation-manager/src/Controller.php",
"vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php",
"vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php",
"vendor/laravel/framework/src/Illuminate/Validation/Concerns/ValidatesAttributes.php",

View File

@ -0,0 +1,190 @@
<?php namespace Barryvdh\TranslationManager;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Barryvdh\TranslationManager\Models\Translation;
use Illuminate\Support\Collection;
class Controller extends BaseController
{
/** @var \Barryvdh\TranslationManager\Manager */
protected $manager;
public function __construct(Manager $manager)
{
$this->manager = $manager;
}
public function getIndex($group = null)
{
$locales = $this->manager->getLocales();
$groups = Translation::groupBy('group');
$excludedGroups = $this->manager->getConfig('exclude_groups');
if($excludedGroups){
$groups->whereNotIn('group', $excludedGroups);
}
$groups = $groups->select('group')->orderBy('group')->get()->pluck('group', 'group');
if ($groups instanceof Collection) {
$groups = $groups->all();
}
$groups = [''=>'Choose a group'] + $groups;
$numChanged = Translation::where('group', $group)->where('status', Translation::STATUS_CHANGED)->count();
$allTranslations = Translation::where('group', $group)->orderBy('key', 'asc')->get();
$numTranslations = count($allTranslations);
$translations = [];
foreach($allTranslations as $translation){
$translations[$translation->key][$translation->locale] = $translation;
}
return view('translation-manager::index')
->with('translations', $translations)
->with('locales', $locales)
->with('groups', $groups)
->with('group', $group)
->with('numTranslations', $numTranslations)
->with('numChanged', $numChanged)
->with('editUrl', action('\Barryvdh\TranslationManager\Controller@postEdit', [$group]))
->with('deleteEnabled', $this->manager->getConfig('delete_enabled'));
}
public function getView($group = null)
{
return $this->getIndex($group);
}
protected function loadLocales()
{
//Set the default locale as the first one.
$locales = Translation::groupBy('locale')
->select('locale')
->get()
->pluck('locale');
if ($locales instanceof Collection) {
$locales = $locales->all();
}
$locales = array_merge([config('app.locale')], $locales);
return array_unique($locales);
}
public function postAdd($group = null)
{
$keys = explode("\n", request()->get('keys'));
foreach($keys as $key){
$key = trim($key);
if($group && $key){
$this->manager->missingKey('*', $group, $key);
}
}
return redirect()->back();
}
public function postEdit($group = null)
{
if(!in_array($group, $this->manager->getConfig('exclude_groups'))) {
$name = request()->get('name');
$value = request()->get('value');
list($locale, $key) = explode('|', $name, 2);
// $translation = Translation::firstOrNew([
// 'locale' => $locale,
// 'group' => $group,
// 'key' => $key,
// ]);
try {
$translation = Translation::where('locale', $locale)
->where('group', $group)
->where(\DB::raw('BINARY `key`'), $key)
->first();
if (!$translation) {
$translation = new Translation();
$translation->locale = $locale;
$translation->group = $group;
$translation->key = $key;
}
} catch (\Exception $e) {
$translation = Translation::firstOrNew([
'locale' => $locale,
'group' => $group,
'key' => $key,
]);
}
$translation->value = (string) $value ?: null;
$translation->status = Translation::STATUS_CHANGED;
$translation->save();
return array('status' => 'ok');
}
}
public function postDelete($group = null, $key)
{
if(!in_array($group, $this->manager->getConfig('exclude_groups')) && $this->manager->getConfig('delete_enabled')) {
Translation::where('group', $group)->where('key', $key)->delete();
return ['status' => 'ok'];
}
}
public function postImport(Request $request)
{
$replace = $request->get('replace', false);
$counter = $this->manager->importTranslations($replace);
return ['status' => 'ok', 'counter' => $counter];
}
public function postFind()
{
$numFound = $this->manager->findTranslations();
return ['status' => 'ok', 'counter' => (int) $numFound];
}
public function postPublish($group = null)
{
$json = false;
if($group === '_json'){
$json = true;
}
$this->manager->exportTranslations($group, $json);
return ['status' => 'ok'];
}
public function postAddGroup(Request $request)
{
$group = str_replace(".", '', $request->input('new-group'));
if ($group)
{
return redirect()->action('\Barryvdh\TranslationManager\Controller@getView',$group);
}
else
{
return redirect()->back();
}
}
public function postAddLocale(Request $request)
{
$locales = $this->manager->getLocales();
$newLocale = str_replace([], '-', trim($request->input('new-locale')));
if (!$newLocale || in_array($newLocale, $locales)) {
return redirect()->back();
}
$this->manager->addLocale($newLocale);
return redirect()->back();
}
public function postRemoveLocale(Request $request)
{
foreach ($request->input('remove-locale', []) as $locale => $val) {
$this->manager->removeLocale($locale);
}
return redirect()->back();
}
}

View File

@ -390,11 +390,25 @@ class Manager
public function missingKey($namespace, $group, $key)
{
if (!in_array($group, $this->config['exclude_groups'])) {
Translation::firstOrCreate([
'locale' => $this->app['config']['app.locale'],
'group' => $group,
'key' => $key,
]);
try {
$translation = Translation::where('locale', $this->app['config']['app.locale'])
->where('group', $group)
->where(\DB::raw('BINARY `key`'), $key)
->first();
if (!$translation) {
$translation = new Translation();
$translation->locale = $this->app['config']['app.locale'];
$translation->group = $group;
$translation->key = $key;
$translation->save();
}
} catch (\Exception $e) {
Translation::firstOrCreate([
'locale' => $this->app['config']['app.locale'],
'group' => $group,
'key' => $key,
]);
}
}
}