Skip to content

Instantly share code, notes, and snippets.

View ivanmiletic's full-sized avatar
💭
Building something amazing!

Ivan Miletic ivanmiletic

💭
Building something amazing!
View GitHub Profile
...
export function initApp(http: HttpClient, translate: TranslateService) {
return () => new Promise<boolean>((resolve: (res: boolean) => void) => {
const defaultLocale = 'en';
http.get(`/assets/i18n/dev.json`).pipe(
catchError(() => of(null))
).subscribe((devKeys: any) => {
translate.setTranslation(defaultLocale, devKeys || {});
{
"main.header.welcome": "Welcome",
"main.page.title": "{{title}} is running!",
"main.page.section.languages.title": "Languages",
"main.page.section.languages.subtitle": "Lets try to change language!",
"main.page.section.languages.english": "English",
"main.page.section.languages.french": "Français"
}
export function initApp(http: HttpClient, translate: TranslateService) {
return () => new Promise<boolean>((resolve: (res: boolean) => void) => {
const defaultLocale = 'en';
const translationsUrl = '/assets/i18n/translations';
const sufix = '.json';
const storageLocale = localStorage.getItem('locale');
const locale = storageLocale || defaultLocale;
forkJoin([
public changeLanguage(code: string) {
localStorage.setItem('locale', code);
window.location.reload();
}
{
"main.header.welcome": "Bienvenue",
"main.page.title": "{{title}} est en cours d'exécution!",
"main.page.section.languages.title": "Langages",
"main.page.section.languages.subtitle": "Essayons de changer de langue!"
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
TranslateModule.forRoot()
],
providers: [],
<!-- Toolbar -->
<div class="toolbar" role="banner">
<img width="40" alt="Angular Logo"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==" />
<span>Welcome</span>
</div>
<div class="content" role="main">
<!-- Highlight Card -->
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title: string = 'dynamic-translations';
}
:host {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 14px;
color: #333;
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
h1,
<!-- Toolbar -->
<div class="toolbar" role="banner">
<img width="40" alt="Angular Logo"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==" />
<span>{{'main.header.welcome' | translate}}</span>
</div>
<div class="content" role="main">
<!-- Highlight Card -->