Skip to content

Commit

Permalink
feat(core): support for Angular 6 and RxJS 6
Browse files Browse the repository at this point in the history
Fixes #816

BREAKING CHANGE: The library is now compatible with Angular 6+ and RxJS 6+. If you need to use Angular 5, please stay on version 9.1.1. If you need to use RxJS 5, update to 5.6 and use the rxjs-compat library (see [the RxJS update guide](https://docs.google.com/document/d/12nlLt71VLKb-z3YaSGzUfx6mJbc34nsMXtByPUN35cg/preview#))
  • Loading branch information
ocombe committed Mar 28, 2018
1 parent 375e5f4 commit 152208e
Show file tree
Hide file tree
Showing 25 changed files with 2,669 additions and 2,613 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ coverage
bundles
build
dist
dist.tgz

#################
## JetBrains
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Get the complete changelog here: https://github.com/ngx-translate/core/releases

**This is the documentation for the 6+ version, if you're using 5.x or less, refer to [this document](https://github.com/ngx-translate/core/blob/fb02ca5920aae405048ebab50e09db67d5bf12a2/README.md).**

**If you're still using Angular v5, please use ngx-translate 9.x, version 10 and above are only compatible with Angular v6. If you need to use RxJS 5, update to 5.6 and use the rxjs-compat library (see [the RxJS update guide](https://docs.google.com/document/d/12nlLt71VLKb-z3YaSGzUfx6mJbc34nsMXtByPUN35cg/preview#)).**

* [Installation](#installation)
* [Usage](#usage)
* [API](#api)
Expand Down
4 changes: 2 additions & 2 deletions config/spec-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require('zone.js/dist/proxy'); // since zone.js 0.6.15
require('zone.js/dist/jasmine-patch'); // put here since zone.js 0.6.14

// RxJS
require('rxjs/Rx');
require('rxjs');

var testing = require('@angular/core/testing');
var browser = require('@angular/platform-browser-dynamic/testing');
Expand Down Expand Up @@ -55,4 +55,4 @@ function requireAll(requireContext) {
}

// requires and returns all modules that match
var modules = requireAll(testContext);
var modules = requireAll(testContext);
4 changes: 0 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export interface TranslateModuleConfig {
export class TranslateModule {
/**
* Use this method in your root module to provide the TranslateService
* @param {TranslateModuleConfig} config
* @returns {ModuleWithProviders}
*/
static forRoot(config: TranslateModuleConfig = {}): ModuleWithProviders {
return {
Expand All @@ -62,8 +60,6 @@ export class TranslateModule {

/**
* Use this method in your other (non root) modules to import the directive/pipe
* @param {TranslateModuleConfig} config
* @returns {ModuleWithProviders}
*/
static forChild(config: TranslateModuleConfig = {}): ModuleWithProviders {
return {
Expand Down
4 changes: 2 additions & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
},
"homepage": "https://github.com/ngx-translate/core",
"peerDependencies": {
"@angular/core": ">=5.0.0",
"rxjs": ">=5.5.2"
"@angular/core": ">=6.0.0-rc.0",
"rxjs": ">=6.0.0-beta.1"
},
"devDependencies": {
"semantic-release": "8.2.3"
Expand Down
59 changes: 26 additions & 33 deletions lib/src/missing-translation-handler.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
import {TranslateService} from "./translate.service";
import {Injectable} from "@angular/core";
import {TranslateService} from "./translate.service";

export interface MissingTranslationHandlerParams {
/**
* the key that's missing in translation files
*
* @type {string}
*/
key: string;
/**
* the key that's missing in translation files
*/
key: string;

/**
* an instance of the service that was unable to translate the key.
*
* @type {TranslateService}
*/
translateService: TranslateService;
/**
* an instance of the service that was unable to translate the key.
*/
translateService: TranslateService;

/**
* interpolation params that were passed along for translating the given key.
*
* @type {Object}
*/
interpolateParams?: Object;
/**
* interpolation params that were passed along for translating the given key.
*/
interpolateParams?: Object;
}

export abstract class MissingTranslationHandler {
/**
* A function that handles missing translations.
*
* @abstract
* @param {MissingTranslationHandlerParams} params context for resolving a missing translation
* @returns {any} a value or an observable
* If it returns a value, then this value is used.
* If it return an observable, the value returned by this observable will be used (except if the method was "instant").
* If it doesn't return then the key will be used as a value
*/
abstract handle(params: MissingTranslationHandlerParams): any;
/**
* A function that handles missing translations.
*
* @param params context for resolving a missing translation
* @returns a value or an observable
* If it returns a value, then this value is used.
* If it return an observable, the value returned by this observable will be used (except if the method was "instant").
* If it doesn't return then the key will be used as a value
*/
abstract handle(params: MissingTranslationHandlerParams): any;
}

/**
* This handler is just a placeholder that does nothing, in case you don't need a missing translation handler at all
*/
@Injectable()
export class FakeMissingTranslationHandler implements MissingTranslationHandler {
handle(params: MissingTranslationHandlerParams): string {
return params.key;
}
handle(params: MissingTranslationHandlerParams): string {
return params.key;
}
}
17 changes: 9 additions & 8 deletions lib/src/translate.compiler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import {Injectable} from "@angular/core";

export abstract class TranslateCompiler {
abstract compile(value: string, lang: string): string | Function;
abstract compileTranslations(translations: any, lang: string): any;
abstract compile(value: string, lang: string): string | Function;

abstract compileTranslations(translations: any, lang: string): any;
}

/**
* This compiler is just a placeholder that does nothing, in case you don't need a compiler at all
*/
@Injectable()
export class TranslateFakeCompiler extends TranslateCompiler {
compile(value: string, lang: string): string | Function {
return value;
}
compile(value: string, lang: string): string | Function {
return value;
}

compileTranslations(translations: any, lang: string): any {
return translations;
}
compileTranslations(translations: any, lang: string): any {
return translations;
}
}
Loading

0 comments on commit 152208e

Please sign in to comment.