--- createdAt: 2025-04-18 updatedAt: 2026-05-31 title: "Angular 21 i18n - あなたのアプリを翻訳する完全ガイド" description: "i18nextはもう不要。2026年に多言語(i18n)Angular 21アプリを構築するためのガイド。AIエージェントで翻訳し、バンドルサイズ、SEO、パフォーマンスを最適化します。" keywords: - 国際化 - ドキュメント - Intlayer - Angular - JavaScript slugs: - doc - environment - angular applicationTemplate: https://github.com/aymericzip/intlayer-angular-21-template applicationShowcase: https://intlayer-angular-21-template.vercel.app/ history: - version: 8.9.0 date: 2026-05-04 changes: "Solid useIntlayer APIのプロパティへの直接アクセスへの変更" - version: 8.0.0 date: 2026-01-26 changes: "安定版リリース" - version: 8.0.0 date: 2025-12-30 changes: "initコマンドの追加" - version: 5.5.10 date: 2025-06-29 changes: "初期履歴" --- # Intlayerを使用してAngular 21(Vite)Webサイトを翻訳する | 国際化(i18n) ## 目次 ## 代替手段ではなく Interlayer を使用する理由 「ngx-translate」や「angular-l10n」などの主要なソリューションと比較して、Intlayer は次のような統合された最適化を備えたソリューションです。 **Angular を完全にカバー** Intlayer は、**コンポーネント レベルのコンテンツ スコープ**、**遅延読み込み**、および国際化 (i18n) のスケーリングに必要なすべての機能を提供することにより、Angular と完全に連携するように最適化されています。 **バンドルサイズ** 大量の JSON ファイルをページにロードするのではなく、必要なコンテンツのみをロードします。 Intlayer は、**バンドルとページのサイズを最大 50% 削減**するのに役立ちます。 **保守性** アプリケーションのコンテンツのスコープを設定すると、大規模なアプリケーションの **メンテナンスが容易になります**。コンテンツ コードベース全体を確認するという精神的な負担を負うことなく、単一の機能フォルダーを複製または削除できます。さらに、Intlayer は**完全に型指定**されており、コンテンツの正確性を保証します。 **AI エージェント** コンテンツを同じ場所に配置すると、大規模言語モデル (LLM) によって **必要なコンテキストが削減**されます。 Intlayer には、翻訳の欠落をテストする **CLI**、**[LSP](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/lsp.md)**、**[MCP](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/mcp_server.md)** などのツール スイートも付属しています。および **[エージェント スキル](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/agent_skills.md)** により、AI エージェントの開発者エクスペリエンス (DX) がさらにスムーズになります。 **オートメーション** AI プロバイダーの費用で、選択した LLM を使用して CI/CD パイプラインで自動化を変換します。 Intlayer は、コンテンツ抽出を自動化する **コンパイラー** と、**バックグラウンドでの翻訳**を支援する [Web プラットフォーム](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md) も提供します。 **パフォーマンス** 大量の JSON ファイルをコンポーネントに接続すると、パフォーマンスと反応性の問題が発生する可能性があります。 Intlayer は、ビルド時のコンテンツの読み込みを最適化します。 **非開発によるスケーリング** Intlayer は単なる i18n ソリューションではなく、**自己ホスト型 [ビジュアル エディター](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md)** と **[完全な CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_CMS.md)** を提供します。 **リアルタイム**で多言語コンテンツを管理できるようになり、翻訳者、コピーライター、その他のチーム メンバーとのコラボレーションがシームレスになります。コンテンツはローカルおよび/またはリモートに保存できます。 --- ## AngularアプリケーションでIntlayerをセットアップするためのステップバイステップガイド GitHubで[アプリケーションテンプレート](https://github.com/aymericzip/intlayer-angular-21-template)を参照してください。 npmを使用して必要なパッケージをインストールします: ```bash packageManager="npm" npm install intlayer angular-intlayer npm install @angular-builders/custom-esbuild --save-dev npx intlayer init ``` ```bash packageManager="pnpm" pnpm add intlayer angular-intlayer pnpm add @angular-builders/custom-esbuild --save-dev pnpm intlayer init ``` ```bash packageManager="yarn" yarn add intlayer angular-intlayer yarn add @angular-builders/custom-esbuild --save-dev yarn intlayer init ``` ```bash packageManager="bun" bun add intlayer angular-intlayer bun add @angular-builders/custom-esbuild --dev bun x intlayer init ``` - **intlayer** 構成管理、翻訳、[コンテンツ宣言](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/content_file.md)、トランスパイル、[CLIコマンド](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/cli/index.md)のための国際化ツールを提供するコアパッケージ。 - **angular-intlayer** IntlayerをAngularアプリケーションに統合するパッケージ。Angularの国際化のためのコンテキストプロバイダとフックを提供します。 - **@angular-builders/custom-esbuild** Angular CLIのesbuild構成をカスタマイズするために必要です。 アプリケーションの言語を構成するための構成ファイルを作成します: ```typescript fileName="intlayer.config.ts" codeFormat={["typescript", "esm", "commonjs"]} import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, // その他の言語 ], defaultLocale: Locales.ENGLISH, }, }; export default config; ``` > この設定ファイルを通じて、ローカライズされたURL、ミドルウェアのリダイレクト、Cookie名、コンテンツ宣言の場所と拡張子、コンソールでのIntlayerログの無効化などを設定できます。利用可能なパラメーターの完全なリストについては、[設定ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/configuration.md)を参照してください。 IntlayerをAngular CLIと統合するには、カスタムビルダーを使用する必要があります。このガイドでは、Vite/esbuild(Angular 21プロジェクトのデフォルト)を使用していることを前提としています。 まず、カスタムesbuildビルダーを使用するように`angular.json`を変更します。`build`と`serve`の構成を更新します: ```json5 fileName="angular.json" { "projects": { "your-app-name": { "architect": { "build": { "builder": "@angular-builders/custom-esbuild:application", // replace "@angular/build:application" "options": { "define": { "process.env": "{}", }, "plugins": ["./esbuild.plugins.ts"], "browser": "src/main.ts", // ... }, }, "serve": { "builder": "@angular-builders/custom-esbuild:dev-server", // replace "@angular/build:dev-server" "options": { "prebundle": { "exclude": [ "intlayer", "angular-intlayer", "@intlayer/config/built", "@intlayer/core" ] }, }, }, }, }, } ``` > `angular.json`内の`your-app-name`をプロジェクトの実際のプロジェクト名に置き換えることを忘れないでください。 次に、プロジェクトのルートに`esbuild.plugins.ts`ファイルを作成します: ```typescript fileName="esbuild.plugins.ts" import { intlayerEsbuildPlugin } from "angular-intlayer/esbuild"; export default [intlayerEsbuildPlugin()]; ``` > `intlayerEsbuildPlugin`関数はesbuildにIntlayerを設定します。コンテンツ宣言ファイルを処理するプラグインを注入し、最適なパフォーマンスのためのエイリアスを設定します。 > **NX ユーザー**: NX の Angular ビルダーは、Node のネイティブ ESM 解決を介してプラグインファイルをロードし、TypeScript プラグインファイルをその場でコンパイルしません。代わりに `.mjs` ファイルを使用し、それに応じて `angular.json` の `plugins` 参照を更新してください: > > ```javascript fileName="esbuild.plugins.mjs" > import { intlayerEsbuildPlugin } from "angular-intlayer/esbuild"; > > export default [intlayerEsbuildPlugin()]; > ``` > > その後、`angular.json` で `"./esbuild.plugins.ts"` の代わりに `"./esbuild.plugins.mjs"` を指定します。 翻訳を保存するためにコンテンツ宣言を作成および管理します: ```tsx fileName="src/app/app.content.ts" contentDeclarationFormat=["typescript", "esm", "cjs"] import { t, type Dictionary } from "intlayer"; const appContent = { key: "app", content: { title: t({ en: "Hello", fr: "Bonjour", es: "Hola", }), congratulations: t({ en: "Congratulations! Your app is running. 🎉", fr: "Félicitations! Votre application est en cours d'exécution. 🎉", es: "¡Felicidades! Tu aplicación está en ejecución. 🎉", }), exploreDocs: t({ en: "Explore the Docs", fr: "Explorer les Docs", es: "Explorar los Docs", }), learnWithTutorials: t({ en: "Learn with Tutorials", fr: "Apprendre avec les Tutoriels", es: "Aprender con los Tutorios", }), cliDocs: "CLI Docs", angularLanguageService: t({ en: "Angular Language Service", fr: "Service de Langage Angular", es: "Servicio de Lenguaje Angular", }), angularDevTools: "Angular DevTools", github: "Github", twitter: "Twitter", youtube: "Youtube", }, } satisfies Dictionary; export default appContent; ``` > コンテンツ宣言は、`contentDir`ディレクトリ(デフォルトでは`./src`)に含まれている限り、アプリケーション内のどこにでも定義できます。また、コンテンツ宣言ファイルの拡張子(デフォルトでは`.content.{json,ts,tsx,js,jsx,mjs,cjs,md,mdx,yaml,yml}`)と一致している必要があります。 > 詳細については、[コンテンツ宣言のドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/content_file.md)を参照してください。 Angularアプリケーション全体でIntlayerの国際化機能を活用するには、アプリケーションの構成でIntlayerを提供する必要があります。 ```typescript fileName="src/app/app.config.ts" import { ApplicationConfig } from "@angular/core"; import { provideRouter } from "@angular/router"; import { provideIntlayer } from "angular-intlayer"; import { routes } from "./app.routes"; export const appConfig: ApplicationConfig = { providers: [ provideRouter(routes), provideIntlayer(), // ここにIntlayerプロバイダを追加します ], }; ``` 次に、任意のコンポーネント内で`useIntlayer`機能を使用できます。 ```typescript fileName="src/app/app.component.ts" import { Component } from "@angular/core"; import { RouterOutlet } from "@angular/router"; import { useIntlayer } from "angular-intlayer"; @Component({ selector: "app-root", standalone: true, imports: [RouterOutlet], templateUrl: "./app.component.html", styleUrl: "./app.component.css", }) export class AppComponent { content = useIntlayer("app"); } ``` そして、テンプレートでは: ```html fileName="src/app/app.component.html" {{ content().title }} {{ content().congratulations }} ``` Intlayerのコンテンツは`Signal`として返されるため、シグナルを呼び出すことで値にアクセスします:`content().title`。 コンテンツの言語を変更するには、`useLocale`関数によって提供される`setLocale`関数を使用できます。これにより、アプリケーションのロケールを設定し、それに応じてコンテンツを更新できます。 言語を切り替えるためのコンポーネントを作成します: ```typescript fileName="src/app/locale-switcher.component.ts" import { Component } from "@angular/core"; import { CommonModule } from "@angular/common"; import { useLocale } from "angular-intlayer"; @Component({ selector: "app-locale-switcher", standalone: true, imports: [CommonModule], template: ` @for (loc of availableLocales; track loc) { {{ loc }} } `, }) export class LocaleSwitcherComponent { localeCtx = useLocale(); locale = this.localeCtx.locale; availableLocales = this.localeCtx.availableLocales; setLocale = this.localeCtx.setLocale; } ``` 次に、このコンポーネントを`app.component.ts`で使用します: ```typescript fileName="src/app/app.component.ts" import { Component } from "@angular/core"; import { RouterOutlet } from "@angular/router"; import { useIntlayer } from "angular-intlayer"; import { LocaleSwitcherComponent } from "./locale-switcher.component"; @Component({ selector: "app-root", standalone: true, imports: [RouterOutlet, LocaleSwitcherComponent], templateUrl: "./app.component.html", styleUrl: "./app.component.css", }) export class AppComponent { content = useIntlayer("app"); } ``` ### TypeScriptの設定 Intlayerは、TypeScriptの利便性を高め、コードベースをより堅牢にするためにモジュール拡張を使用します。   TypeScript構成に自動生成された型が含まれていることを確認してください。 ```json5 fileName="tsconfig.json" { // ... 既存のTypeScript構成 "include": [ // ... 既存のTypeScript構成 ".intlayer/**/*.ts", // 自動生成された型を含める ], } ``` ### Gitの設定 Intlayerによって生成されたファイルを無視することをお勧めします。これにより、Gitリポジトリへのコミットを避けることができます。 これを行うには、`.gitignore`ファイルに次の指示を追加できます: ```bash # Intlayerによって生成されたファイルを無視 .intlayer ``` ### VS Code拡張機能 Intlayerでの開発エクスペリエンスを向上させるために、公式の**Intlayer VS Code拡張機能**をインストールできます。 [VS Code Marketplaceからインストール](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension) この拡張機能は次を提供します: - 翻訳キーの**オートコンプリート**。 - 欠落している翻訳の**リアルタイムエラー検出**。 - 翻訳されたコンテンツの**インラインプレビュー**。 - 翻訳を簡単に作成および更新するための**クイックアクション**。 拡張機能の使い方の詳細については、[Intlayer VS Code拡張機能のドキュメント](https://intlayer.org/doc/vs-code-extension)を参照してください。 --- ### さらに進む さらに進むには、[ビジュアルエディター](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_visual_editor.md)を実装したり、[CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_CMS.md)を使用してコンテンツを外部化したりできます。 ---
{{ content().congratulations }}