Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN?}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Monorepo for [simply-translate](https://www.npmjs.com/package/simply-translate)

### [simply-translate-angular](projects/translate/README.md)

The core translation library — `TranslateModule`, directive, pipes, `TranslateService`, and dictionary loading (root/lazy). See [projects/translate/README.md](projects/translate/README.md) for setup and usage, and its [changelog](projects/translate/CHANGELOG.md).
The core translation library — `provideTranslate()`, standalone directive and pipes, `TranslateService`, and dictionary loading (root/lazy). See [projects/translate/README.md](projects/translate/README.md) for setup and usage, and its [changelog](projects/translate/CHANGELOG.md).

### [simply-translate-angular-proxy](projects/proxy/README.md)

Expand All @@ -16,12 +16,12 @@ Optional add-on built on top of `simply-translate-angular` — `TranslateProxy`

```bash
npm ci
npm test # tests both libraries once in headless Chrome
npm test # both libraries and the demo app, once in headless Chrome
npm run build:prod # builds dist/translate and dist/proxy
npm run start:demo # demo app on http://localhost:4800 (run build:prod first)
```

The proxy library and the demo app import `simply-translate-angular` from `dist/translate`, so build the translate library before working on them.
The proxy library imports `simply-translate-angular` from `dist/translate`, and the demo app imports `simply-translate-angular-proxy` from `dist/proxy`, so build those before working on them — `npm test` does it in order.

## Releasing

Expand Down
46 changes: 23 additions & 23 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"newProjectRoot": "projects",
"projects": {
"simply-translate": {
"root": "",
"sourceRoot": "src",
"root": "projects/demo",
"sourceRoot": "projects/demo/src",
"projectType": "application",
"prefix": "app",
"schematics": {
Expand All @@ -18,16 +18,16 @@
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/simply-translate",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"index": "projects/demo/src/index.html",
"main": "projects/demo/src/main.ts",
"polyfills": "projects/demo/src/polyfills.ts",
"tsConfig": "projects/demo/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
"projects/demo/src/favicon.ico",
"projects/demo/src/assets"
],
"styles": [
"src/styles.scss"
"projects/demo/src/styles.scss"
],
"scripts": [],
"vendorChunk": true,
Expand All @@ -41,8 +41,8 @@
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
"replace": "projects/demo/src/environments/environment.ts",
"with": "projects/demo/src/environments/environment.prod.ts"
}
],
"optimization": true,
Expand Down Expand Up @@ -87,26 +87,26 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.cjs",
"main": "projects/demo/src/test.ts",
"polyfills": "projects/demo/src/polyfills.ts",
"tsConfig": "projects/demo/tsconfig.spec.json",
"karmaConfig": "projects/demo/karma.conf.cjs",
"styles": [
"src/styles.scss"
"projects/demo/src/styles.scss"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
"projects/demo/src/favicon.ico",
"projects/demo/src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
"projects/demo/tsconfig.app.json",
"projects/demo/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
Expand All @@ -116,14 +116,14 @@
}
},
"simply-translate-e2e": {
"root": "e2e/",
"root": "projects/demo/e2e",
"projectType": "application",
"prefix": "",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"protractorConfig": "projects/demo/e2e/protractor.conf.js",
"devServerTarget": "simply-translate:serve"
},
"configurations": {
Expand All @@ -135,7 +135,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"tsConfig": "projects/demo/e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
"build:dev": "ng build translate && ng build proxy --configuration development",
"publish:translate": "npm run build:translate && npm publish ./dist/translate",
"publish:proxy": "npm run build:prod && npm publish ./dist/proxy",
"build:demo:dev": "ng build --configuration development",
"build:demo:prod": "node --max-old-space-size=8192 ./node_modules/@angular/cli/bin/ng build --configuration production --aot",
"start:demo": "ng serve --port 4800 --live-reload false",
"build:demo:dev": "ng build simply-translate --configuration development",
"build:demo:prod": "node --max-old-space-size=8192 ./node_modules/@angular/cli/bin/ng build simply-translate --configuration production --aot",
"start:demo": "ng serve simply-translate --port 4800 --live-reload false",
"restart:all": "npm run build:prod && npm run start:demo",
"test": "npm run test:translate && npm run build:translate && npm run test:proxy",
"test": "npm run test:translate && npm run build:translate && npm run test:proxy && npm run build:proxy && npm run test:demo",
"test:translate": "ng test translate --watch=false --browsers=ChromeHeadless",
"test:proxy": "ng test proxy --watch=false --browsers=ChromeHeadless",
"test:demo": "ng test simply-translate --watch=false --browsers=ChromeHeadless",
"test:watch": "ng test translate",
"e2e": "ng e2e"
"e2e": "ng e2e simply-translate-e2e"
},
"dependencies": {
"@angular/animations": "^17.3.12",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions e2e/tsconfig.e2e.json → projects/demo/e2e/tsconfig.e2e.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"outDir": "../../../out-tsc/app",
"module": "commonjs",
"target": "es5",
"types": [
Expand Down
2 changes: 1 addition & 1 deletion src/karma.conf.cjs → projects/demo/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (config) {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
dir: require('path').join(__dirname, '../../coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
Expand Down
6 changes: 6 additions & 0 deletions projects/demo/src/_translate.imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// In a real application this is simply:
// export * from 'simply-translate-angular';
// It must resolve to the same copy simply-translate-angular-proxy imports (dist/translate, see tsconfig paths):
// pointing at projects/translate/src instead creates a second TranslateService class, and the proxies
// fail with "No provider for TranslateService". Run `npm run build:translate` after changing the library.
export * from 'simply-translate-angular';
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
import { TRANSLATE_IMPORTS } from 'src/_translate.imports';
@Component({
standalone: true,
imports: [TRANSLATE_IMPORTS, RouterLink],
styles: [
`
:host {
Expand Down
30 changes: 30 additions & 0 deletions projects/demo/src/app/another-dynamic/dynamic.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HttpClient } from '@angular/common/http';
import { inject } from '@angular/core';
import { Routes } from '@angular/router';
import { forkJoin, map } from 'rxjs';
import { Dictionary, withTranslateChild } from 'src/_translate.imports';
import { DynamicComponent } from './dynamic.component';
import { OtherDynamicComponent } from './other-dynamic.component';

function getDictionary(lang: string, client: HttpClient) {
return client.get<Dictionary>(`/assets/translations/${lang}.other-dynamic.json`);
}

export const routes: Routes = [
{
path: '',
...withTranslateChild({
id: 'another_dynamic',
loadDictionaries: ({ lang }) => {
const client = inject(HttpClient);
return forkJoin([getDictionary(lang!, client), getDictionary('ru-RU', client)]).pipe(
map(([current, fallback]) => ({ [lang!]: { ...current, same_key: 'Same in another Dynamic' }, 'ru-RU': fallback })),
);
},
}),
children: [
{ path: '', component: DynamicComponent },
{ path: 'other', component: OtherDynamicComponent },
],
},
];
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Component } from '@angular/core';
import { TRANSLATE_IMPORTS } from 'src/_translate.imports';
@Component({
standalone: true,
imports: [TRANSLATE_IMPORTS],
selector: 'app-dynamic',
template: `
<h2>{{ 'hello_user_dynamic' | translateTo: 'ru-RU': { user: 'Basil' } }}</h2>
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions projects/demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, ViewEncapsulation } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
import { TRANSLATE_IMPORTS } from 'src/_translate.imports';
@Component({
standalone: true,
imports: [TRANSLATE_IMPORTS, ReactiveFormsModule, RouterOutlet, RouterLink, RouterLinkActive],
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
nameInput = new FormControl('');
constructor() {
}

}
44 changes: 44 additions & 0 deletions projects/demo/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { HttpClient, provideHttpClient } from '@angular/common/http';
import { ApplicationConfig, inject } from '@angular/core';
import { provideRouter } from '@angular/router';
import { forkJoin, map } from 'rxjs';
import { Dictionary, provideTranslate, withLoader, withMiddleware } from 'src/_translate.imports';
import { routes } from './app.routes';
import { TranslateProxyMore, TranslateProxyOneMore } from './try-proxy/translate.proxy';

function getDictionary(lang: string, client: HttpClient) {
return client.get<Dictionary>(`/assets/translations/${lang}.json`);
}

export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
provideRouter(routes),

provideTranslate(
{
lang: 'en-US',
fallbackLang: 'en-US',
},

withMiddleware(() => [
({ params, result }) => {
if (result.fallingBack) {
console.warn('falling back:', `${params.key.toString()}, [${params.lang}]`);
}
},
]),

// dependencies come from inject(), there is no deps array any more
withLoader(({ lang }) => {
const client = inject(HttpClient);
return forkJoin([getDictionary(lang!, client), getDictionary('ru-RU', client)]).pipe(
map(([current, fallback]) => ({ [lang!]: current, 'ru-RU': fallback })),
);
}),
),

TranslateProxyMore,
TranslateProxyOneMore,
],
};
18 changes: 18 additions & 0 deletions projects/demo/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Routes } from '@angular/router';
import { TranslateToComponent } from './components/translate-to.component';
import { TryDateComponent } from './components/try-date.component';
import { SwitchLangComponent } from './switch-lang/switch-lang.component';
import { AppTranslateComponent } from './translate.component';
import { TryDirectiveComponent } from './try-directive/try-directive.component';
import { TryProxyComponent } from './try-proxy/try-proxy.component';

export const routes: Routes = [
{ path: 'translate', component: AppTranslateComponent },
{ path: 'translate-to', component: TranslateToComponent },
{ path: 'try-date', component: TryDateComponent },
{ path: 'switch-lang', component: SwitchLangComponent },
{ path: 'try-directive', component: TryDirectiveComponent },
{ path: 'try-proxy', component: TryProxyComponent },
{ path: 'dynamic', loadChildren: () => import('./dynamic/dynamic.routes').then((m) => m.routes) },
{ path: 'another-dynamic', loadChildren: () => import('./another-dynamic/dynamic.routes').then((m) => m.routes) },
];
Loading
Loading