Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

[WIP] feat(i18n): integrate internationalization and russian language support #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12,523 changes: 12,523 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"@angular/platform-browser": "4.4.4",
"@angular/platform-browser-dynamic": "4.4.4",
"@angular/router": "4.4.4",
"@ngx-translate/core": "8.0.0",
"@ngx-translate/http-loader": "2.0.0",
"@types/hammerjs": "2.0.35",
"core-js": "2.4.1",
"hammerjs": "2.0.8",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<mat-sidenav #sidenav role="navigation">
<mat-nav-list (click)="sidenav.toggle()">
<a *ngFor="let menu of menus" mat-list-item routerLinkActive="active" [routerLinkActiveOptions]="menu.options" [routerLink]="menu.link">
{{menu.title}}
{{menu.title | translate}}
</a>
</mat-nav-list>
</mat-sidenav>
Expand Down
33 changes: 20 additions & 13 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from "@angular/core";
import { Component, OnInit } from '@angular/core';
import { LanguageService } from './services/language.service';

interface Menu {
title: string;
Expand All @@ -7,31 +8,37 @@ interface Menu {
}

@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
export class AppComponent implements OnInit {
menus: Menu[] = [
{
title: "Home",
link: "/",
title: 'MENU.HOME',
link: '/',
options: { exact: true }
},
{
title: "Operators",
link: "/operators",
title: 'MENU.OPERATORS',
link: '/operators',
options: { exact: false }
},
{
title: "Companies",
link: "/companies",
title: 'MENU.COMPANIES',
link: '/companies',
options: { exact: false }
},
{
title: "Team",
link: "/team",
title: 'MENU.TEAM',
link: '/team',
options: { exact: false }
}
];

constructor(private languageService: LanguageService) {}

ngOnInit() {
this.languageService.init(['en', 'ru']);
}
}
39 changes: 30 additions & 9 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { NgModule } from "@angular/core";
import { RouterModule, PreloadAllModules } from "@angular/router";
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { RouterModule, PreloadAllModules } from '@angular/router';

import { AppComponent } from "./app.component";
import { RXJS_DOC_ROUTES } from "./app.routing";
import { ToolbarModule } from "./toolbar/toolbar.module";
import { MatSidenavModule, MatListModule } from "@angular/material";
import { AppComponent } from './app.component';
import { RXJS_DOC_ROUTES } from './app.routing';
import { ToolbarModule } from './toolbar/toolbar.module';
import { MatSidenavModule, MatListModule } from '@angular/material';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import {
TranslateModule,
TranslatePipe,
TranslateService,
TranslateLoader
} from '@ngx-translate/core';
import { LanguageService } from './services/language.service';

export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}

