Skip to content

Commit

Permalink
ng9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
deerua committed Mar 12, 2020
1 parent ab8525d commit 202a36a
Show file tree
Hide file tree
Showing 10 changed files with 693 additions and 218 deletions.
22 changes: 6 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- '8'
- "stable"
before_install:
- export CHROME_BIN=chromium-browser
- npm i -g npm@^3
before_script:
- npm prune
branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
services:
- xvfb
script:
- yarn install
- npm run test
13 changes: 1 addition & 12 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,11 @@ module.exports = function (config) {
autoWatch: false,

browsers: [
'ChromeHeadless'
'Chrome'
],

customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},

singleRun: true
};

if (process.env.TRAVIS) {
configuration.browsers = ['Chrome_travis_ci'];
}

config.set(configuration);
};
3 changes: 1 addition & 2 deletions config/spec-bundle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

Error.stackTraceLimit = Infinity;

require('core-js/es6');
require('core-js/es7/reflect');
require('core-js');

// Typescript emit helpers polyfill
require('ts-helpers');
Expand Down
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,31 @@
"typings": "index.d.ts",
"homepage": "https://github.com/Greentube/localize-router",
"peerDependencies": {
"@angular/common": ">=6.0.0",
"@angular/core": ">=6.0.0",
"@angular/router": ">=6.0.0",
"@ngx-translate/core": ">=10.0.0",
"rxjs": "^6.0.0"
"@angular/common": ">=9.0.5",
"@angular/core": ">=9.0.5",
"@angular/router": ">=9.0.5",
"@ngx-translate/core": ">=12.0.0",
"rxjs": "^6.5.3"
},
"devDependencies": {
"@angular/animations": "~6.0.6",
"@angular/common": "~6.0.6",
"@angular/compiler": "~6.0.6",
"@angular/compiler-cli": "~6.0.6",
"@angular/core": "~6.0.6",
"@angular/http": "~6.0.6",
"@angular/platform-browser": "~6.0.6",
"@angular/platform-browser-dynamic": "~6.0.6",
"@angular/platform-server": "~6.0.6",
"@angular/router": "~6.0.6",
"@ngx-translate/core": "10.0.2",
"@angular/animations": "~9.0.5",
"@angular/common": "~9.0.5",
"@angular/compiler": "~9.0.5",
"@angular/compiler-cli": "~9.0.5",
"@angular/core": "~9.0.5",
"@angular/platform-browser": "~9.0.5",
"@angular/platform-browser-dynamic": "~9.0.5",
"@angular/platform-server": "~9.0.5",
"@angular/router": "~9.0.5",
"@ngx-translate/core": "^12.0.0",
"@types/es6-promise": "0.0.32",
"@types/hammerjs": "2.0.34",
"@types/jasmine": "2.5.47",
"@types/node": "7.0.22",
"@types/node": "~13.9.0",
"awesome-typescript-loader": "3.1.3",
"codelyzer": "~4.5.0",
"codelyzer": "~5.2.1",
"concurrently": "3.1.0",
"core-js": "2.4.1",
"core-js": "~3.6.4",
"istanbul-instrumenter-loader": "~2.0.0",
"jasmine-core": "2.6.2",
"karma": "1.7.0",
Expand All @@ -70,16 +69,17 @@
"karma-webpack": "2.0.3",
"loader-utils": "1.1.0",
"reflect-metadata": "0.1.10",
"rxjs": "6.2.1",
"rxjs": "6.5.3",
"source-map-loader": "0.2.1",
"ts-helpers": "1.1.2",
"tslib": "~1.10.0",
"tslint": "5.8.0",
"tslint-eslint-rules": "^4.1.1",
"tslint-loader": "3.5.3",
"typescript": "2.7.2",
"typescript": "3.7.5",
"webpack": "2.6.0",
"webpack-node-externals": "^1.5.4",
"yarn": "^1.12.1",
"zone.js": "~0.8.26"
"zone.js": "~0.10.2"
}
}
4 changes: 3 additions & 1 deletion src/localize-router.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, InjectionToken, Provider } from '@angular/core';
import { Inject, InjectionToken, Provider, Injectable } from '@angular/core';
import { Routes } from '@angular/router';
import { LocalizeRouterModule } from './localize-router.module';

