mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-30 20:19:49 +09:00
feat: Dynamically add all languages to db
Add unit test to find missing translations
This commit is contained in:
committed by
Attila Jozsef Kerekes
parent
99193a578e
commit
edb51e56f1
@@ -19,7 +19,8 @@
|
|||||||
"laravelcollective/html": "^6.0",
|
"laravelcollective/html": "^6.0",
|
||||||
"nunomaduro/collision": "^5.0",
|
"nunomaduro/collision": "^5.0",
|
||||||
"symfony/yaml": "^5.4",
|
"symfony/yaml": "^5.4",
|
||||||
"ext-json": "*"
|
"ext-json": "*",
|
||||||
|
"ext-intl": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"filp/whoops": "~2.0",
|
"filp/whoops": "~2.0",
|
||||||
|
|||||||
@@ -7,9 +7,40 @@ use App\SettingGroup;
|
|||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Locale;
|
||||||
|
|
||||||
class SettingsSeeder extends Seeder
|
class SettingsSeeder extends Seeder
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
public static function getSupportedLanguageMap()
|
||||||
|
{
|
||||||
|
$languageDirectories = array_filter(glob(resource_path().'/lang/*'), 'is_dir');
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($languageDirectories as $languageDirectory) {
|
||||||
|
$language = self::getLanguageFromDirectory($languageDirectory);
|
||||||
|
$resultNative = mb_convert_case(Locale::getDisplayLanguage($language.'-', $language), MB_CASE_TITLE, 'UTF-8');
|
||||||
|
$resultEn = ucfirst(Locale::getDisplayLanguage($language, 'en'));
|
||||||
|
$result[$language] = "$resultNative ($resultEn)";
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_encode($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $languageDirectory
|
||||||
|
* @return false|string[]
|
||||||
|
*/
|
||||||
|
public static function getLanguageFromDirectory($languageDirectory)
|
||||||
|
{
|
||||||
|
$directories = explode('/', $languageDirectory);
|
||||||
|
|
||||||
|
return $directories[array_key_last($directories)];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the database seeds.
|
* Run the database seeds.
|
||||||
*
|
*
|
||||||
@@ -124,20 +155,8 @@ class SettingsSeeder extends Seeder
|
|||||||
$setting->save();
|
$setting->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$language_options = json_encode([
|
$language_options = SettingsSeeder::getSupportedLanguageMap();
|
||||||
'de' => 'Deutsch (German)',
|
|
||||||
'en' => 'English',
|
|
||||||
'cn' => '简体中文 (Simplified Chinese)',
|
|
||||||
'fi' => 'Suomi (Finnish)',
|
|
||||||
'fr' => 'Français (French)',
|
|
||||||
'el' => 'Ελληνικά (Greek)',
|
|
||||||
'it' => 'Italiano (Italian)',
|
|
||||||
'no' => 'Norsk (Norwegian)',
|
|
||||||
'pl' => 'Polski (Polish)',
|
|
||||||
'sv' => 'Svenska (Swedish)',
|
|
||||||
'es' => 'Español (Spanish)',
|
|
||||||
'tr' => 'Türkçe (Turkish)',
|
|
||||||
]);
|
|
||||||
if ($languages = Setting::find(5)) {
|
if ($languages = Setting::find(5)) {
|
||||||
$languages->options = $language_options;
|
$languages->options = $language_options;
|
||||||
$languages->save();
|
$languages->save();
|
||||||
|
|||||||
19
readme.md
19
readme.md
@@ -84,15 +84,26 @@ When you are finished, create a pull request.
|
|||||||
Currently added languages are
|
Currently added languages are
|
||||||
|
|
||||||
- English
|
- English
|
||||||
|
- Breton
|
||||||
|
- Danish
|
||||||
- German
|
- German
|
||||||
|
- Greek
|
||||||
|
- Spanish
|
||||||
- Finnish
|
- Finnish
|
||||||
- French
|
- French
|
||||||
- Swedish
|
- Hungarian
|
||||||
- Spanish
|
- Italian
|
||||||
- Turkish
|
- Korean
|
||||||
|
- Lombard
|
||||||
|
- Dutch
|
||||||
|
- Norwegian
|
||||||
|
- Polish
|
||||||
|
- Portuguese
|
||||||
- Russian
|
- Russian
|
||||||
|
- Slovenian
|
||||||
|
- Swedish
|
||||||
|
- Turkish
|
||||||
- Chinese
|
- Chinese
|
||||||
- Português
|
|
||||||
|
|
||||||
## Web Server Configuration
|
## Web Server Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ return [
|
|||||||
|
|
||||||
'settings.window_target.current' => 'In quella scheda chi',
|
'settings.window_target.current' => 'In quella scheda chi',
|
||||||
|
|
||||||
'settings.window_target.one' => 'In l'istessa scheda',
|
'settings.window_target.one' => 'In l\'istessa scheda',
|
||||||
|
|
||||||
'settings.window_target.new' => 'In d'una scheda noeuva',
|
'settings.window_target.new' => 'In d\'una scheda noeuva',
|
||||||
|
|
||||||
'settings.homepage_search' => 'Ricerca in l'home page',
|
'settings.homepage_search' => 'Ricerca in l\'home page',
|
||||||
|
|
||||||
'settings.search_provider' => 'Provider de default',
|
'settings.search_provider' => 'Provider de default',
|
||||||
|
|
||||||
@@ -90,17 +90,17 @@ return [
|
|||||||
|
|
||||||
'buttons.add' => 'Sgionta',
|
'buttons.add' => 'Sgionta',
|
||||||
|
|
||||||
'buttons.upload' => 'Carega 'n icona',
|
'buttons.upload' => 'Carega \'n icona',
|
||||||
|
|
||||||
'buttons.downloadapps' => 'Descarega la lista di app',
|
'buttons.downloadapps' => 'Descarega la lista di app',
|
||||||
|
|
||||||
'dash.pin_item' => 'Taca su l'oget',
|
'dash.pin_item' => 'Taca su l\'oget',
|
||||||
|
|
||||||
'dash.no_apps' => 'Ghe n'è minga de app tacade su, :link1 o :link2',
|
'dash.no_apps' => 'Ghe n\'è minga de app tacade su, :link1 o :link2',
|
||||||
|
|
||||||
'dash.link1' => 'Met 'n aplicazzion chi',
|
'dash.link1' => 'Met \'n aplicazzion chi',
|
||||||
|
|
||||||
'dash.link2' => 'Taca su 'n oget',
|
'dash.link2' => 'Taca su \'n oget',
|
||||||
|
|
||||||
'dash.pinned_items' => 'Oget tacad su',
|
'dash.pinned_items' => 'Oget tacad su',
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ return [
|
|||||||
|
|
||||||
'apps.add_application' => 'Sgionta aplicazzion',
|
'apps.add_application' => 'Sgionta aplicazzion',
|
||||||
|
|
||||||
'apps.application_name' => 'Nom de l'aplicazzion',
|
'apps.application_name' => 'Nom de l\'aplicazzion',
|
||||||
|
|
||||||
'apps.colour' => 'Color',
|
'apps.colour' => 'Color',
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ return [
|
|||||||
|
|
||||||
'apps.tags' => 'Tag',
|
'apps.tags' => 'Tag',
|
||||||
|
|
||||||
'apps.override' => 'Se divers de l'url principal',
|
'apps.override' => 'Se divers de l\'url principal',
|
||||||
|
|
||||||
'apps.preview' => 'Varda prima',
|
'apps.preview' => 'Varda prima',
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ return [
|
|||||||
|
|
||||||
'apps.description' => 'Descrizzion',
|
'apps.description' => 'Descrizzion',
|
||||||
|
|
||||||
'apps.only_admin_account' => 'Domà se te gh'heet un cunt admin!',
|
'apps.only_admin_account' => 'Domà se te gh\'heet un cunt admin!',
|
||||||
|
|
||||||
'apps.autologin_url' => 'Auto login url',
|
'apps.autologin_url' => 'Auto login url',
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ return [
|
|||||||
|
|
||||||
'user.secure_front' => 'Fà entra del front - El fonziona domà cont una password.',
|
'user.secure_front' => 'Fà entra del front - El fonziona domà cont una password.',
|
||||||
|
|
||||||
'user.autologin' => 'Permet el login de 'n ciar URL. Tucc quèi che ghe l'hann poden entrà.',
|
'user.autologin' => 'Permet el login de \'n ciar URL. Tucc quèi che ghe l\'hann poden entrà.',
|
||||||
|
|
||||||
'url' => 'URL',
|
'url' => 'URL',
|
||||||
|
|
||||||
@@ -202,9 +202,9 @@ return [
|
|||||||
|
|
||||||
'alert.success.tag_restored' => 'Tag ripescad',
|
'alert.success.tag_restored' => 'Tag ripescad',
|
||||||
|
|
||||||
'alert.success.setting_updated' => 'L'impostazzion l'è stada mudada',
|
'alert.success.setting_updated' => 'L\'impostazzion l\'è stada mudada',
|
||||||
|
|
||||||
'alert.error.not_exist' => 'Quella impostazzion chi la gh'è no.',
|
'alert.error.not_exist' => 'Quella impostazzion chi la gh\'è no.',
|
||||||
|
|
||||||
'alert.success.user_created' => 'Utent fad su',
|
'alert.success.user_created' => 'Utent fad su',
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testBasicTest()
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
23
tests/Unit/database/seeders/SettingsSeederTest.php
Normal file
23
tests/Unit/database/seeders/SettingsSeederTest.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\database\seeders;
|
||||||
|
|
||||||
|
use Database\Seeders\SettingsSeeder;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SettingsSeederTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* All language keys are defined in all languages based on the en language file.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReturnsAJSONMapWithSameAmountOfItemsAsLanguageDirectoriesPresent()
|
||||||
|
{
|
||||||
|
$languageDirectories = array_filter(glob(resource_path().'/lang/*'), 'is_dir');
|
||||||
|
|
||||||
|
$languageMap = json_decode(SettingsSeeder::getSupportedLanguageMap(), true);
|
||||||
|
|
||||||
|
$this->assertTrue(count($languageMap) === count($languageDirectories));
|
||||||
|
}
|
||||||
|
}
|
||||||
48
tests/Unit/lang/LangTest.php
Normal file
48
tests/Unit/lang/LangTest.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\lang;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class LangTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* All language keys are defined in all languages based on the en language file.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAllLanguageKeysAreDefined()
|
||||||
|
{
|
||||||
|
$this->markTestSkipped('2022-11-14 Lot of keys missing. Enable this test to see them all.');
|
||||||
|
$languageDirectories = array_filter(glob(resource_path().'/lang/*'), 'is_dir');
|
||||||
|
|
||||||
|
$enLanguageDirectory = array_values(array_filter($languageDirectories, function($v) {
|
||||||
|
return substr($v, -2) === 'en';
|
||||||
|
}))[0];
|
||||||
|
$notENLanguageDirectories = array_filter($languageDirectories, function ($v) {
|
||||||
|
return substr($v, -2) !== 'en';
|
||||||
|
});
|
||||||
|
|
||||||
|
$enLanguageKeys = require_once($enLanguageDirectory.'/app.php');
|
||||||
|
$missingKeys = [];
|
||||||
|
|
||||||
|
foreach ($notENLanguageDirectories as $langDirectory) {
|
||||||
|
$testingLangKeys = require_once($langDirectory . '/app.php');
|
||||||
|
|
||||||
|
foreach ($enLanguageKeys as $langKey => $langValue) {
|
||||||
|
if (!array_key_exists($langKey, $testingLangKeys)) {
|
||||||
|
if(!isset($missingKeys[$langDirectory])) {
|
||||||
|
$missingKeys[$langDirectory] = [];
|
||||||
|
}
|
||||||
|
$missingKeys[$langDirectory][] = $langKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($missingKeys) > 0) {
|
||||||
|
print_r(json_encode($missingKeys));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEmpty($missingKeys);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user