i18next 适用于开发服务器,但不适用于 Azure 应用服务

i18next works on dev server but not in azure app-service

我做了一个react应用,用i18next包翻译了一下。 因为我已经安装了 i18n-backend 模块,所以我将我的文件放在目录 "public/locales/en/translation.json" 中。 在我开发的过程中,这很好用。但是如果我将它部署到 AZURE 应用程序服务,它会给我警告 "missing keys".

顺便提一下:

The files do exist in the directory from the App-Service and it's the same path.

但我无法通过 URL

访问它们

"myApplicationURL/locales/en/translation.json"。

import i18n from 'i18next';
import Backend from 'i18next-xhr-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';

const fallbackLng = ['en'];
const availableLanguages = ['en', 'de'];

i18n
    .use(Backend)

    .use(LanguageDetector)

    .use(initReactI18next)

    .init({
        fallbackLng,
        debug: true,
        whitelist: availableLanguages,

        interpolation: {
            escapeValue: false
        },
    });

export default i18n;

有没有人遇到过这个问题? 老实说,我不知道如何解决这个问题。

谢谢

运行 本地反应 (webpack) 使用 devserver 为您的本地 /public 文件夹提供服务 -> 在您的服务器上,这种魔法不存在......文件只是不由没有配置的服务器...

现在可以了。如果您有同样的问题,只需插入:

<staticContent>
    <mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>

进入web.config文件。 这允许服务器提供 json 个文件。