forked from ngx-translate/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small demo project for experimenting.
- Loading branch information
1 parent
072722f
commit 7acc672
Showing
18 changed files
with
467 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Routes } from '@angular/router'; | ||
|
||
export const routes: Routes = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
Oops, something went wrong.