Skip to content

Commit

Permalink
support production builds
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika committed Aug 13, 2018
1 parent 12d66f3 commit 8842a16
Show file tree
Hide file tree
Showing 9 changed files with 984 additions and 854 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ Create `en.json` file in the `src/app/assets/i18n` folder of your application.
```

Import `TranslateModule` into you main application module,
configure `TranslateService` to start during application startup.
configure `TranslateService` to load during application startup.

You will also need `HttpClientModule` module dependency.

```ts
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngstack/translate';

// needed to load translation before application starts
export function setupTranslateService(service: TranslateService) {
return () => service.load();
}

@NgModule({
imports: [
BrowserModule,
Expand All @@ -47,6 +53,15 @@ import { TranslateModule } from '@ngstack/translate';
activeLang: 'en'
})
],
providers: [
// needed to load translation before application starts
{
provide: APP_INITIALIZER,
useFactory: setupTranslateService,
deps: [TranslateService],
multi: true
}
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
Expand Down
1,604 changes: 842 additions & 762 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@
"lint": "ng lint",
"e2e": "ng e2e",
"spellcheck": "cspell 'src/**/*.ts' 'e2e/**/*.ts' 'projects/**/*.ts'",
"build:translate": "ng build translate",
"prod:translate": "ng build translate --prod"
"build:lib": "ng build translate",
"build:prod": "ng build translate --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.6",
"@angular/common": "^6.0.6",
"@angular/compiler": "^6.0.6",
"@angular/core": "^6.0.6",
"@angular/forms": "^6.0.6",
"@angular/http": "^6.0.6",
"@angular/material": "^6.3.0",
"@angular/platform-browser": "^6.0.6",
"@angular/platform-browser-dynamic": "^6.0.6",
"@angular/router": "^6.0.6",
"@angular/animations": "^6.1.2",
"@angular/common": "^6.1.2",
"@angular/compiler": "^6.1.2",
"@angular/core": "^6.1.2",
"@angular/forms": "^6.1.2",
"@angular/http": "^6.1.2",
"@angular/material": "^6.4.3",
"@angular/platform-browser": "^6.1.2",
"@angular/platform-browser-dynamic": "^6.1.2",
"@angular/router": "^6.1.2",
"core-js": "^2.5.4",
"monaco-editor": "^0.13.1",
"rxjs": "^6.2.1",
"rxjs": "^6.2.2",
"zone.js": "^0.8.26",
"@angular/cdk": "^6.3.0"
"@angular/cdk": "^6.4.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.3",
"@angular-devkit/build-ng-packagr": "~0.6.5",
"@angular/cli": "^6.0.8",
"@angular/compiler-cli": "^6.0.6",
"@angular/language-service": "^6.0.6",
"@angular-devkit/build-angular": "~0.7.3",
"@angular-devkit/build-ng-packagr": "~0.7.3",
"@angular/cli": "^6.1.3",
"@angular/compiler-cli": "^6.1.2",
"@angular/language-service": "^6.1.2",
"@types/electron": "^1.6.10",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
Expand All @@ -52,12 +52,12 @@
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"ng-packagr": "^3.0.1",
"ng-packagr": "^4.1.0",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tsickle": ">=0.25.5",
"tslib": "^1.7.1",
"tsickle": "^0.32.1",
"tslib": "^1.9.3",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
"typescript": "~2.9.2"
}
}
17 changes: 16 additions & 1 deletion projects/translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ Create `en.json` file in the `src/app/assets/i18n` folder of your application.
```

Import `TranslateModule` into you main application module,
configure `TranslateService` to start during application startup.
configure `TranslateService` to load during application startup.

You will also need `HttpClientModule` module dependency.

```ts
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngstack/translate';

// needed to load translation before application starts
export function setupTranslateService(service: TranslateService) {
return () => service.load();
}

@NgModule({
imports: [
BrowserModule,
Expand All @@ -45,6 +51,15 @@ import { TranslateModule } from '@ngstack/translate';
activeLang: 'en'
})
],
providers: [
// needed to load translation before application starts
{
provide: APP_INITIALIZER,
useFactory: setupTranslateService,
deps: [TranslateService],
multi: true
}
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
Expand Down
2 changes: 1 addition & 1 deletion projects/translate/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ngstack/translate",
"description": "Translation library for Angular and Ionic applications.",
"version": "0.4.1",
"version": "0.5.0",
"license": "MIT",
"author": {
"name": "Denys Vuika",
Expand Down
47 changes: 2 additions & 45 deletions projects/translate/src/lib/translate.module.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,23 @@
import {
NgModule,
ModuleWithProviders,
InjectionToken,
APP_INITIALIZER
} from '@angular/core';
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { TranslateService } from './translate.service';
import { TranslateService, TRANSLATE_SETTINGS } from './translate.service';
import { TranslatePipe } from './translate.pipe';
import { TitleService } from './title.service';
import { TranslateSettings } from './translate.settings';

export const TRANSLATE_SETTINGS = new InjectionToken<TranslateSettings>(
'TRANSLATE_SETTINGS'
);

export function setupTranslateService(
service: TranslateService,
settings: TranslateSettings
): Function {
return () => {
if (settings.debugMode === true) {
service.debugMode = true;
}
if (settings.disableCache === true) {
service.disableCache = true;
}
if (settings.supportedLangs) {
service.supportedLangs = settings.supportedLangs;
}
if (settings.translatePaths) {
service.translatePaths = settings.translatePaths;
}
if (settings.translationRoot) {
service.translationRoot = settings.translationRoot;
}
if (settings.activeLang) {
service.activeLang = settings.activeLang;
}
return service.use(service.activeLang);
};
}

@NgModule({
imports: [CommonModule, HttpClientModule],
declarations: [TranslatePipe],
exports: [TranslatePipe]
})
export class TranslateModule {
static forRoot(settings?: TranslateSettings): ModuleWithProviders {
settings = settings || {};
return {
ngModule: TranslateModule,
providers: [
{ provide: TRANSLATE_SETTINGS, useValue: settings },
TranslateService,
{
provide: APP_INITIALIZER,
useFactory: setupTranslateService,
deps: [TranslateService, TRANSLATE_SETTINGS],
multi: true
},
TitleService
]
};
Expand Down
14 changes: 7 additions & 7 deletions projects/translate/src/lib/translate.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { TestBed, inject } from '@angular/core/testing';

import { TranslateService } from './translate.service';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { Observable, of, throwError } from 'rxjs';
import { of, throwError } from 'rxjs';

describe('TranslateService', () => {
let translate: TranslateService;
Expand All @@ -18,12 +18,12 @@ describe('TranslateService', () => {
http = TestBed.get(HttpClient);
});

it(
'should be created',
inject([TranslateService], (service: TranslateService) => {
it('should be created', inject(
[TranslateService],
(service: TranslateService) => {
expect(service).toBeTruthy();
})
);
}
));

it('should fetch and return translation data on use', async () => {
const translation = { title: 'hello' };
Expand Down
Loading

0 comments on commit 8842a16

Please sign in to comment.