Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ngx-translate standalone API in demo project #166

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -22,13 +22,13 @@ Based on and extension of [ngx-translate](https://github.com/ngx-translate/core)
| 6 - 7 | 1.0.2 | 1.0.1 | legacy |
| 7 | 1.7.3 | 1.1.0 | legacy |
| 8 | 2.2.3 | 1.1.0 | legacy |
| 8 - 12 | 3.1.9 | 1.1.2 | active |
| 13 | 4.0.1 | 2.0.0 | active |
| 14 | 5.1.1 | 2.0.0 | active | need rxjs 7 or higher |
| 15 | 6.0.0 | 2.0.0 | active | minimum angular 15.0.3 |
| 15.1 | 6.1.0 | 2.0.0 | active | minimum angular 15.1.0 |
| 16 | 7.0.0 | 2.0.0 | active | minimum angular 16 |
| 17 | 7.1.0 | 2.0.0 | active | optional standalone API |
| 8 - 12 | 3.1.9 | 1.1.2 | legacy |
| 13 | 4.0.1 | 2.0.0 | legacy |
| 14 | 5.1.1 | 2.0.0 | legacy | need rxjs 7 or higher |
| 15 | 6.0.0 | 2.0.0 | legacy | minimum angular 15.0.3 |
| 15.1 | 6.1.0 | 2.0.0 | legacy | minimum angular 15.1.0 |
| 16 | 7.0.0 | 2.0.0 | legacy | minimum angular 16 |
| 17 | 7.1.0 | 2.0.0 | legacy | optional standalone API |
| 18 | 7.2.1 | 2.0.0 | active | |

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add smth like this?

| 19 | 8.0.0 | 2.0.0 | active | ngx-translate v16 |

Demo project can be found under sub folder `src`.
@@ -103,7 +103,7 @@ Parameters for this function are exactly the same as for `LocalizeRouterModule.f
```ts
providers: [
provideHttpClient(withFetch()),
importProvidersFrom(TranslateModule.forRoot()),
provideTranslateService(),
provideRouter(
routes,
withDisabledInitialNavigation(),
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
"server": "src/main.server.ts",
"prerender": true,
"ssr": {
"entry": "server.ts"
"entry": "src/server.ts"
}
},
"configurations": {
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -15,32 +15,32 @@
},
"private": true,
"dependencies": {
"@angular/animations": "18.0.1",
"@angular/common": "18.0.1",
"@angular/compiler": "18.0.1",
"@angular/core": "18.0.1",
"@angular/platform-browser": "18.0.1",
"@angular/platform-browser-dynamic": "18.0.1",
"@angular/platform-server": "18.0.1",
"@angular/router": "18.0.1",
"@angular/ssr": "^18.0.2",
"@ngx-translate/core": "15.0.0",
"@ngx-translate/http-loader": "8.0.0",
"@angular/animations": "^19.0.0",
"@angular/common": "^19.0.0",
"@angular/compiler": "^19.0.0",
"@angular/core": "^19.0.0",
"@angular/platform-browser": "^19.0.0",
"@angular/platform-browser-dynamic": "^19.0.0",
"@angular/platform-server": "^19.0.0",
"@angular/router": "^19.0.0",
"@angular/ssr": "^19.0.0",
"@ngx-translate/core": "^16.0.0",
"@ngx-translate/http-loader": "^16.0.0",
"@scullyio/scully": "0.0.102",
"express": "^4.18.2",
"rxjs": "7.8.0",
"express": "^4.21.1",
"rxjs": "^7.8.1",
"tslib": "2.3.1",
"zone.js": "~0.14.6"
"zone.js": "~0.15.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "18.0.2",
"@angular/cli": "18.0.2",
"@angular/compiler-cli": "18.0.1",
"@angular/language-service": "18.0.1",
"@angular-devkit/build-angular": "^19.0.0",
"@angular/cli": "^19.0.0",
"@angular/compiler-cli": "^19.0.0",
"@angular/language-service": "^19.0.0",
"@types/express": "^4.17.17",
"@types/jasmine": "~3.10.2",
"@types/jasminewd2": "~2.0.8",
"@types/node": "18.11.9",
"@types/node": "^22.9.1",
"browser-sync": "^3.0.0",
"codelyzer": "6.0.2",
"jasmine-core": "~3.10.1",
@@ -50,9 +50,9 @@
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.1",
"karma-jasmine-html-reporter": "1.7.0",
"ng-packagr": "18.0.0",
"ng-packagr": "^19.0.0",
"protractor": "~7.0.0",
"ts-node": "~10.4.0",
"typescript": "5.4.5"
"typescript": "5.6.3"
}
}
}
2 changes: 1 addition & 1 deletion projects/ngx-translate-router-scully-plugin/package.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
},
"peerDependencies": {
"@angular/common": ">=16.2.12",
"@ngx-translate/core": ">=16.2.12",
"@ngx-translate/core": ">=16.0.0",
"@gilsdav/ngx-translate-router": ">=7.1.0",
"@scullyio/scully": ">=0.0.102"
},
2 changes: 1 addition & 1 deletion projects/ngx-translate-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gilsdav/ngx-translate-router",
"version": "7.2.1",
"version": "7.2.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s update the version to 8.0.0, as the library now utilizes ngx-translate v16 and Angular v19.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It’s backwards compatible, no breaking changes, just following semantic versioning

