Merge remote-tracking branch 'origin/master' into oasis

# Conflicts:
#	public/js/main.js
#	public/mix-manifest.json
This commit is contained in:
Peter Papp
2021-04-06 10:02:20 +02:00
10 changed files with 234 additions and 46 deletions
-32
View File
@@ -8,7 +8,6 @@ use App\Models\Share;
use Aws\Exception\MultipartUploadException;
use Aws\S3\MultipartUploader;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
@@ -323,35 +322,4 @@ class HelperService
}
}
}
/**
* @param $license
* @param $locale
*/
function create_default_language_translations($license, $locale)
{
$translations = [
'extended' => collect([
config("language-translations.extended"),
config("language-translations.regular"),
config("custom-language-translations")
])->collapse(),
'regular' => collect([
config("language-translations.regular"),
config("custom-language-translations")
])->collapse(),
];
$translations = $translations[strtolower($license)]
->map(function ($value, $key) use ($locale) {
return [
'lang' => $locale,
'value' => $value,
'key' => $key,
];
})->toArray();
DB::table('language_translations')
->insert($translations);
}
}
+93
View File
@@ -0,0 +1,93 @@
<?php
namespace App\Services;
use App\Models\Language;
use App\Models\LanguageTranslation;
use DB;
class LanguageService
{
/**
* @param $license
* @param $locale
*/
function create_default_language_translations($license, $locale)
{
$translations = [
'extended' => collect([
config("language-translations.extended"),
config("language-translations.regular"),
config("custom-language-translations")
])->collapse(),
'regular' => collect([
config("language-translations.regular"),
config("custom-language-translations")
])->collapse(),
];
$translations = $translations[strtolower($license)]
->map(function ($value, $key) use ($locale) {
return [
'lang' => $locale,
'value' => $value,
'key' => $key,
];
})->toArray();
DB::table('language_translations')
->insert($translations);
}
/**
* Find newly added translations in default language
* translations file and insert it into database
*/
function upgrade_language_translations()
{
// Get all app locales
$locales = Language::all()
->pluck('locale');
// Get default translations
$translations = LanguageTranslation::whereLang('en')
->get();
$default_translations = [
'extended' => collect([
config("language-translations.extended"),
config("language-translations.regular"),
config("custom-language-translations")
])->collapse(),
'regular' => collect([
config("language-translations.regular"),
config("custom-language-translations")
])->collapse(),
];
$license = strtolower(get_setting('license'));
// Find new translations in default translations
$newbies = $default_translations[$license]
->diff(map_language_translations($translations));
// Store new translations for every language
$locales->each(function ($locale) use ($newbies) {
$translations = $newbies
->map(function ($value, $key) use ($locale) {
return [
'lang' => $locale,
'value' => $value,
'key' => $key,
];
})->toArray();
// Store translations into database
DB::table('language_translations')
->insert($translations);
});
}
}