为什么我的 next-i18next 不工作,即使翻译的内容立即写入 json 文件

问题描述 投票:0回答:0

应用程序没有从 json 文件中获取最新内容。 我在数据库中有翻译。对于页面 /product/3,我做如下服务器端道具:

export async function getServerSideProps({ params, locale }) {
    const res = await axios.get(`/api/products/${params.id}`);
    return {
      props: {
        ...(await serverSideTranslations(locale, ['singleproduct'])),
      },
    };
}
the api is like this:
import db from '../../../db';
import fs from 'fs';
import axios from 'axios';

export default async function handler(req, res) {
    const { method } = req;

    if(method === 'GET') {
        try {
            var enResults = await axios.get('mydatabase link');
            var deResults = await axios.get('my database link');

            const singleFileDE = './public/locales/de/singleproduct.json';
            const singleFileEN = './public/locales/en/singleproduct';
            const singleFileDefault = './public/locales/default/singleproduct.json';


            const singleproductDataDE  = JSON.parse(fs.readFileSync(singleFileDE, 'utf8'));
            const singleproductDataEN  = JSON.parse(fs.readFileSync(singleFileEN, 'utf8'));
            const singleproductDataDefault  = JSON.parse(fs.readFileSync(singleFileDefault, 'utf8'));

            var deDestinations = deResults.data.message;
            var enDestinations = enResults.data.message;
           
            let updatedData = {
                    ...homeDataAR,
                    singleproduct: deDestinations
            };...

            fs.writeFileSync(homeFileDE, JSON.stringify(updatedData, null, 2));

            return res.json(deDestinations);
        } catch(error) {
            console.log(error);
        }
    }
}

next-i18next.config.js:

const path = require("path");

module.exports = {
  i18n: {
    locales: ["default", "en", "ar"],
    defaultLocale: "default",
    localeDetection: false,
  },
};

仅此而已。该 api 完美运行,写入 json 文件,但 next-i18next 未加载最新内容 :(,如果有人可以提供帮助,请帮助

node.js next.js internationalization i18next next-i18next
© www.soinside.com 2019 - 2024. All rights reserved.