"homepage": "https://github.com/gilsdav/ngx-translate-router#readme",
"license" : "MIT",
"author": {
13 changes: 9 additions & 4 deletions projects/ngx-translate-router/src/lib/localize-router.module.ts
Original file line number Diff line number Diff line change
@@ -8,8 +8,7 @@ import {
RouterModule, Routes, RouteReuseStrategy, Router, RouterConfigurationFeature
} from '@angular/router';
import { LocalizeRouterPipe } from './localize-router.pipe';
import { TranslateModule } from '@ngx-translate/core';
import { CommonModule, Location } from '@angular/common';
import { CommonModule } from '@angular/common';
import {
ALWAYS_SET_PREFIX,
CACHE_MECHANISM, CACHE_NAME, DEFAULT_LANG_FUNCTION, LOCALIZE_ROUTER_FORROOT_GUARD,
@@ -120,8 +119,14 @@ function createLocalizeRouterProviders(routes: Routes, config: LocalizeRouterCon
}

@NgModule({
imports: [CommonModule, RouterModule, TranslateModule, LocalizeRouterPipe],
exports: [LocalizeRouterPipe]
imports: [
CommonModule,
RouterModule,
LocalizeRouterPipe
],
exports: [
LocalizeRouterPipe
]
})
export class LocalizeRouterModule {

Original file line number Diff line number Diff line change
@@ -28,9 +28,11 @@ export abstract class LocalizeParser {
/**
* Loader constructor
*/
constructor(@Inject(TranslateService) private translate: TranslateService,
constructor(
@Inject(TranslateService) private translate: TranslateService,
@Inject(Location) private location: Location,
@Inject(LocalizeRouterSettings) private settings: LocalizeRouterSettings) {
@Inject(LocalizeRouterSettings) private settings: LocalizeRouterSettings
) {
}

/**
9 changes: 5 additions & 4 deletions projects/ngx-translate-router/src/lib/localized-router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Router, ROUTES, Route, DefaultExport, Routes, PRIMARY_OUTLET, ɵEmptyOutletComponent as EmptyOutletComponent } from '@angular/router';
import { Injector, Compiler, NgModuleFactory, PLATFORM_ID, inject, Injectable, EnvironmentInjector } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { from, of, isObservable, Observable, ConnectableObservable, Subject } from 'rxjs';
import { mergeMap, map, refCount, finalize } from 'rxjs/operators';
import { from, of, isObservable, Observable, Subject } from 'rxjs';
import { mergeMap, map, finalize, share } from 'rxjs/operators';
import { isPromise } from './util';
import { LocalizeParser } from './localize-router.parser';

@@ -41,8 +41,9 @@ export class LocalizedRouter extends Router {
this.childrenLoaders.delete(route);
}),
);
const loader = new ConnectableObservable(loadRunner, () => new Subject<any>())
.pipe(refCount());
const loader = loadRunner.pipe(
share({ connector: () => new Subject() })
);
this.childrenLoaders.set(route, loader);
return loader;
}
21 changes: 10 additions & 11 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Component, OnInit } from '@angular/core';
import { LocalizeRouterService, LocalizeRouterPipe } from '@gilsdav/ngx-translate-router';
import { TranslateModule } from '@ngx-translate/core';
import { RouterLink, RouterOutlet } from '@angular/router';
import { TranslatePipe } from '@ngx-translate/core';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
standalone: true,
imports: [
RouterLink,
RouterOutlet,
LocalizeRouterPipe,
TranslateModule
]
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
imports: [
RouterLink,
RouterOutlet,
TranslatePipe,
LocalizeRouterPipe
]
})
export class AppComponent implements OnInit {
title = 'app';
7 changes: 4 additions & 3 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { importProvidersFrom } from '@angular/core';

import { createTranslateLoader } from './app.utils';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateLoader, provideTranslateService } from '@ngx-translate/core';
import { AppRoutingModule } from './app-routing.module';
import { withInterceptorsFromDi, provideHttpClient, HttpClient } from '@angular/common/http';
import { TranslateTitleStrategy } from './translate-title-strategy';
@@ -12,13 +12,14 @@ import {ApplicationConfig} from '@angular/core';

export const appConfig: ApplicationConfig = {
providers: [
importProvidersFrom(BrowserModule, AppRoutingModule, TranslateModule.forRoot({
importProvidersFrom(BrowserModule, AppRoutingModule),
provideTranslateService({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
})),
}),
provideClientHydration(),
{ provide: TitleStrategy, useClass: TranslateTitleStrategy }
// {
5 changes: 2 additions & 3 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { TranslatePipe } from '@ngx-translate/core';
import { LocalizeRouterPipe } from '@gilsdav/ngx-translate-router';
import { RouterLink, RouterOutlet } from '@angular/router';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
standalone: true,
imports: [RouterLink, RouterOutlet, LocalizeRouterPipe, TranslateModule]
imports: [RouterLink, RouterOutlet, LocalizeRouterPipe, TranslatePipe]
})
export class HomeComponent implements OnInit, OnDestroy {

1 change: 0 additions & 1 deletion src/app/matcher/matcher-detail/matcher-detail.component.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import { NgFor } from '@angular/common';
selector: 'app-matcher-detail',
templateUrl: './matcher-detail.component.html',
styleUrls: ['./matcher-detail.component.css'],
standalone: true,
imports: [RouterLinkActive, RouterLink, NgFor, LocalizeRouterPipe]
})
export class MatcherDetailComponent implements OnInit, OnDestroy {
2 changes: 0 additions & 2 deletions src/app/matcher/matcher-detail/matcher-detail.module.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import { CommonModule } from '@angular/common';
import { RouterModule, Routes, UrlSegment, UrlMatchResult } from '@angular/router';

import { LocalizeRouterModule, LocalizedMatcherUrlSegment } from '@gilsdav/ngx-translate-router';
import { TranslateModule } from '@ngx-translate/core';

import { MatcherDetailComponent } from './matcher-detail.component';

@@ -50,7 +49,6 @@ const routes: Routes = [
CommonModule,
RouterModule.forChild(routes),
LocalizeRouterModule.forChild(routes),
TranslateModule.forChild(),
MatcherDetailComponent
],
exports: [
1 change: 0 additions & 1 deletion src/app/matcher/matcher.component.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import { NgFor } from '@angular/common';
selector: 'app-matcher',
templateUrl: './matcher.component.html',
styleUrls: ['./matcher.component.css'],
standalone: true,
imports: [RouterLinkActive, RouterLink, NgFor, LocalizeRouterPipe]
})
export class MatcherComponent implements OnInit, OnDestroy {
2 changes: 0 additions & 2 deletions src/app/matcher/matcher.module.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import { CommonModule } from '@angular/common';
import { UrlSegment, UrlMatchResult, RouterModule, Routes } from '@angular/router';

import { LocalizeRouterModule, LocalizedMatcherUrlSegment } from '@gilsdav/ngx-translate-router';
import { TranslateModule } from '@ngx-translate/core';

import { MatcherComponent } from './matcher.component';

@@ -57,7 +56,6 @@ const routes: Routes = [
CommonModule,
RouterModule.forChild(routes),
LocalizeRouterModule.forChild(routes),
TranslateModule.forChild(),
MatcherComponent
],
providers: [],
1 change: 0 additions & 1 deletion src/app/not-found/not-found.component.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import { RouterLink } from '@angular/router';
selector: 'app-not-found',
templateUrl: './not-found.component.html',
styleUrls: ['./not-found.component.css'],
standalone: true,
imports: [RouterLink, LocalizeRouterPipe]
})
export class NotFoundComponent implements OnInit {
5 changes: 2 additions & 3 deletions src/app/test/bob/bob.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Component, OnInit } from '@angular/core';

import { LocalizeRouterService } from '@gilsdav/ngx-translate-router';
import { TranslateModule } from '@ngx-translate/core';
import { TranslatePipe } from '@ngx-translate/core';

@Component({
selector: 'app-bob',
templateUrl: './bob.component.html',
styleUrls: ['./bob.component.css'],
standalone: true,
imports: [TranslateModule]
imports: [TranslatePipe]
})
export class BobComponent implements OnInit {

3 changes: 0 additions & 3 deletions src/app/test/test.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { TranslateModule } from '@ngx-translate/core';

import { TestRoutingModule } from './test-routing.module';
import { BobComponent } from './bob/bob.component';

@NgModule({
imports: [
CommonModule,
TestRoutingModule,
TranslateModule.forChild(),
BobComponent
]
})
1 change: 0 additions & 1 deletion src/app/test2/bob/bob.component.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import { RouterLink } from '@angular/router';
selector: 'app-bob',
templateUrl: './bob.component.html',
styleUrls: ['./bob.component.css'],
standalone: true,
imports: [RouterLink, LocalizeRouterPipe]
})
export class BobComponent implements OnInit {
6 changes: 2 additions & 4 deletions src/app/test2/test.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { TranslateModule } from '@ngx-translate/core';

import { TestRoutingModule } from './test-routing.module';
import { BobComponent } from './bob/bob.component';
import { Test2Component } from './test2/test2.component';
@@ -11,8 +9,8 @@ import { Test2Component } from './test2/test2.component';
imports: [
CommonModule,
TestRoutingModule,
TranslateModule.forChild(),
BobComponent, Test2Component
BobComponent,
Test2Component
]
})
export class TestModule { }
1 change: 0 additions & 1 deletion src/app/test2/test2/test2.component.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import { RouterOutlet } from '@angular/router';
selector: 'app-test2',
templateUrl: './test2.component.html',
styleUrls: ['./test2.component.css'],
standalone: true,
imports: [RouterOutlet]
})
export class Test2Component implements OnInit {
1 change: 0 additions & 1 deletion src/app/test3/bob/bob.component.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import { RouterLink } from '@angular/router';
selector: 'app-bob',
templateUrl: './bob.component.html',
styleUrls: ['./bob.component.css'],
standalone: true,
imports: [RouterLink, LocalizeRouterPipe]
})
export class BobComponent implements OnInit {
Loading