Angular provides a robust built-in internationalization (i18n) framework to help developers build multilingual applications. Here's how Angular handles i18n:
🌐 1. Built-In i18n Support
Angular offers native support for i18n through:
-
The
@angular/localize
package -
Markup in templates using the
i18n
attribute -
Compiler-level extraction and localization
🔤 2. Marking Text for Translation
You use the i18n
attribute in templates to mark static text for translation:
You can also add meaning and description:
✅ This metadata helps translators understand context.
📦 3. Extracting Translatable Strings
Run this command to extract messages:
This generates a messages.xlf
or messages.json
file containing all marked strings.
🌍 4. Translating and Managing Files
-
Translators provide localized versions of the file (e.g.,
messages.fr.xlf
for French). -
Tools like POEditor, Crowdin, or Lokalise can manage translations.
⚙️ 5. Building with Locales
To serve different locales, build the app with the appropriate translation file:
You define locales and translation files in angular.json
:
This builds multiple versions of the app, one per language.
🧠 6. Runtime vs. Compile-Time i18n
Angular’s i18n system is compile-time by default, which means:
-
Translations are embedded into separate builds
-
Each language has its own bundle
For runtime translation, third-party libraries like ngx-translate are used when:
-
You need dynamic language switching
-
You want translations loaded from APIs or JSON files
✅ Best Use Cases for Angular's Built-In i18n:
-
SEO-friendly apps
-
Static content-heavy apps
-
Apps where language is chosen at install/load time
🔄 When to Use ngx-translate:
-
Dynamic language switching
-
Translations from external sources or at runtime
-
Apps with lots of user-generated content