12100 Restore database language

This commit is contained in:
Fred Tempez 2023-01-01 11:12:30 +01:00
parent 6e97d5c519
commit cf1e574173
4 changed files with 58 additions and 18 deletions

View File

@ -690,6 +690,14 @@ class common
} }
$db->save; $db->save;
// Créer la base de données des langues
if ($module === 'languages') {
copy('core/module/install/ressource/i18n/languages.json', self::DATA_DIR . 'languages.json');
$this->copyDir('core/module/install/ressource/i18n', self::I18N_DIR);
unlink(self::I18N_DIR . 'languages.json');
}
// Créer le jeu de pages du site de test // Créer le jeu de pages du site de test
if ($module === 'page') { if ($module === 'page') {
$langFolder = $lang . '/content/'; $langFolder = $lang . '/content/';
@ -2141,16 +2149,15 @@ class common
foreach (self::$languages as $key => $value) { foreach (self::$languages as $key => $value) {
if (is_dir(self::DATA_DIR . $key)) { if (is_dir(self::DATA_DIR . $key)) {
$c++; $c++;
$location = helper::baseUrl() . 'translate/content/' . $key ; $location = helper::baseUrl() . 'translate/content/' . $key;
$leftItem .= '<option name="' . $key . '" value="' . $location . '" ' . ($key === self::$i18nContent ? 'selected' : '') . '>' . $value . '</option>'; $leftItem .= '<option name="' . $key . '" value="' . $location . '" ' . ($key === self::$i18nContent ? 'selected' : '') . '>' . $value . '</option>';
} }
} }
if ($c > 1 ) { if ($c > 1) {
$leftItems .= '<li><select id="barSelectLanguage">'; $leftItems .= '<li><select id="barSelectLanguage">';
$leftItems .= $leftItem; $leftItems .= $leftItem;
$leftItems .= '</select></li>'; $leftItems .= '</select></li>';
} }
} }
// Liste des pages // Liste des pages
if ($this->getUser('group') >= self::GROUP_MODERATOR) { if ($this->getUser('group') >= self::GROUP_MODERATOR) {

View File

@ -199,6 +199,7 @@ class install extends common
unlink(self::TEMP_DIR . 'files.tar'); unlink(self::TEMP_DIR . 'files.tar');
helper::deleteCookie('ZWII_UI'); helper::deleteCookie('ZWII_UI');
// Créer le dossier des fontes // Créer le dossier des fontes
if (!is_dir(self::DATA_DIR . 'fonts')) { if (!is_dir(self::DATA_DIR . 'fonts')) {
mkdir(self::DATA_DIR . 'fonts'); mkdir(self::DATA_DIR . 'fonts');
@ -224,8 +225,9 @@ class install extends common
if (is_dir(self::I18N_DIR) === false) { if (is_dir(self::I18N_DIR) === false) {
mkdir(self::I18N_DIR); mkdir(self::I18N_DIR);
} }
$enums = json_decode(file_get_contents('core/module/install/ressource/i18n/languages.json'), true);
$this->setData(['languages', $enums]); // Créer la base de données des langues
copy('core/module/install/ressource/i18n/languages.json', self::DATA_DIR . 'languages.json');
$this->copyDir('core/module/install/ressource/i18n', self::I18N_DIR); $this->copyDir('core/module/install/ressource/i18n', self::I18N_DIR);
unlink(self::I18N_DIR . 'languages.json'); unlink(self::I18N_DIR . 'languages.json');
@ -397,4 +399,33 @@ class install extends common
'view' => 'update' 'view' => 'update'
]); ]);
} }
/**
* Génère un fichier d'énumération des langues de l'UI
*/
private function makeUiLanguages()
{
// Générer une énumération absente
if (empty($enums)) {
if (is_dir(self::I18N_DIR) === false) {
mkdir(self::I18N_DIR);
}
$dir = getcwd();
chdir(self::I18N_DIR);
$files = glob('*.json');
chdir($dir);
$enums = [];
foreach ($files as $file => $value) {
if (basename($value, '.json') === 'languages') {
continue;
}
$enums[basename($value, '.json')] = [
'version' => "?",
'date' => 1672052400
];
}
$this->setData(['languages', $enums]);
}
}
} }

View File

@ -1,14 +1,16 @@
{ {
"fr_FR": { "languages": {
"version": "1.0", "en_EN": {
"date": 1672052400 "version": "1.0",
}, "date": 1672052400
"es": { },
"version": "1.0", "es": {
"date": 1672052400 "version": "1.0",
}, "date": 1672052400
"en_EN": { },
"version": "1.0", "fr_FR": {
"date": 1672052400 "version": "1.0",
"date": 1672052400
}
} }
} }

View File

@ -81,7 +81,7 @@ class translate extends common
$response = file_put_contents(self::I18N_DIR . $lang . '.json', json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); $response = file_put_contents(self::I18N_DIR . $lang . '.json', json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
// Mettre à jour le descripteur // Mettre à jour le descripteur
$enumsStore = json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'languages.json'), true); $enumsStore = json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'languages.json'), true);
$enums = $this->getUiLanguages(); $enums = $this->getData(['languages']);
$enums = array_merge($enums, [ $enums = array_merge($enums, [
$lang => $enumsStore[$lang] $lang => $enumsStore[$lang]
]); ]);
@ -210,7 +210,7 @@ class translate extends common
} }
// Langues installées // Langues installées
$installedUI = $this->getUiLanguages(); $installedUI = $this->getData(['languages']);
// Langues disponibles en ligne // Langues disponibles en ligne
$storeUI = json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'languages.json'), true); $storeUI = json_decode(helper::getUrlContents(common::ZWII_UI_URL . 'languages.json'), true);