Skip to content

Commit

Permalink
Small demo project for experimenting.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeAndWeb committed Sep 24, 2024
1 parent 072722f commit 7acc672
Show file tree
Hide file tree
Showing 18 changed files with 467 additions and 0 deletions.
95 changes: 95 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,101 @@
}
}
}
},
"test-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "projects/test-app",
"sourceRoot": "projects/test-app/src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/test-app",
"index": "projects/test-app/src/index.html",
"browser": "projects/test-app/src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "projects/test-app/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"glob": "**/*",
"input": "projects/test-app/public"
}
],
"styles": [
"projects/test-app/src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kB",
"maximumError": "1MB"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kB",
"maximumError": "4kB"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "test-app:build:production"
},
"development": {
"buildTarget": "test-app:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "projects/test-app/tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"glob": "**/*",
"input": "projects/test-app/public"
}
],
"styles": [
"projects/test-app/src/styles.scss"
],
"scripts": []
}
}
}
}
}
}
Binary file added projects/test-app/public/favicon.ico
Binary file not shown.
12 changes: 12 additions & 0 deletions projects/test-app/public/i18n/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"demo": {
"simple": {
"text-as-attribute": "Text als Attribut",
"text-as-content": "Text als Inhalt"
},
"title": "Test Anwendung"
},
"standalone-component": {
"title": "Eigenständige Komponente"
}
}
12 changes: 12 additions & 0 deletions projects/test-app/public/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"demo": {
"simple": {
"text-as-attribute": "Text as attribute",
"text-as-content": "Text as content"
},
"title": "Test Application"
},
"standalone-component": {
"title": "Standalone Component"
}
}
12 changes: 12 additions & 0 deletions projects/test-app/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="title">
<h1>{{ 'demo.title' | translate }}</h1>
</div>
<div>
<h2>Simple translations without parameters</h2>

<p [translate]="'demo.simple.text-as-attribute'"></p>

<p translate>demo.simple.text-as-content</p>
</div>

<app-standalone-component/>
38 changes: 38 additions & 0 deletions projects/test-app/src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
div
{
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 1rem 2rem;
}

p, .translated
{
background-color: #d4f3ff;
padding:0.5rem 1rem;
}

button {
background-color: #008CBA;
border: none;
color: white;
padding: 0.25rem 0.5rem;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-left: 1rem;
border-radius: 0.5rem;
transition: background-color 0.3s ease;

&:hover {
background-color: #005f73;
}
}

.title {
background-color: #bde8f8;
padding: 0.5rem 2rem 1.5rem 2rem;
position: sticky;
top: 0;
z-index: 1000;
}
29 changes: 29 additions & 0 deletions projects/test-app/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent],
}).compileComponents();
});

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it(`should have the 'test-app' title`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('test-app');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, test-app');
});
});
23 changes: 23 additions & 0 deletions projects/test-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Component} from "@angular/core";
import {RouterOutlet} from "@angular/router";
import {TranslateService, TranslatePipe, TranslateDirective} from "@codeandweb/ngx-translate";
import {StandaloneComponent} from "./standalone.component";


@Component({
selector: "app-root",
standalone: true,
imports: [RouterOutlet, TranslateDirective, TranslatePipe, StandaloneComponent],
templateUrl: "./app.component.html",
styleUrl: "./app.component.scss"
})
export class AppComponent
{
title = "test-app";

constructor(private translate: TranslateService) {
this.translate.addLangs(['de', 'en']);
this.translate.setDefaultLang('en');
this.translate.use('en');
}
}
25 changes: 25 additions & 0 deletions projects/test-app/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {ApplicationConfig, provideZoneChangeDetection} from "@angular/core";
import {provideRouter} from "@angular/router";

import {routes} from "./app.routes";
import {HttpClient, provideHttpClient} from "@angular/common/http";
import {TranslateLoader, provideTranslateService} from "@codeandweb/ngx-translate";
import {TranslateHttpLoader} from "@codeandweb/http-loader";

const httpLoaderFactory: (http: HttpClient) => TranslateHttpLoader = (http: HttpClient) =>
new TranslateHttpLoader(http, "./i18n/", ".json");

export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({eventCoalescing: true}),
provideRouter(routes),
provideHttpClient(),
provideTranslateService({
loader: {
provide: TranslateLoader,
useFactory: httpLoaderFactory,
deps: [HttpClient]
}
})
]
};
3 changes: 3 additions & 0 deletions projects/test-app/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Routes } from '@angular/router';

export const routes: Routes = [];
10 changes: 10 additions & 0 deletions projects/test-app/src/app/standalone.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="title">
<h1>{{ 'standalone-component.title' | translate }}</h1>
</div>
<div>
<h2>Simple translations without parameters</h2>

<p [translate]="'demo.simple.text-as-attribute'"></p>

<p translate>demo.simple.text-as-content</p>
</div>
14 changes: 14 additions & 0 deletions projects/test-app/src/app/standalone.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component} from "@angular/core";
import {TranslatePipe, TranslateDirective} from "@codeandweb/ngx-translate";


@Component({
selector: "app-standalone-component",
standalone: true,
imports: [TranslateDirective, TranslatePipe],
templateUrl: "./standalone.component.html"
})
export class StandaloneComponent
{

}
13 changes: 13 additions & 0 deletions projects/test-app/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TestApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
6 changes: 6 additions & 0 deletions projects/test-app/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent, appConfig)
.catch((err) => console.error(err));
1 change: 1 addition & 0 deletions projects/test-app/src/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */
Loading

0 comments on commit 7acc672

Please sign in to comment.