Add Translations for the Language names and the Language Controller will retrieve it's files from a path instead of the classpath (ref #228)

This commit is contained in:
George Kalampokis 2020-01-24 18:03:05 +02:00
parent 63ac6df2ab
commit d119a723f3
7 changed files with 23 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -27,11 +28,11 @@ public class LanguageController {
public ResponseEntity getLanguage(@PathVariable String lang) throws IOException {
String fileName = this.environment.getProperty("language.path") + lang + ".json";
InputStream is = getClass().getClassLoader().getResource(fileName).openStream();
InputStream is = new FileInputStream(fileName);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(is.available());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");

View File

@ -42,7 +42,7 @@
</button>
<mat-menu #languageMenu="matMenu">
<button mat-menu-item *ngFor="let lang of languages" (click)="onLanguageSelected(lang)">
{{ lang.label }}
{{ lang.label | translate }}
</button>
</mat-menu>
</div>

View File

@ -91,7 +91,7 @@
<mat-select placeholder="{{'USER-PROFILE.SETTINGS.LANGUAGE' | translate}}"
[formControl]="this.formGroup.get('language')" required>
<mat-option *ngFor="let language of languages" [value]="language">
{{ language.label }}
{{ language.label | translate }}
</mat-option>
</mat-select>
</mat-form-field>

View File

@ -126,6 +126,11 @@
"XML": "XML",
"JSON": "JSON",
"DOC": "Document"
},
"LANGUAGES": {
"ENGLISH": "English",
"GREEK": "Greek",
"SPANISH": "Spanish"
}
},
"COOKIE": {

View File

@ -126,6 +126,11 @@
"XML": "XML",
"JSON": "JSON",
"DOC": "Document"
},
"LANGUAGES": {
"ENGLISH": "Inglés",
"GREEK": "Griego",
"SPANISH": "Espanol"
}
},
"COOKIE": {

View File

@ -5,6 +5,11 @@
},
"ACTIONS": {
"LOG-IN": "Είσοδος"
},
"LANGUAGES": {
"ENGLISH": "Αγγλικά",
"GREEK": "Ελληνικά",
"SPANISH": "Ισπανικά"
}
},
"USER-PROFILE": {

View File

@ -1,14 +1,14 @@
[
{
"label": "English",
"label": "GENERAL.LANGUAGES.ENGLISH",
"value": "en"
},
{
"label": "Greek",
"label": "GENERAL.LANGUAGES.GREEK",
"value": "gr"
},
{
"label": "Spanish",
"label": "GENERAL.LANGUAGES.SPANISH",
"value": "es"
}
]