Sun Woo Kang
Sun Woo Kang

Reputation: 1

next-i18next translations break during ECS deployment

I am experiencing an issue with next-i18next translations in my Next.js project during AWS ECS deployments. Here’s the situation:

Issue Steps:

  1. Deploy the application to AWS ECS successfully.
  2. Open the deployed website, and everything works fine, including translations.
  3. Trigger a new deployment of the application.
  4. During the deployment process, if I navigate between pages on the currently deployed site, the translations break. Instead of showing the translated values, the keys (e.g., common:next) are displayed. But this is not always, it happens sometimes.

My Setup:

getStaticProps in pages/index.tsx:

export async function getStaticProps({
  locale,
  locales,
}: IDefaultGetStaticProps) {
  return {
    props: {
      ...(await serverSideTranslations(locale, [
        ...commonNamespaces,
        'dashboard',
      ])),
      locales,
    },
  };
}

What I Tried:

  1. Set localePath in next-i18next.config.js:
const path = require('path');
module.exports = {
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'ko'],
    defaultNS: 'common',
    localeDetection: true,
  },
  localePath: path.resolve('./public/locales'),
};
  1. Configured headers in next.config.js to disable caching for /locales:
const { i18n } = require('./next-i18next.config');
module.exports = {
  output: 'standalone',
  reactStrictMode: true,
  i18n,
  transpilePackages: ['helper'],
  webpack: (config) => {
    config.resolve.alias.canvas = false;
    return config;
  },
  async headers() {
    return [
      {
        source: '/:path*',
        headers: [
          {
            key: 'Access-Control-Allow-Origin',
            value: 'My-Devloped-Web-Url',
          },
          {
            key: 'Access-Control-Allow-Methods',
            value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT',
          },
          {
            key: 'Access-Control-Allow-Headers',
            value:
              'X-CSRF-Token, X-Requested-With, Accept, Content-Type, Authorization',
          },
        ],
      },
      {
        source: '/locales/:all*',
        headers: [
          {
            key: 'Cache-Control',
            value: 'no-store, must-revalidate',
          },
        ],
      },
    ];
  },
};
}

  1. Added middleware for /locales paths:
export async function middleware(req: NextRequest) {
  ...
}

export const config = {
  matcher: [
    '/',
    '/locales/:path*',
    '/((?!api|_next/static|_next/image|images|assets|favicon|mockServiceWorker|fonts).*)'
  ]
}

Despite these attempts, the issue persists.

What I Suspect:

Upvotes: 0

Views: 21

Answers (0)

Related Questions