Message extraction feedback #2036
Replies: 19 comments 69 replies
-
|
Question from @jurerotar:
Answer: Yep, namespaces are being considered, they are currently only briefly mentioned in regard to monorepos in the catalog generation section. E.g.: const t = useExtracted('namespace');
t('Hey there!');… would generate e.g.: {
"namespace": {
"5VpL9Z": "Hey there"
}
}I think the point is valid and this should be clarified more visibly (and perhaps not just be a "future exploration"). The ultimate goal for Does that answer the question? |
Beta Was this translation helpful? Give feedback.
-
|
Quick poll: After reading the section on File formats & AI translation, which file format would you prefer as a default?
|
Beta Was this translation helpful? Give feedback.
-
|
Another poll: Do you prefer import {useExtracted} from 'next-intl';
function InlineMessages() {
const t = useExtracted();
return <h1>{t('Look ma, no keys!')}</h1>;
}import {useInlined} from 'next-intl';
function InlineMessages() {
const t = useInlined();
return <h1>{t('Look ma, no keys!')}</h1>;
}Please vote with your preference:
I'd also appreciate if you leave a comment here explaining why you prefer a particular option! (or why the alternative is bad) |
Beta Was this translation helpful? Give feedback.
-
|
Some thoughts on rich text formatting from @niieani:
I think it's an interesting approach, somewhere in the middle of using direct concatenation and using arguments in ICU strings. Kind of a hybrid solution in contrast to what the RFC currently discusses. |
Beta Was this translation helpful? Give feedback.
-
|
A first release is out in Learn more: |
Beta Was this translation helpful? Give feedback.
-
|
Thanks again for working on this. I wanted to share some initial feedback: 1. Source string in PO filesRight now, the In other frameworks using Gettext (like Phoenix), the It would be great to have an option for this behavior, or at least include the source string as a comment above each 2. Deterministic compilationCurrently, every Ideally, the output should be deterministic and only update when translations are actually added, modified, or removed. |
Beta Was this translation helpful? Give feedback.
-
|
Something else I just noticed: Fallback for untranslated stringsRight now, untranslated strings render as empty. It would be great if they could fall back to the default locale. For example, if a string isn’t yet translated to |
Beta Was this translation helpful? Give feedback.
-
|
Is the package tree-shakeable and does it bundle only the messages used by the current page — similar to how @inlang/paraglide-sveltekit works for SvelteKit? |
Beta Was this translation helpful? Give feedback.
-
|
Should it work with monorepo? Seems like message aren't picked up from packages at build or dev. |
Beta Was this translation helpful? Give feedback.
-
|
i dont have src folder and i want extract from root folder so when use srcPath: "./",instead of srcPath: ["./actions", "./app", "./components", "./lib", "./schemas"],messages not extracted
|
Beta Was this translation helpful? Give feedback.
-
|
Will this work if |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
We use next-intl on all our websites with a dashboard that allows our customers to directly modify translations if they wish. Our workflow is as follows: we load the translations from the JSON, then we retrieve what comes from the database. We merge everything and send it. const json = (await import(`../../messages/${locale}.json`)).default
const flattened = flatten(json) as Record<string, string>
const url = new URL(`${publicEnv.NEXT_PUBLIC_BASE_URL}/api/i18n`)
url.searchParams.set('locale', locale)
const data = await fetch(url.toString())
.then(res => res.json())
.catch(() => ({}))
const messages = {
...flattened,
...data,
}
return {
locale,
messages: {
...(unflatten(messages) as Record<string, unknown>),
},
}With the system as developed here, our version is no longer possible because the keys change. However, if the keys do not change, then we can use the feature. Is it possible that the keys are the text as encoded? Something like : const t = useExtracted('namespace')
return <span>{t('Hello Github')}</span>conversion : {
"namespace": {
"Hello Github": "Hello Github"
}
}which would allow us to change the value in database while keeping the key ? Edit: Looks like I'm not the only one wanting this feature :D #2036 (comment) |
Beta Was this translation helpful? Give feedback.
-
|
When merge default messages with untranslated messages still show empty String |
Beta Was this translation helpful? Give feedback.
-
|
getting this error in monorepo when using import { getExtracted } from "@repo/i18n/server";
export default async function Page() {
const t = await getExtracted();
return (
<h1>{t("title")}</h1>
);
}./apps/web/app/[locale]/page.tsx
Error evaluating Node.js code
ResolveMessage: Cannot find module 'next-intl/extractor/extractionLoader' from 'C:\Users\benna\dev\my-app\apps\web\.next\dev\build\chunks\[turbopack]_runtime.js' |
Beta Was this translation helpful? Give feedback.
-
|
Hello, On the positive side, being able to extract text directly from the code feels cleaner, no VSCode plugin to inline messages, just wrap the text with At the very beginning, I spent a lot of time thinking about key naming and namespaces, but I often ended up duplicating the same translation across different namespaces or keys just to make it easier to locate within the project. Over time, I realized I actually prefer translating the text directly and using the code editor or the PO file to find where each translation resides. One approach I’ve seen in other projects, like Lingui, is to also include the line where the translation appears, which can be helpful. |
Beta Was this translation helpful? Give feedback.
-
|
Let's collect feedback about wiped-out messages here. I'm currently investigating the bug, but I haven't found the cause yet. Can you explain in as much detail as you can what exactly you were doing when this happened to you? And can you give me all the details about your environment (OS, hardware, Next.js version, A few additional questions:
Many thanks for your help, this is at the top of my list for |
Beta Was this translation helpful? Give feedback.
-
|
I've been experimenting with it, but I'm unsure if the behavior is correct: autocompletion isn't working anymore. My expectation: if a message already exists somewhere (e.g., "Reload the page"), typing "Reload" should trigger an autocompletion suggestion. But it's not happening. Question: Is this the expected behavior, or is there an issue with my setup? For info :
Config : // next.config.ts
const withNextIntl = createNextIntlPlugin({
requestConfig: "./src/shared/i18n/request.tsx",
experimental: {
createMessagesDeclaration: "./src/shared/i18n/translations/fr.json",
srcPath: "./src/app",
extract: {
sourceLocale: "fr",
},
messages: {
format: "json",
path: "./src/shared/i18n/translations",
locales: "infer",
},
},
});// request.tsx
export default getRequestConfig(async ({ requestLocale }) => {
// This typically corresponds to the `[locale]` segment
const requested = await requestLocale;
// Ensure that a valid locale is used
const locale = hasLocale(routing.locales, requested)
? requested
: routing.defaultLocale;
await loadZodLocale("fr");
return {
onError: onNextIntlError,
timeZone: "Europe/Paris",
locale,
messages: {
...(await import(`./translations/${locale}.json`)).default,
},
};
});// next-intl.d.ts
declare module "next-intl" {
interface AppConfig {
Locale: (typeof routing.locales)[number];
Messages: messages; // Importing the emitted fr.d.json.ts
Formats: typeof formats;
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Seems like having a newline character in the string passed to t('Test string\nwith newline')results in msgid "J+/aas"
msgstr "Test string
with newline"which I suppose is not allowed by the |
Beta Was this translation helpful? Give feedback.





Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Please use this thread to share feedback related to
useExtracted.This is my public TODO list for the feature: #2087 (but please keep the feedback here)
Beta Was this translation helpful? Give feedback.
All reactions