diff --git a/src/app/configuration/controllers/ConfigurationController.php b/src/app/configuration/controllers/ConfigurationController.php index 30ceaf98fb1612dfeef73bf0a9a6814c756d3380..939690da1de43056078986bcc092499cbcd1ab46 100755 --- a/src/app/configuration/controllers/ConfigurationController.php +++ b/src/app/configuration/controllers/ConfigurationController.php @@ -121,12 +121,15 @@ class ConfigurationController // Get Default lang file $defaultLangFilepath = realpath('src/frontend/assets/i18n/'.$args['lang'].'.json'); - $defaultLangFileContent = file_get_contents($defaultLangFilepath); + if (file_exists($defaultLangFilepath)) { + $defaultLangFileContent = file_get_contents($defaultLangFilepath); - $defaultLangFile = json_decode($defaultLangFileContent); - - + $defaultLangFile = json_decode($defaultLangFileContent); + } else { + $defaultLangFile = json_decode('{"lang":{}}'); + } + $loadedXml = CoreConfigModel::getConfig(); // Get custom lang file @@ -139,13 +142,38 @@ class ConfigurationController $customLangFile = json_decode($customLangFileContent); foreach ($customLangFile->lang as $key => $value) { - if ($defaultLangFile->lang->$key !== null) { - $defaultLangFile->lang->$key = $customLangFile->lang->$key; - } + $defaultLangFile->lang->$key = $customLangFile->lang->$key; } } } return $response->withJson($defaultLangFile); } + + public function getAvailableLang() + { + + // Get Default lang list + $langFilenameList = array_diff(scandir(realpath('src/frontend/assets/i18n/')), array('..', '.')); + + $loadedXml = CoreConfigModel::getConfig(); + + // Get custom lang list + if (!empty((string)$loadedXml->config->customLangPathDirectory)) { + $customLangPathDirectory = rtrim((string)$loadedXml->config->customLangPathDirectory, '/'); + + $customLangFilenameList = array_diff(scandir(realpath($customLangPathDirectory)), array('..', '.')); + + $mergedLangFilenameList = array_unique(array_merge($langFilenameList, $customLangFilenameList), SORT_REGULAR); + } else { + $mergedLangFilenameList = $langFilenameList; + } + + $langFilenameList = []; + foreach ($mergedLangFilenameList as $key => $value) { + $langFilenameList[] = str_replace('.json', '', $value); + } + + return ['lang' => $langFilenameList]; + } } diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 7ee24e998639748a5a1b6f53e121f025b0c5e237..735313fb56180b33f482380794ef476d6182fbd0 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -14,6 +14,8 @@ namespace User\controllers; + +use Configuration\controllers\ConfigurationController; use Email\controllers\EmailController; use History\controllers\HistoryController; use Respect\Validation\Validator; @@ -136,7 +138,7 @@ class UserController } $check = Validator::arrayType()->notEmpty()->validate($body['preferences']); - $check = $check && Validator::stringType()->notEmpty()->validate($body['preferences']['lang']) && in_array($body['preferences']['lang'], ['fr', 'en']); + //$check = $check && Validator::stringType()->notEmpty()->validate($body['preferences']['lang']) && in_array($body['preferences']['lang'], ['fr', 'en']); $check = $check && Validator::stringType()->notEmpty()->validate($body['preferences']['writingMode']); $check = $check && Validator::intType()->notEmpty()->validate($body['preferences']['writingSize']); $check = $check && Validator::stringType()->notEmpty()->validate($body['preferences']['writingColor']); @@ -363,6 +365,9 @@ class UserController $user = UserModel::getById(['select' => ['id', 'login', 'email', 'firstname', 'lastname', 'picture', 'preferences'], 'id' => $args['id']]); + $langs = ConfigurationController::getAvailableLang(); + $user['availableLang'] = $langs['lang']; + if (empty($user['picture'])) { $user['picture'] = base64_encode(file_get_contents('src/frontend/assets/user_picture.png')); $user['picture'] = 'data:image/png;base64,' . $user['picture']; diff --git a/src/frontend/app/profile/profile.component.html b/src/frontend/app/profile/profile.component.html index 5452e1dd06e49d044dee3611d6c88eb1956a2b4c..9b80592b33c96f3dc187a1531a5a19a79c16a0f8 100644 --- a/src/frontend/app/profile/profile.component.html +++ b/src/frontend/app/profile/profile.component.html @@ -106,8 +106,7 @@ <div class="form-2-col"> <mat-form-field> <mat-select #langSelect name="langUser" [(ngModel)]="this.profileInfo.preferences.lang"> - <mat-option value="fr">Français</mat-option> - <mat-option value="en">English</mat-option> + <mat-option *ngFor="let lang of this.profileInfo.availableLang" [value]="lang">{{'lang.'+lang | translate }}</mat-option> </mat-select> </mat-form-field> </div> diff --git a/src/frontend/assets/i18n/en.json b/src/frontend/assets/i18n/en.json index 7e41cb983bdf8ff94576d27095702f00db75a98d..2c9f0a6e6252dc619cb5c9f20ca331e2210ee70f 100755 --- a/src/frontend/assets/i18n/en.json +++ b/src/frontend/assets/i18n/en.json @@ -29,11 +29,13 @@ "doubletapSignatureToAddDocument": "Double-tap on a signature to add it to your document", "email": "Email", "emittedBy": "Emitted by", + "en": "English", "enterLogin": "Enter your username", "erase": "Erase", "exitAnnotation": "Exit the annotation", "firstname": "Firstname", "forgotPassword": "Forgot password", + "fr": "Français", "free": "Free", "freeModeInfo": "You will only be able to annotate documents with the Apple <b>stylus</b>.<br />This has the advantage of being able to put your hand on the tablet without disturbing the writing.", "fromRange": "From", diff --git a/src/frontend/assets/i18n/fr.json b/src/frontend/assets/i18n/fr.json index bb9ef21c32a8af6e414e47e01913b178a8294d87..f8818386c2505e4a794f43fe6a96ccf74189e7e8 100755 --- a/src/frontend/assets/i18n/fr.json +++ b/src/frontend/assets/i18n/fr.json @@ -29,11 +29,13 @@ "doubletapSignatureToAddDocument": "Double-tapez sur une signature pour l'ajouter à votre document", "email": "Courriel", "emittedBy": "Émis par", + "en": "English", "enterLogin": "Saisissez votre identifiant", "erase": "Effacer", "exitAnnotation": "Quitter l'annotation", "firstname": "Prénom", "forgotPassword": "Mot de passe oublié", + "fr": "Français", "free": "Libre", "freeModeInfo": "Vous ne pourrez annoter les documents qu'avec le <b>stylet Apple</b>.<br />Cela a pour avantage de pouvoir poser la main sur la tablette sans perturber l'écriture.", "fromRange": "De",