1010*/
1111import { Component , Inject , Optional } from '@angular/core' ;
1212import { BaseLogger } from '../../../../../../virtual-desktop/src/app/shared/logger' ;
13- // import { LanguageLocaleService } from '../../../../../../virtual-desktop/src/app/i18n/language-locale.service';
13+ import { LanguageLocaleService } from '../../../../../../virtual-desktop/src/app/i18n/language-locale.service' ;
1414import { Angular2InjectionTokens , Angular2PluginWindowActions } from 'pluginlib/inject-resources' ;
15- // import { L10nTranslationService } from 'angular-l10n';
15+ import { L10nTranslationService } from 'angular-l10n' ;
1616
1717@Component ( {
1818 selector : 'language-component' ,
@@ -39,31 +39,39 @@ export class LanguageComponent {
3939 public LanguageChanges : string ;
4040 public Select : string ;
4141
42+ private languageMap : { [ key : string ] : string } = {
43+ en : 'English' ,
44+ fr : 'French' ,
45+ ru : 'Russian' ,
46+ zh : 'Chinese' ,
47+ ja : 'Japanese' ,
48+ de : 'German'
49+ } ;
50+
4251 constructor (
43- // private languageLocaleService: LanguageLocaleService,
44- // private translation: L10nTranslationService,
52+ private languageLocaleService : LanguageLocaleService ,
53+ private translation : L10nTranslationService ,
4554 @Optional ( ) @Inject ( Angular2InjectionTokens . WINDOW_ACTIONS ) private windowActions : Angular2PluginWindowActions ,
4655
4756 ) {
4857 this . isRestartWindowVisible = false ;
4958 this . isVeilVisible = false ;
5059 this . updateLanguageSelection ( ) ;
5160 this . updateLanguageStrings ( ) ;
52- if ( this . windowActions ) { this . windowActions . setTitle ( this . Languages ) ; }
61+ if ( this . windowActions ) { this . windowActions . setTitle ( this . Languages ) ; }
5362 }
5463
5564 applyLanguage ( ) : void {
56- this . logger . debug ( "hello" )
57- // this.languageLocaleService.setLanguage(this.idLanguage).subscribe(
58- // arg => {
59- // this.logger.debug("ZWED5323I",arg); //this.logger.debug(`setLanguage, arg=`,arg);
60- // this.isRestartWindowVisible = true;
61- // this.isVeilVisible = true;
62- // },
63- // err => {
64- // this.logger.warn("ZWED5192W",err); //this.logger.warn("setLanguage error=",err);
65- // }
66- // )
65+ this . languageLocaleService . setLanguage ( this . idLanguage ) . subscribe (
66+ arg => {
67+ this . logger . debug ( 'ZWED5323I' , arg ) ; // this.logger.debug(`setLanguage, arg=`,arg);
68+ this . isRestartWindowVisible = true ;
69+ this . isVeilVisible = true ;
70+ } ,
71+ err => {
72+ this . logger . warn ( 'ZWED5192W' , err ) ; // this.logger.warn("setLanguage error=",err);
73+ }
74+ )
6775 }
6876
6977 closeRestartWindow ( ) : void {
@@ -75,93 +83,30 @@ export class LanguageComponent {
7583 window . location . reload ( ) ;
7684 }
7785
78- //TODO: Ideally, when selecting a language in the panel we would adjust the language strings to the chosen
79- //language in real-time (contrary to restarting the desktop) but this doesn't work yet as this.translation
80- //only loads translations for the currently loaded language (that of which data is coming from a cookie)
81-
82- selectEnglish ( ) : void {
83- this . selectedLanguage = "English" ;
84- this . selectedLanguage = "English" ;
85- this . idLanguage = "en" ;
86- }
87-
88- selectFrench ( ) : void {
89- this . selectedLanguage = "French" ;
90- this . selectedLanguage = "English" ;
91- this . idLanguage = "fr" ;
92- }
86+ // TODO: Ideally, when selecting a language in the panel we would adjust the language strings to the chosen
87+ // language in real-time (contrary to restarting the desktop) but this doesn't work yet as this.translation
88+ // only loads translations for the currently loaded language (that of which data is coming from a cookie)
9389
94- selectRussian ( ) : void {
95- this . selectedLanguage = "Russian" ;
96- this . selectedLanguage = "English" ;
97- this . idLanguage = "ru" ;
98- }
99-
100- selectChinese ( ) : void {
101- this . selectedLanguage = "Chinese" ;
102- this . selectedLanguage = "English" ;
103- this . idLanguage = "zh" ;
104- }
105-
106- selectJapanese ( ) : void {
107- this . selectedLanguage = "Japanese" ;
108- this . selectedLanguage = "English" ;
109- this . idLanguage = "ja" ;
110- }
111-
112- selectGerman ( ) : void {
113- this . selectedLanguage = "German" ;
114- this . selectedLanguage = "English" ;
115- this . idLanguage = "de" ;
90+ selectLanguage ( langCode : string ) : void {
91+ this . selectedLanguage = this . languageMap [ langCode ] || 'English' ;
92+ this . idLanguage = langCode in this . languageMap ? langCode : 'en' ;
11693 }
11794
11895 updateLanguageSelection ( ) : void {
119- this . idLanguage = "en" ;
120-
121- switch ( this . idLanguage ) {
122- case "en" : {
123- this . selectEnglish ( ) ;
124- break ;
125- }
126- case "fr" : {
127- this . selectFrench ( ) ;
128- break ;
129- }
130- case "ja" : {
131- this . selectJapanese ( ) ;
132- break ;
133- }
134- case "ru" : {
135- this . selectRussian ( ) ;
136- break ;
137- }
138- case "zh" : {
139- this . selectChinese ( ) ;
140- break ;
141- }
142- case "de" : {
143- this . selectGerman ( ) ;
144- break ;
145- }
146- default : {
147- this . selectEnglish ( ) ;
148- break ;
149- }
150- }
96+ this . selectLanguage ( this . idLanguage ) ;
15197 }
15298
15399 updateLanguageStrings ( ) : void {
154- // this.selectedLanguage = this.translation?.translate(this.selectedLanguage, null, this.idLanguage);
155- // this.Languages = this.translation?.translate('Languages', null, this.idLanguage);
156- // this.Apply = this.translation?.translate('Apply', null, this.idLanguage);
157- // this.LanguageChanges = this.translation?.translate('Language Changes', null, this.idLanguage);
158- // this.LanguageSelected = this.translation?.translate('Language Selected', null, this.idLanguage);
159- // this.RestartDescr1 = this.translation?.translate('For language changes to take effect, Zowe must be restarted.', null, this.idLanguage);
160- // this.RestartDescr2 = this.translation?.translate('Would you like to restart the desktop?', null, this.idLanguage);
161- // this.RestartLater = this.translation?.translate('Restart Later', null, this.idLanguage);
162- // this.RestartNow = this.translation?.translate('Restart Now', null, this.idLanguage);
163- // this.Select = this.translation?.translate('Select', null, this.idLanguage);
164-
100+ this . selectedLanguage = this . translation ?. translate ( this . selectedLanguage , null , this . idLanguage ) ;
101+ this . Languages = this . translation ?. translate ( 'Languages' , null , this . idLanguage ) ;
102+ this . Apply = this . translation ?. translate ( 'Apply' , null , this . idLanguage ) ;
103+ this . LanguageChanges = this . translation ?. translate ( 'Language Changes' , null , this . idLanguage ) ;
104+ this . LanguageSelected = this . translation ?. translate ( 'Language Selected' , null , this . idLanguage ) ;
105+ this . RestartDescr1 = this . translation ?. translate ( 'For language changes to take effect, Zowe must be restarted.' , null , this . idLanguage ) ;
106+ this . RestartDescr2 = this . translation ?. translate ( 'Would you like to restart the desktop?' , null , this . idLanguage ) ;
107+ this . RestartLater = this . translation ?. translate ( 'Restart Later' , null , this . idLanguage ) ;
108+ this . RestartNow = this . translation ?. translate ( 'Restart Now' , null , this . idLanguage ) ;
109+ this . Select = this . translation ?. translate ( 'Select' , null , this . idLanguage ) ;
165110 }
166111
167112}
0 commit comments