js-lingui icon indicating copy to clipboard operation
js-lingui copied to clipboard

When using Next.js dynamic routing, it is not possible to extract text into Po files.

Open Yidoon opened this issue 10 months ago • 2 comments

Description

In my Next.js project, I used dynamic routing [...params], and I customized the output directory for Lingui, finally I discovered that [...params] appeared in the directory. However, there was no content inside; it should have contained a "hello world" message.

The official demo can also reproduce it. 👉repo

Verifications

  • [x] I've checked the docs and this isn't covered there.
  • [x] I've searched existing issues on GitHub.

Reproduction Steps

lingui.config.js Use {name} to custom the output

const nextConfig = require("./next.config")

/** @type {import('@lingui/conf').LinguiConfig} */
module.exports = {
  locales: nextConfig.i18n.locales,
  pseudoLocale: "pseudo",
  sourceLocale: nextConfig.i18n.defaultLocale,
  fallbackLocales: {
    default: "en",
  },
  catalogs: [
    {
      path: "src/locales/{name}/{locale}/messages",
      include: ["src/pages/{name}"],
    },
  ],
}

pages/[...params]/index.tsx add 'Hello world'

import { Trans } from "@lingui/react/macro"

export default function Home() {
  return <Trans>Hello World</Trans>
}

locales/[...params]/cs/message.po But 'hello world' did not appear

msgid ""
msgstr ""
"POT-Creation-Date: 2025-02-13 20:31+0800\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: @lingui/cli\n"
"Language: cs\n"

Expected Behavior

"hello word" should appear in the po file

Macro Support

Babel with babel-macro-plugin

Lingui Version

5.0.0-next.2

Babel Version

5.0.0-next.2

Framework

Next.js

Yidoon avatar Feb 13 '25 12:02 Yidoon

Sounds like a bug, probably some issue with folder matching when there is [..] symbols.

The PR with a fix is welcome.

timofei-iatsenko avatar Feb 13 '25 13:02 timofei-iatsenko

Is there a work around for this...?

RicSala avatar Apr 24 '25 03:04 RicSala