Translator

This commit is contained in:
vijikannan 2019-07-19 15:16:52 +05:30
parent c600c17f44
commit 833bacc378
8 changed files with 572 additions and 5 deletions

View File

@ -27,6 +27,7 @@
"@angular/router": "~8.0.0", "@angular/router": "~8.0.0",
"@nguniversal/express-engine": "^7.0.2", "@nguniversal/express-engine": "^7.0.2",
"@nguniversal/module-map-ngfactory-loader": "^7.0.2", "@nguniversal/module-map-ngfactory-loader": "^7.0.2",
"@ngx-translate/core": "^11.0.1",
"babel-preset-es2015": "^6.24.1", "babel-preset-es2015": "^6.24.1",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"class-transformer": "^0.2.3", "class-transformer": "^0.2.3",
@ -38,10 +39,12 @@
"helmet": "^3.18.0", "helmet": "^3.18.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"morgan": "^1.9.1", "morgan": "^1.9.1",
"ngx-cookie-service": "^2.2.0",
"pg": "^7.11.0", "pg": "^7.11.0",
"pg-native": "^3.0.0", "pg-native": "^3.0.0",
"plotly.js": "^1.48.3", "plotly.js": "^1.48.3",
"rxjs": "~6.4.0", "rxjs": "~6.4.0",
"socket.io-client": "^2.2.0",
"swagger-jsdoc": "^3.2.9", "swagger-jsdoc": "^3.2.9",
"tslib": "^1.9.0", "tslib": "^1.9.0",
"typeorm": "^0.2.18", "typeorm": "^0.2.18",

View File

@ -110,6 +110,29 @@ export class BlockchainKernelController {
this.TransactionFee, 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 * @swagger
* /epic_explorer/v1/blockchain_kernel/transactionheatmap: * /epic_explorer/v1/blockchain_kernel/transactionheatmap:
@ -424,6 +447,32 @@ export class BlockchainKernelController {
next(new InternalServerErrorException(error)); next(new InternalServerErrorException(error));
} }
}; };
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 ( private TransactionFee = async (
request: Request, request: Request,

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

File diff suppressed because one or more lines are too long

View File

@ -21,4 +21,4 @@ export const routes: Routes = [
], ],
exports: [RouterModule], exports: [RouterModule],
}) })
export class AppRoutingModule {} export class AppRoutingModule {}

View File

@ -1,4 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { TransServiceService } from './shared/services/trans-service.service';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -7,4 +9,5 @@ import { Component } from '@angular/core';
}) })
export class AppComponent { export class AppComponent {
title = 'explorer2-epic'; title = 'explorer2-epic';
constructor(private _cookieService: CookieService,public translate: TransServiceService){}
} }

View File

@ -3,9 +3,33 @@ import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component'; 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 { 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({ @NgModule({
declarations: [ declarations: [
AppComponent,NotFoundComponent AppComponent,NotFoundComponent
@ -15,9 +39,17 @@ import { NotFoundComponent } from './view/home/not-found/not-found.component';
HttpClientModule, HttpClientModule,
AppRoutingModule, AppRoutingModule,
BrowserAnimationsModule, BrowserAnimationsModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: CustomLoader,
// useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
], ],
providers: [], providers: [TransServiceService,CookieService],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule { } export class AppModule { }

View 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');
}
}