在我的 Angular 應用程式中,我試圖僅使用阿拉伯語獲取國家/地區名稱,并使用 i18n-iso-countries 庫將其代碼保留為英語。我使用 npm 安裝了它
npm -i i18n-iso-國家
然后在我的組件中我像這樣匯入它:
從 'i18n-iso-countries' 匯入 * 作為 i18IsoCountries;
我試圖用 ar 替換 en 但它不起作用
getCountries(): { id: string; name: string }[] {
return Object.entries(countriesLib.getNames('ar', { select: 'official' })).map((entry) => {
return {
id: entry[0],
name: entry[1]
};
});
}
getCountry(countryKey: string): string {
return countriesLib.getName(countryKey, 'en');
}
uj5u.com熱心網友回復:
您必須匯入 ar 語言 json 檔案
countriesLib.registerLocale(require('i18n-iso-countries/langs/ar.json'));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/515370.html
標籤:有角度的
