我正在使用 p-datepicker 组件,但我想将其翻译成法语和西班牙语。我怎样才能在 Angular/Primeng 19 中做到这一点?
经过研究,我发现了这个:
npm i primelocale
(https://github.com/primefaces/primelocale)代码配置翻译示例:
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { provideHttpClient, withFetch } from '@angular/common/http';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { providePrimeNG } from 'primeng/config';
import Lara from '@primeng/themes/lara';
import MyLaraLightBluePreset from './style';
import { fr } from "primelocale/fr.json"
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes),provideAnimationsAsync(),provideHttpClient(withFetch()),
providePrimeNG({
translation: fr,
theme: {
preset: MyLaraLightBluePreset,
options: {
darkModeSelector: '.my-app-dark'
}
}
})
]
};
使用 PrimeNG 本地化支持
导入区域设置和配置
import { PrimeNGConfig } from 'primeng/api';
import { localeFr } from 'primeng/api'; // French
import { localeEs } from 'primeng/api'; // Spanish
像这样使用它。
export class AppModule {
constructor(private primeNGConfig: PrimeNGConfig) {
// Set the locales as per needs
this.primeNGConfig.setTranslation(localeFr); // French
// this.primeNGConfig.setTranslation(localeEs); // Spanish
}
}