@NgModule({
declarations: [AppComponent],
Expand All @@ -16,11 +29,19 @@ import { MatSidenavModule, MatListModule } from "@angular/material";
ToolbarModule,
MatListModule,
MatSidenavModule,
HttpClientModule,
RouterModule.forRoot(RXJS_DOC_ROUTES, {
preloadingStrategy: PreloadAllModules
}),
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
],
providers: [],
providers: [TranslateService, LanguageService, TranslatePipe],
bootstrap: [AppComponent]
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2> Additional Resources </h2>
<h2> {{ 'OPERATOR.ADDITIONAL_RESOURCES' | translate }} </h2>
<ul class="section-list">
<li>
<a [href]="sourceUrl" target="_blank"> Source Code </a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need i18n on lines 4, 7 and 10

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<h2> Examples </h2>
<h2> {{ 'OPERATOR.EXAMPLES' | translate }} </h2>
<div
class="code-example"
*ngFor="let example of operatorExamples"
appHighlightJs>
<div class="code-block mat-elevation-z2">
<div class="example-header">
<div class="header-title" [innerHTML]="example.name"></div>
<div class="header-title" [innerHTML]="example.name[currentLang]"></div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to write a pipe for this behaviour. To get the element at currentLang will be pretty repetiv.

<button
mat-icon-button
ngxClipboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import { OperatorExample } from '../../../../operator-docs';
})
export class OperatorExamplesComponent {
@Input() operatorExamples: OperatorExample[];
@Input() currentLang = 'en';
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<h2> Parameters </h2>
<h2> {{ 'OPERATOR.PARAMETERS.TITLE' | translate }} </h2>
<table class="parameter-table mat-elevation-z2">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attribute</th>
<th>Description</th>
<th>{{'OPERATOR.PARAMETERS.NAME' | translate}}</th>
<th>{{'OPERATOR.PARAMETERS.TYPE' | translate}}</th>
<th>{{'OPERATOR.PARAMETERS.ATTRIBUTE' | translate}}</th>
<th>{{'OPERATOR.PARAMETERS.DESCRIPTION' | translate}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let parameter of operatorParameters">
<td> {{parameter.name}} </td>
<td> {{parameter.type}} </td>
<td> {{parameter.attribute}} </td>
<td> {{parameter.description}} </td>
<td> {{parameter.description[currentLang]}} </td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, Input } from '@angular/core';
import { OperatorParameters } from '../../../../operator-docs';
import { Component, Input } from "@angular/core";
import { OperatorParameters } from "../../../../operator-docs";

@Component({
selector: 'app-operator-parameters',
templateUrl: './operator-parameters.component.html',
styleUrls: ['./operator-parameters.component.scss']
selector: "app-operator-parameters",
templateUrl: "./operator-parameters.component.html",
styleUrls: ["./operator-parameters.component.scss"]
})
export class OperatorParametersComponent {
@Input() operatorParameters: OperatorParameters[];
@Input() currentLang = "en";
}
10 changes: 7 additions & 3 deletions src/app/operators/components/operator/operator.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class="operator-header">
</app-operator-header>
<section class="main-operator-container mat-typography">
<h3 class="short-description" [innerHTML]="shortDescription"></h3>
<h3 class="short-description" [innerHTML]="shortDescription[currentLang]"></h3>
<app-operator-extras
class="margin-bottom-16"
*ngIf="shortDescriptionExtras"
Expand All @@ -18,13 +18,17 @@ <h3 class="short-description" [innerHTML]="shortDescription"></h3>
[url]="marbleUrl">
</app-marble-diagram>
<app-operator-examples
[operatorExamples]="examples" class="margin-bottom-16">
[operatorExamples]="examples"
[currentLang]="currentLang"
class="margin-bottom-16">
</app-operator-examples>
<app-operator-parameters
[operatorParameters]="parameters">
[operatorParameters]="parameters"
[currentLang]="currentLang">
</app-operator-parameters>
<app-operator-walkthrough
class="margin-bottom-16"
[currentLang]="currentLang"
[operatorWalkthrough]="walkthrough" >
</app-operator-walkthrough>
<app-related-operators
Expand Down
10 changes: 8 additions & 2 deletions src/app/operators/components/operator/operator.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
import {
Component,
Input,
OnInit,
ChangeDetectionStrategy
} from '@angular/core';
import { OperatorDoc } from '../../../../operator-docs/operator.model';

@Component({
Expand All @@ -9,6 +14,7 @@ import { OperatorDoc } from '../../../../operator-docs/operator.model';
})
export class OperatorComponent {
@Input() operator: OperatorDoc;
@Input() currentLang = 'en';

private readonly baseSourceUrl = 'https://github.com/ReactiveX/rxjs/blob/master/src/operators/';
private readonly baseSpecUrl = 'http://reactivex.io/rxjs/test-file/spec-js/operators';
Expand Down Expand Up @@ -38,7 +44,7 @@ export class OperatorComponent {
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n needed for shortDescription on l.39 and shortDescriptionExtras on l.42


get walkthrough() {
return this.operator.walkthrough && this.operator.walkthrough.description;
return this.operator.walkthrough && this.operator.walkthrough.description[this.currentLang];
}

get parameters() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2 class="related-operators"> Related Operators </h2>
<h2 class="related-operators"> {{ 'OPERATOR.RELATED' | translate }} </h2>
<ul class="section-list">
<li *ngFor="let related of relatedOperators">
<a [href]="'/operators#' + related"> {{ related }} </a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2> Walkthrough </h2>
<h2> {{ 'OPERATOR.WALKTHROGH' | translate }} </h2>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: type OPERATOR.WALKTHROUGH

<div class="walkthrough-container" [innerHTML]="operatorWalkthrough">

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import { OperatorExample } from '../../../../operator-docs';
})
export class WalkthroughComponent {
@Input() operatorWalkthrough: string;
@Input() currentLang = 'en';
}
4 changes: 2 additions & 2 deletions src/app/operators/operators.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<mat-sidenav-container
class="operator-container">
<mat-sidenav-container class="operator-container">
<mat-sidenav
[mode]="sidenavMode"
[opened]="!smallScreen"
Expand All @@ -18,6 +17,7 @@ <h3 mat-subheader class="category-subheader">{{ category }}</h3>
</mat-sidenav>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n for category needed on l.10

<app-operator
*ngFor="let operator of operators"
[currentLang]="currentLang"
[operator]="operator">
</app-operator>
</mat-sidenav-container>
Expand Down
Loading