10章:Internationalization, Localization, and Accessibility of Angular Applications
を読んだので調べたことをつらつらと書く
・多言語化
translocoというライブラリを使う
npm i @ngneat/transloco nx g @ngneat/transloco:ng-add
ng-addはライブラリをプロジェクトに追加する
transloco-loader.tsが自動生成される
app.configにloaderが追加される
https://www.alpha.co.jp/blog/202306_02/
・多言語化のやり方(テンプレート編)
<ng-container *transloco="let t">
<h1>{{ t('expenses_overview') }}</h1>
</ng-container>
・多言語化のやり方(コンポーネント編)
const translococ =
this.translationService.translocoService.translate('expenses_overview');
console.log(translococ);
this.translationService.translocoService
.selectTranslate('expenses_overview')
.subscribe((title) => {
console.log('async:' + title);
});