Replies: 6 comments 7 replies
-
I like the pattern. So I have an idea, what about structuring files for messages inside folder of a component and load it dynamically to the config (somehow)? @amannn Now you can use multiple files per locale (https://next-intl-docs-git-docs-app-router-first-next-intl.vercel.app/docs/configuration#messages), but I think it could be imported to the config (and also types) automatically (hierarchically) by some pattern (e.g. **/specificFolderName/*.json) |
Beta Was this translation helpful? Give feedback.
-
Redirected from #425. I like the idea of structuring the message by component name I think it would be critical to keep this optional instead of required. One of the reasons to keep it optional instead of required is because my app uses some translation that is shared across components/pages. Taking my game info app as an example, the translation of an item must be the same in the same locale, but these items could show up in different pages, so there's no point making them into separate translations. |
Beta Was this translation helpful? Give feedback.
-
I don't like this pattern because it makes refactoring component (renaming, splitting into smaller components, etc...) a big pain. Also it's ackward if I have the same text for two different components. |
Beta Was this translation helpful? Give feedback.
-
I would really like to have an option to put the translations like so: import { useTranslations } from 'next-intl';
export default function Page() {
const t = useTranslations();
return <div>{t({ en: 'Title', de: 'Titel' })}</div>;
} The advantages of this patterns are:
Disadvantages are:
|
Beta Was this translation helpful? Give feedback.
-
One of the things I learned (from others, but also the hard way) working for years with large translation codebases is that you should never (with some global exceptions) reuse translations across components or pages. I absolutely love the idea proposed here as a developer, it just feels right. I have, however, worked with enough translators and translation software, to know that:
Both of this seem nearly impossible with the proposed setup :( |
Beta Was this translation helpful? Give feedback.
-
Apologies if this has been brought up already (I couldn't find any existing discussions here about this), but I really prefer the developer experience with libraries like react-intl and lingui, where they can automatically generate message IDs based on the content of the translation, rather than manually specifying an ID. Really helps speed up the dev process and improves readability of components when you have immediate feedback of what the user will see in your default locale. Are there any plans to support automatic message ID generation in the future, with this library? |
Beta Was this translation helpful? Give feedback.
-
In the docs, we recommend structuring messages by component name.
Components are the main concept for code reuse in React apps and we can piggyback on that for message reuse.
It’s a constraint, but I believe it results in a simpler mental model with a guarantee to know which message is used where. Also, this results in somewhat shorter message keys in components.
Since this is entirely optional, I'd be curious about how many people use this pattern, if you've encountered problems, or if you prefer an entirely different pattern and why.
Beta Was this translation helpful? Give feedback.
All reactions