How to translate text with Angular i18n

Implementing internationalization is crucial for Angular applications that serve users in multiple languages and regions. As the creator of CoreUI with over 11 years of Angular development experience since 2014, I’ve built multilingual interfaces for global enterprise applications. The most effective solution is to use Angular’s built-in i18n system with the i18n attribute to mark translatable text. This approach integrates seamlessly with Angular’s build process and provides compile-time translation for optimal performance.

Use the i18n attribute to mark text for translation in Angular templates.

<!-- template.html -->
<h1 i18n>Welcome to our application</h1>
<p i18n='@@welcomeMessage'>This is a translatable message</p>
<button i18n='Submit button|Button to submit form'>Submit</button>
// component.ts
export class AppComponent {
  userName = 'John'
}
<!-- with variables -->
<p i18n>Hello {{ userName }}</p>

The i18n attribute marks text for extraction and translation. You can add a unique ID using @@id syntax to ensure consistent translations across your app. Descriptions and meaning can be added using the pipe syntax meaning|description. After marking text, run ng extract-i18n to generate translation files. Angular replaces marked text with translations at build time based on the target locale, ensuring no runtime performance overhead.

Best Practice Note

This is the same i18n approach we use in CoreUI Angular components for multilingual support. Always provide unique IDs for important translations to prevent conflicts. For runtime translation or dynamic content, consider using libraries like ngx-translate, but the built-in i18n system offers better performance for static content.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to compare dates with JavaScript
How to compare dates with JavaScript

How to disable a button in JavaScript
How to disable a button in JavaScript

How to Clone an Object in JavaScript
How to Clone an Object in JavaScript

Mastering JavaScript List Comprehension: The Ultimate Guide
Mastering JavaScript List Comprehension: The Ultimate Guide

Answers by CoreUI Core Team