UI language management: Version 1.02 - access to language data from server enabled

This commit is contained in:
Rene V. Vergara A. 2023-02-17 09:48:26 -05:00
parent d93c95558f
commit d14f47cc8b
2 changed files with 22 additions and 6 deletions

View file

@ -1,4 +1,5 @@
export interface LanguageData { export interface LanguageData {
_id: string;
language: string; language: string;
component: string; component: string;
data?: any; data?: any;

View file

@ -3,13 +3,22 @@ import { LanguageData } from './language.model';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { ConfigData } from './configdata'; import { ConfigData } from './configdata';
var Buffer = require('buffer/').Buffer;
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class LanguageService { export class LanguageService {
//
private baseURL = 'http://localhost:8080/getlang'; // URL for test using REST API to local MariaDB database
// private baseURL = 'http://localhost:8080/zgointl';
//
// URL for test using REST API to local MongoDB database
// private baseURL = 'http://localhost:5000/zgointl';
//
// URL for access MongoDB database from remote server
private baseURL = ConfigData.Be_URL + 'api/getlang';
public zgoLanguage: string = ''; public zgoLanguage: string = '';
@ -20,7 +29,12 @@ export class LanguageService {
// //
// Get default language from localStorage // Get default language from localStorage
// //
var def_zgoLanguage = localStorage.getItem('zgo_language'); const def_zgoLanguage = localStorage.getItem('zgo_language');
//
// Set authorizacion paramaters
//
const Auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
const reqHeaders = new HttpHeaders().set('Authorization', Auth);
if ( def_zgoLanguage == null ) { if ( def_zgoLanguage == null ) {
this.zgoLanguage = 'en-US'; this.zgoLanguage = 'en-US';
@ -29,10 +43,11 @@ export class LanguageService {
this.zgoLanguage = def_zgoLanguage; this.zgoLanguage = def_zgoLanguage;
} }
// //
// Get View's text data from language database // Get component's text data from language database
// //
return this.http.get<LanguageData>(this.baseURL + return this.http.get<LanguageData>(this.baseURL +
'/?lang_id=' + this.zgoLanguage + '/?lang=' + this.zgoLanguage +
'&viewname=' + viewName); '&component=' + viewName,
{ headers : reqHeaders });
} }
} }