Skip to content

Commit

Permalink
feat: update to angular 2 RC2
Browse files Browse the repository at this point in the history
fixes #148
  • Loading branch information
ocombe committed Jun 16, 2016
1 parent c95eb41 commit c0df9b1
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 48 deletions.
24 changes: 13 additions & 11 deletions bundles/ng2-translate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.registerDynamic("src/translate.pipe", ["angular2/core", "./translate.service", "angular2/src/facade/lang"], true, function($__require, exports, module) {
System.registerDynamic("src/translate.pipe", ["@angular/core", "./translate.service", "@angular/core/src/facade/lang"], true, function($__require, exports, module) {
"use strict";
;
var define,
Expand All @@ -20,9 +20,9 @@ System.registerDynamic("src/translate.pipe", ["angular2/core", "./translate.serv
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var core_1 = $__require('angular2/core');
var core_1 = $__require('@angular/core');
var translate_service_1 = $__require('./translate.service');
var lang_1 = $__require('angular2/src/facade/lang');
var lang_1 = $__require('@angular/core/src/facade/lang');
var TranslatePipe = (function() {
function TranslatePipe(translate, _ref) {
this.translate = translate;
Expand Down Expand Up @@ -77,6 +77,7 @@ System.registerDynamic("src/translate.pipe", ["angular2/core", "./translate.serv
var _this = this;
this.translate.get(key, interpolateParams).subscribe(function(res) {
_this.value = res ? res : key;
_this.lastKey = key;
_this._ref.markForCheck();
});
};
Expand Down Expand Up @@ -109,6 +110,7 @@ System.registerDynamic("src/translate.pipe", ["angular2/core", "./translate.serv
this.updateValue(query, interpolateParams);
this._dispose();
this.onLangChange = this.translate.onLangChange.subscribe(function(event) {
_this.lastKey = null;
_this.updateValue(query, interpolateParams);
});
return this.value;
Expand All @@ -132,7 +134,7 @@ System.registerDynamic("src/translate.pipe", ["angular2/core", "./translate.serv
return module.exports;
});

System.registerDynamic("src/translate.service", ["angular2/core", "angular2/http", "rxjs/Observable", "rxjs/add/observable/of", "rxjs/add/operator/share", "rxjs/add/operator/map", "rxjs/add/operator/merge", "rxjs/add/operator/toArray", "./translate.parser"], true, function($__require, exports, module) {
System.registerDynamic("src/translate.service", ["@angular/core", "@angular/http", "rxjs/Observable", "rxjs/add/observable/of", "rxjs/add/operator/share", "rxjs/add/operator/map", "rxjs/add/operator/merge", "rxjs/add/operator/toArray", "./translate.parser"], true, function($__require, exports, module) {
"use strict";
;
var define,
Expand All @@ -159,8 +161,8 @@ System.registerDynamic("src/translate.service", ["angular2/core", "angular2/http
decorator(target, key, paramIndex);
};
};
var core_1 = $__require('angular2/core');
var http_1 = $__require('angular2/http');
var core_1 = $__require('@angular/core');
var http_1 = $__require('@angular/http');
var Observable_1 = $__require('rxjs/Observable');
$__require('rxjs/add/observable/of');
$__require('rxjs/add/operator/share');
Expand Down Expand Up @@ -413,7 +415,7 @@ System.registerDynamic("src/translate.parser", [], true, function($__require, ex
return module.exports;
});

System.registerDynamic("ng2-translate", ["angular2/core", "angular2/http", "./src/translate.pipe", "./src/translate.service", "./src/translate.parser"], true, function($__require, exports, module) {
System.registerDynamic("ng2-translate", ["@angular/http", "./src/translate.pipe", "./src/translate.service", "./src/translate.parser"], true, function($__require, exports, module) {
"use strict";
;
var define,
Expand All @@ -424,19 +426,19 @@ System.registerDynamic("ng2-translate", ["angular2/core", "angular2/http", "./sr
if (!exports.hasOwnProperty(p))
exports[p] = m[p];
}
var core_1 = $__require('angular2/core');
var http_1 = $__require('angular2/http');
var http_1 = $__require('@angular/http');
var translate_pipe_1 = $__require('./src/translate.pipe');
var translate_service_1 = $__require('./src/translate.service');
__export($__require('./src/translate.pipe'));
__export($__require('./src/translate.service'));
__export($__require('./src/translate.parser'));
exports.TRANSLATE_PROVIDERS = [core_1.provide(translate_service_1.TranslateLoader, {
exports.TRANSLATE_PROVIDERS = [{
provide: translate_service_1.TranslateLoader,
useFactory: function(http) {
return new translate_service_1.TranslateStaticLoader(http);
},
deps: [http_1.Http]
}), translate_service_1.TranslateService];
}, translate_service_1.TranslateService];
Object.defineProperty(exports, "__esModule", {value: true});
exports.default = {
pipes: [translate_pipe_1.TranslatePipe],
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function(config) {
typescriptPreprocessor: {
options: require('./tsconfig.json').compilerOptions,
typings: [
"typings/main.d.ts"
"typings/index.d.ts"
]
},

Expand Down
10 changes: 5 additions & 5 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ var config = {
},
map: {
typescript: './node_modules/typescript/lib/typescript.js',
'@angular': path.resolve('node_modules/@angular'),
rxjs: path.resolve('node_modules/rxjs')
'@angular': './node_modules/@angular',
rxjs: './node_modules/rxjs'
},
paths: {
'*': '*.js'
},
meta: {
'node_modules/@angular/*': { build: false },
'node_modules/rxjs/*': { build: false }
},
'./node_modules/@angular/*': { build: false },
'./node_modules/rxjs/*': { build: false }
}
};

builder.config(config);
Expand Down
5 changes: 3 additions & 2 deletions ng2-translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export * from './src/translate.service';
export * from './src/translate.parser';

export const TRANSLATE_PROVIDERS: any = [
provide(TranslateLoader, {
{
provide: TranslateLoader,
useFactory: (http: Http) => new TranslateStaticLoader(http),
deps: [Http]
}),
},
TranslateService
];

Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
"typings": "./ng2-translate.d.ts",
"homepage": "https://github.com/ocombe/ng2-translate",
"peerDependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1"
"@angular/common": "2.0.0-rc.2",
"@angular/compiler": "2.0.0-rc.2",
"@angular/core": "2.0.0-rc.2",
"@angular/http": "2.0.0-rc.2"
},
"devDependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/common": "2.0.0-rc.2",
"@angular/compiler": "2.0.0-rc.2",
"@angular/core": "2.0.0-rc.2",
"@angular/http": "2.0.0-rc.2",
"@angular/platform-browser": "2.0.0-rc.2",
"commitizen": "~2.5.0",
"cz-conventional-changelog": "~1.1.4",
"es6-promise": "^3.0.2",
Expand All @@ -50,14 +50,14 @@
"karma-firefox-launcher": "~0.1.7",
"karma-jasmine": "~0.3.8",
"karma-typescript-preprocessor": "0.0.21",
"reflect-metadata": "0.1.2",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"semantic-release": "~4.3.5",
"systemjs": "~0.19.24",
"systemjs-builder": "^0.15.13",
"tsd": "^0.6.5",
"typescript": "^1.8.9",
"typings": "^0.6.8",
"typings": "1.2.0",
"zone.js": "^0.6.10"
},
"czConfig": {
Expand Down
2 changes: 2 additions & 0 deletions src/translate.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class TranslatePipe implements PipeTransform, OnDestroy {
updateValue(key: string, interpolateParams?: Object): void {
this.translate.get(key, interpolateParams).subscribe((res: string) => {
this.value = res ? res : key;
this.lastKey = key;
this._ref.markForCheck();
});
}
Expand Down Expand Up @@ -113,6 +114,7 @@ export class TranslatePipe implements PipeTransform, OnDestroy {

// subscribe to onLangChange event, in case the language changes
this.onLangChange = this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
this.lastKey = null; // we want to make sure it doesn't return the same value until it's been updated
this.updateValue(query, interpolateParams);
});

Expand Down
17 changes: 11 additions & 6 deletions tests/translate.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function main() {
injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
// Provide a mocked (fake) backend for Http
provide(XHRBackend, {useClass: MockBackend}),
{provide: XHRBackend, useClass: MockBackend},
TRANSLATE_PROVIDERS
]);
backend = injector.get(XHRBackend);
Expand Down Expand Up @@ -127,9 +127,10 @@ export function main() {
expect(translatePipe.transform('TEST')).toEqual("This is a test");

// this will be resolved at the next lang change
translate.onLangChange.subscribe((res: LangChangeEvent) => {
let subscription = translate.onLangChange.subscribe((res: LangChangeEvent) => {
expect(res.lang).toEqual('fr');
expect(translatePipe.transform('TEST')).toEqual("C'est un test");
subscription.unsubscribe();
done();
});

Expand All @@ -142,10 +143,14 @@ export function main() {
expect(translatePipe.transform('TEST')).toEqual("This is a test");

// this will be resolved at the next lang change
translate.onLangChange.subscribe((res: LangChangeEvent) => {
expect(res.lang).toEqual('fr');
expect(translatePipe.transform('TEST')).toEqual("C'est un test");
done();
let subscription = translate.onLangChange.subscribe((res: LangChangeEvent) => {
// let it update the translations
setTimeout(() => {
expect(res.lang).toEqual('fr');
expect(translatePipe.transform('TEST')).toEqual("C'est un test");
subscription.unsubscribe();
done();
});
});

translate.use('fr');
Expand Down
12 changes: 6 additions & 6 deletions tests/translate.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function main() {
injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
// Provide a mocked (fake) backend for Http
provide(XHRBackend, {useClass: MockBackend}),
{provide: XHRBackend, useClass: MockBackend},
TRANSLATE_PROVIDERS
]);
backend = injector.get(XHRBackend);
Expand Down Expand Up @@ -264,9 +264,9 @@ export function main() {
injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
// Provide a mocked (fake) backend for Http
provide(XHRBackend, {useClass: MockBackend}),
{provide:XHRBackend, useClass: MockBackend},
TRANSLATE_PROVIDERS,
provide(MissingTranslationHandler, {useClass: handlerClass})
{provide: MissingTranslationHandler, useClass: handlerClass}
]);
backend = injector.get(XHRBackend);
translate = injector.get(TranslateService);
Expand Down Expand Up @@ -422,7 +422,7 @@ export function main() {
injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
// Provide a mocked (fake) backend for Http
provide(XHRBackend, {useClass: MockBackend}),
{provide: XHRBackend, useClass: MockBackend},
TRANSLATE_PROVIDERS
]);
prepare(injector);
Expand Down Expand Up @@ -452,9 +452,9 @@ export function main() {
injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
// Provide a mocked (fake) backend for Http
provide(XHRBackend, {useClass: MockBackend}),
{provide: XHRBackend, useClass: MockBackend},
TRANSLATE_PROVIDERS,
provide(TranslateLoader, {useClass: CustomLoader})
{provide: TranslateLoader, useClass: CustomLoader}
]);
prepare(injector);

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"moduleResolution": "node"
},
"files": [
"typings/main.d.ts",
"typings/index.d.ts",
"ng2-translate.ts",
"./src/translate.pipe.ts",
"./src/translate.service.ts",
Expand Down
10 changes: 5 additions & 5 deletions typings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"ambientDevDependencies": {
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4"
"globalDevDependencies": {
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#36a1be34dbe202c665b3ddafd50824f78c09eea3"
},
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2",
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#aee0039a2d6686ec78352125010ebb38a7a7d743"
"globalDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#9807d9b701f58be068cb07833d2b24235351d052",
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#6abf99dda133ff859e16e3520b0b00b6b1239341"
}
}

0 comments on commit c0df9b1

Please sign in to comment.