Translator
This commit is contained in:
parent
c600c17f44
commit
833bacc378
@ -27,6 +27,7 @@
|
||||
"@angular/router": "~8.0.0",
|
||||
"@nguniversal/express-engine": "^7.0.2",
|
||||
"@nguniversal/module-map-ngfactory-loader": "^7.0.2",
|
||||
"@ngx-translate/core": "^11.0.1",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"class-transformer": "^0.2.3",
|
||||
@ -38,10 +39,12 @@
|
||||
"helmet": "^3.18.0",
|
||||
"moment": "^2.24.0",
|
||||
"morgan": "^1.9.1",
|
||||
"ngx-cookie-service": "^2.2.0",
|
||||
"pg": "^7.11.0",
|
||||
"pg-native": "^3.0.0",
|
||||
"plotly.js": "^1.48.3",
|
||||
"rxjs": "~6.4.0",
|
||||
"socket.io-client": "^2.2.0",
|
||||
"swagger-jsdoc": "^3.2.9",
|
||||
"tslib": "^1.9.0",
|
||||
"typeorm": "^0.2.18",
|
||||
|
@ -110,6 +110,29 @@ export class BlockchainKernelController {
|
||||
this.TransactionFee,
|
||||
);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /epic_explorer/v1/translator:
|
||||
* get:
|
||||
* tags:
|
||||
* - name: Translator | Translator CONTROLLER
|
||||
* summary: create a translator
|
||||
* description: create a translator
|
||||
* consumes:
|
||||
* - application/json
|
||||
* produces:
|
||||
* - application/json
|
||||
* parameters:
|
||||
* - name: lang
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Transaction fee chart fetched successfully
|
||||
*/
|
||||
this.router.get(
|
||||
`${this.path}/translator`,
|
||||
this.Translator,
|
||||
);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /epic_explorer/v1/blockchain_kernel/transactionheatmap:
|
||||
@ -425,6 +448,32 @@ export class BlockchainKernelController {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private Translator = async (
|
||||
request: Request,
|
||||
response: Response,
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const lang = request.querylang;
|
||||
|
||||
response.status(200).json({
|
||||
status: 200,
|
||||
timestamp: Date.now(),
|
||||
message: 'Transaction fee chart fetched successfully',
|
||||
response: {
|
||||
lang: lang
|
||||
},
|
||||
});
|
||||
|
||||
// res.header("Content-Type",'application/json');
|
||||
// res.sendFile(path.join(__dirname + '/../i18n/'+req.query.lang+'.json'));
|
||||
|
||||
} catch (error) {
|
||||
next(new InternalServerErrorException(error));
|
||||
}
|
||||
};
|
||||
|
||||
private TransactionFee = async (
|
||||
request: Request,
|
||||
response: Response,
|
||||
|
226
server/i18n/en.json
Normal file
226
server/i18n/en.json
Normal file
File diff suppressed because one or more lines are too long
212
server/i18n/es.json
Normal file
212
server/i18n/es.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,6 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { TransServiceService } from './shared/services/trans-service.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -7,4 +9,5 @@ import { Component } from '@angular/core';
|
||||
})
|
||||
export class AppComponent {
|
||||
title = 'explorer2-epic';
|
||||
constructor(private _cookieService: CookieService,public translate: TransServiceService){}
|
||||
}
|
||||
|
@ -3,9 +3,33 @@ import { NgModule } from '@angular/core';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { AppComponent } from './app.component';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
|
||||
import { HttpClientModule, HttpClient } from '@angular/common/http';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
|
||||
import { TransServiceService } from './shared/services/trans-service.service';
|
||||
import { NotFoundComponent } from './view/home/not-found/not-found.component';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
|
||||
export class CustomLoader implements TranslateLoader {
|
||||
apiHost: string;
|
||||
|
||||
constructor(private http: HttpClient ) {
|
||||
}
|
||||
|
||||
public getTranslation(lang: String): Observable<any> {
|
||||
|
||||
return this.http.get(this.apiHost+'/Translation?lang='+lang).pipe(
|
||||
map((res: any) => {
|
||||
console.log("Data got: ");
|
||||
console.log(res);
|
||||
return res;
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent,NotFoundComponent
|
||||
@ -16,8 +40,16 @@ import { NotFoundComponent } from './view/home/not-found/not-found.component';
|
||||
AppRoutingModule,
|
||||
BrowserAnimationsModule,
|
||||
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: CustomLoader,
|
||||
// useFactory: HttpLoaderFactory,
|
||||
deps: [HttpClient]
|
||||
}
|
||||
})
|
||||
],
|
||||
providers: [],
|
||||
providers: [TransServiceService,CookieService],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
42
src/app/shared/services/trans-service.service.ts
Normal file
42
src/app/shared/services/trans-service.service.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TransServiceService{
|
||||
public langLabel: any = {};
|
||||
|
||||
constructor(public translate : TranslateService,private cookie: CookieService) {
|
||||
translate.addLangs(['en', 'es']);
|
||||
translate.setDefaultLang('en');
|
||||
this.langLabel = {en: 'English', es: 'Spanish'};
|
||||
// console.log('this.getCookie() ifconf',this.getCookie() != 'undefined' ? 1: 2);
|
||||
console.log("(this.getCookie() && this.getCookie() != null) ? this.getCookie() : (this.getCurrentLang() && this.getCurrentLang() != null) ? this.getCurrentLang() : 'en'",(this.getCookie() && this.getCookie() != 'undefined') ? this.getCookie() : (this.getCurrentLang() && this.getCurrentLang() != 'undefined') ? this.getCurrentLang() : 'en');
|
||||
translate.use((this.getCookie() && this.getCookie() != 'undefined') ? this.getCookie() : (this.getCurrentLang() && this.getCurrentLang() != 'undefined') ? this.getCurrentLang() : 'en');
|
||||
|
||||
this.setCookie(this.getCurrentLang());
|
||||
}
|
||||
|
||||
public getLanguage(){
|
||||
return this.translate.getLangs();
|
||||
}
|
||||
|
||||
public getCurrentLang(){
|
||||
return this.translate.currentLang;
|
||||
}
|
||||
|
||||
public changeLang(langSelect){
|
||||
this.translate.use(langSelect);
|
||||
this.setCookie(langSelect);
|
||||
}
|
||||
|
||||
public setCookie(lang){
|
||||
this.cookie.set('Lang',lang);
|
||||
}
|
||||
|
||||
public getCookie(){
|
||||
return this.cookie.get('Lang');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user