AWS Amplify未在Nextjs(页面目录)中的动态页面上显示i18n翻译

sz81bmfz  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(92)

我尝试在Nextjs项目中使用next-i18next包。在我的动态页面如:/blogs/[id]部分,i18 n无法翻译页面,只能在服务器上显示其键,但在本地工作正常。
这是我在next-i18 next中的翻译代码:
export async function getServerSideProps(context) { const { locale, params: { id }} = context; return { props: {...(await serverSideTranslations(locale))}}}
在服务器上,它只显示JSON键,我看不到任何翻译。(仅适用于动态页面)
我想这个问题是由于使用了amplify,我们需要对它进行一些配置。

cbjzeqam

cbjzeqam1#

可能存在与解析消息/本地文件相关的问题,如next-i18 next本身的README中所述:
一些无服务器PaaS可能无法定位您的翻译路径,需要额外的配置。
尝试使用path.resolve添加区域设置的绝对路径,例如:

  • next-i18next.config.js:*
const path = require('path');

module.exports = {
    i18n: {
      defaultLocale: 'en',
      locales: ['en', 'cs'],
      localePath: path.resolve('./public/locales')
    },
  };

字符串

相关问题