Expand Down Expand Up @@ -75,6 +75,8 @@ export interface LocalizeRouterConfig {

const LOCALIZE_CACHE_NAME = 'LOCALIZE_DEFAULT_LANGUAGE';

// @dynamic
@Injectable()
export class LocalizeRouterSettings implements LocalizeRouterConfig {
/**
* Settings for localize router
Expand Down
8 changes: 5 additions & 3 deletions src/localize-router.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { TranslateModule } from '@ngx-translate/core';
import { CommonModule } from '@angular/common';
import {
ALWAYS_SET_PREFIX,
CACHE_MECHANISM, CACHE_NAME, DEFAULT_LANG_FUNCTION, LOCALIZE_ROUTER_FORROOT_GUARD, LocalizeRouterConfig, LocalizeRouterSettings,
CACHE_MECHANISM, CACHE_NAME, DEFAULT_LANG_FUNCTION,
LOCALIZE_ROUTER_FORROOT_GUARD,
LocalizeRouterConfig, LocalizeRouterSettings,
RAW_ROUTES,
USE_CACHED_LANG
} from './localize-router.config';
Expand Down Expand Up @@ -70,7 +72,7 @@ export function getAppInitializer(p: ParserInitializer, parser: LocalizeParser,
})
export class LocalizeRouterModule {

static forRoot(routes: Routes, config: LocalizeRouterConfig = {}): ModuleWithProviders {
static forRoot(routes: Routes, config: LocalizeRouterConfig = {}): ModuleWithProviders<LocalizeRouterModule> {
return {
ngModule: LocalizeRouterModule,
providers: [
Expand Down Expand Up @@ -104,7 +106,7 @@ export class LocalizeRouterModule {
};
}

static forChild(routes: Routes): ModuleWithProviders {
static forChild(routes: Routes): ModuleWithProviders<LocalizeRouterModule> {
return {
ngModule: LocalizeRouterModule,
providers: [
Expand Down
24 changes: 13 additions & 11 deletions src/localize-router.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export abstract class LocalizeParser {
* @param location
* @param settings
*/
constructor(@Inject(TranslateService) private translate: TranslateService,
@Inject(Location) private location: Location,
@Inject(LocalizeRouterSettings) private settings: LocalizeRouterSettings) {
}
constructor(
@Inject(TranslateService) private translate: TranslateService,
@Inject(Location) private location: Location,
@Inject(LocalizeRouterSettings) private settings: LocalizeRouterSettings
) { }

/**
* Load routes and fetch necessary data
Expand Down Expand Up @@ -260,14 +261,15 @@ export abstract class LocalizeParser {
*/
private get _cachedLang(): string {
if (!this.settings.useCachedLang) {
return;
return '';
}
if (this.settings.cacheMechanism === CacheMechanism.LocalStorage) {
return this._cacheWithLocalStorage();
}
if (this.settings.cacheMechanism === CacheMechanism.Cookie) {
return this._cacheWithCookies();
}
return '';
}

/**
Expand Down Expand Up @@ -295,17 +297,17 @@ export abstract class LocalizeParser {
*/
private _cacheWithLocalStorage(value?: string): string {
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
return;
return '';
}
try {
if (value) {
window.localStorage.setItem(this.settings.cacheName, value);
return;
return '';
}
return this._returnIfInLocales(window.localStorage.getItem(this.settings.cacheName));
} catch (e) {
// weird Safari issue in private mode, where LocalStorage is defined but throws error on access
return;
return '';
}
}

Expand All @@ -316,21 +318,21 @@ export abstract class LocalizeParser {
*/
private _cacheWithCookies(value?: string): string {
if (typeof document === 'undefined' || typeof document.cookie === 'undefined') {
return;
return '';
}
try {
const name = encodeURIComponent(this.settings.cacheName);
if (value) {
const d: Date = new Date();
d.setTime(d.getTime() + COOKIE_EXPIRY * 86400000); // * days
document.cookie = `${name}=${encodeURIComponent(value)};expires=${d.toUTCString()}`;
return;
return '';
}
const regexp = new RegExp('(?:^' + name + '|;\\s*' + name + ')=(.*?)(?:;|$)', 'g');
const result = regexp.exec(document.cookie);
return decodeURIComponent(result[1]);
} catch (e) {
return; // should not happen but better safe than sorry
return ''; // should not happen but better safe than sorry
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/localize-router.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import {
Router,
NavigationStart,
Expand All @@ -16,6 +16,7 @@ import { LocalizeRouterSettings } from './localize-router.config';
* Localization service
* modifyRoutes
*/
@Injectable()
export class LocalizeRouterService {
routerEvents: Subject<string>;

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
],
"angularCompilerOptions": {
"strictMetadataEmit": true,
"skipTemplateCodegen": true
"skipTemplateCodegen": true,
"enableIvy": false
}
}
Loading

0 comments on commit 202a36a

Please sign in to comment.