Skip to content

Instantly share code, notes, and snippets.

View itayod's full-sized avatar

Itay Oded itayod

  • Tel Aviv
View GitHub Profile
<ng-container *transloco="let t; scope: 'core'">
<p>{{ t('core.title') }}</p>
</ng-container>
import { Component, OnInit } from '@angular/core';
import { TRANSLOCO_SCOPE } from '@ngneat/transloco';
@Component({
selector: 'app-core',
templateUrl: './core.component.html',
providers: [{ provide: TRANSLOCO_SCOPE, useValue: 'core']
})
export class CoreComponent {
constructor() {}
{
"scopePathMap": {
"my-scope": "src/app/path-to-scope",
"my-project-scope": "projects/my-project/i18n"
}
}
{
"hello": "transloco es",
"todos": {
"todos-translation": "todos es"
}
}
const { TranslocoScopedLibsWebpackPlugin } = require('@ngneat/transloco-scoped-libs/webpack');
module.exports = {
plugins: [new TranslocoScopedLibsWebpackPlugin()]
};
@Injectable({ providedIn: 'root' })
export class HttpLoader implements TranslocoLoader {
contructor(private http: HttpClient) {}
getTranslation(lang: string, { scope }) {
const base = this.http.get(`/assets/i18n/${lang}.json`);
if(scope) {
return base;
}
{
"name": "@app/core",
"i18n": [
{
"scope": "core",
"path": "src/lib/i18n",
"strategy": "join"
}
]
}
module.exports = {
...
scopedLibs: [
{
src: './projects/core',
dist: ['./projects/spa/src/assets/i18n', './src/assets/i18n/']
}
]
};​
module.exports = {
...
scopedLibs: ['./projects/core/', '@lib/name']
};
{
"name": "@app/core",
"i18n": [
{
"scope": "core",
"path": "src/lib/i18n"
}
]
}