我正在尝试在我的 astro 项目中安装 i18next,但我遇到了新的 i18next 版本包的问题。我用这个参考。然后我更新了依赖项
"dependencies": {
"astro": "^4.11.3",
"astro-i18next": "^1.0.0-beta.21",
"i18next": "^23.11.5"
}
我收到此错误:
TypeError 发生错误。无法读取未定义的属性 (读“地图”)组件/LanguageSelector.astro:26:19
node_modules/astro-i18next/src/components/LanguageSelector.astro
---
import i18next from "i18next";
import { localizePath } from "../..";
import localeEmoji from "locale-emoji";
import ISO6991 from "iso-639-1";
interface languageMapping {
[localeCode: string]: string;
}
export interface Props extends astroHTML.JSX.SelectHTMLAttributes {
showFlag?: boolean;
languageMapping?: languageMapping;
}
const supportedLanguages = i18next.languages;
const currentLanguage = i18next.language;
const { pathname } = Astro.url;
const { showFlag = false, languageMapping, ...attributes } = Astro.props;
---
<select onchange="location = this.value;" {...attributes}>
{
supportedLanguages.map((supportedLanguage: string) => {
let value = localizePath(pathname, supportedLanguage);
const flag = showFlag ? localeEmoji(supportedLanguage) + " " : "";
let nativeName = "";
if (
languageMapping &&
languageMapping.hasOwnProperty(supportedLanguage)
) {
nativeName = languageMapping[supportedLanguage];
} else {
nativeName = ISO6991.getNativeName(supportedLanguage);
}
const label = flag + nativeName;
return (
<option value={value} selected={supportedLanguage === currentLanguage}>
{label}
</option>
);
})
}
</select>
所有配置与参考中的相同。而且我不想降级该软件包。
我仅将 i18next 降级到版本 ^22.4.10,这并没有影响其他依赖项。这解决了错误,但是这个bug在^23.11.5(目前最新的)上仍然存在