com um clique
intlayer-angular
// Integrates Intlayer internationalization with Angular applications. Use when the user asks to "setup Angular i18n", create a new translated component, use the "useIntlayer" composable, or configure providers.
// Integrates Intlayer internationalization with Angular applications. Use when the user asks to "setup Angular i18n", create a new translated component, use the "useIntlayer" composable, or configure providers.
Integrates Intlayer internationalization with Astro applications. Use when the user asks to "setup Astro i18n", use "getIntlayer" in Astro components, or manage server-side content in Astro.
Define rich content structures using Intlayer content nodes. Use when the user asks to "create translations", "handle pluralization", "use markdown in content", or implement "conditional content".
Integrates Intlayer internationalization with Next.js App Router and Pages Router. Use when the user asks to "setup Next.js i18n", use "useIntlayer" in Server Components, or handle client-side translations in Next.js.
Integrates Intlayer internationalization with Preact applications. Use when the user asks to "setup Preact i18n", create a new translated component, use the "useIntlayer" hook in Preact, or configure providers.
Integrates Intlayer internationalization with React component. Use when the user asks to "setup React i18n", create a new translated component, use the "useIntlayer" hook, or configure providers.
Integrates Intlayer internationalization with SolidJS components. Use when the user asks to "setup SolidJS i18n", create a new translated component, use the "useIntlayer" hook in Solid, or configure providers.
| name | intlayer-angular |
| description | Integrates Intlayer internationalization with Angular applications. Use when the user asks to "setup Angular i18n", create a new translated component, use the "useIntlayer" composable, or configure providers. |
| metadata | {"author":"Intlayer","url":"https://intlayer.org","license":"Apache-2.0","mcp-server":"@intlayer/mcp","category":"productivity","tags":["i18n","angular"],"documentation":"https://intlayer.org/doc","support":"contact@intlayer.org"} |
Intlayer promotes Component-Level Content Declaration. Instead of a massive global translation file, content is declared in *.content.ts files adjacent to the Angular components that use them.
To create a translated component, you need two files:
my-component.content.ts) defining the dictionary.my-component.component.ts) using the useIntlayer signal.Create a content file using t() for translations.
File: src/app/my-component/my-component.content.ts
import { t, type Dictionary } from "intlayer";
const content = {
// The 'key' must be unique and matches what you pass to useIntlayer()
key: "my-component",
content: {
text: t({
en: "Welcome",
fr: "Bienvenue",
es: "Hola",
}),
},
} satisfies Dictionary;
export default content;
To use Intlayer in your Angular application, you need to add the provideIntlayer provider to your application configuration.
import { ApplicationConfig } from "@angular/core";
import { provideIntlayer } from "angular-intlayer";
export const appConfig: ApplicationConfig = {
providers: [provideIntlayer()],
};
In Angular, useIntlayer returns a Signal. You must call it as a function to access the value.
import { Component } from "@angular/core";
import { useIntlayer } from "angular-intlayer";
@Component({
selector: "app-my-component",
standalone: true,
template: `
<div>
<h1>
{{ content().text }}
</h1>
<img [src]="content().text.value" [alt]="content().text.value" />
</div>
`,
})
export class MyComponent {
content = useIntlayer("my-component");
}
To change the language, use the setLocale function from the useLocale hook.
import { Component } from "@angular/core";
import { useLocale } from "angular-intlayer";
import { Locales } from "intlayer";
@Component({
selector: "app-locale-switcher",
standalone: true,
template: `
<button (click)="setLocale(Locales.FRENCH)">
Change Language to French
</button>
`,
})
export class LocaleSwitcherComponent {
Locales = Locales;
private localeCtx = useLocale();
setLocale = this.localeCtx.setLocale;
}
Ensure your application's navigation respects the current locale by using a localized link. You can create a component or use a helper.
import { Component, Input } from "@angular/core";
import { RouterModule } from "@angular/router";
import { useLocale } from "angular-intlayer";
import { getLocalizedUrl } from "intlayer";
@Component({
selector: "app-link",
standalone: true,
imports: [RouterModule],
template: `
<a [routerLink]="localizedHref()" [replaceUrl]="false">
<ng-content></ng-content>
</a>
`,
})
export class LinkComponent {
@Input() href: string = "";
private localeCtx = useLocale();
locale = this.localeCtx.locale;
localizedHref() {
return this.href.startsWith("http")
? this.href
: getLocalizedUrl(this.href, this.locale());
}
}