aidiomix automatically organizes translations using namespaces based on the file structure. This helps keep your translations organized and prevents key conflicts.
'full-path')Uses the complete file path relative to sourceDirectories as the namespace.
Example:
./app/components/ui/Button.tsxcomponents.ui.Buttoncomponents.ui.Button.hello_worldPros:
Cons:
'filename')Uses only the filename (without path or extension) as the namespace.
Example:
./app/components/ui/Button.tsxButtonButton.hello_worldPros:
Cons:
'x-first-parent')Uses the first X parent directories as the namespace. Replace x with the number of directories you want.
Examples:
'1-first-parent': File ./app/components/ui/Button.tsx → Namespace: components (1 parent, filename excluded)'2-first-parent': File ./app/components/ui/Button.tsx → Namespace: components.ui (2 parents, filename excluded)'3-first-parent': File ./app/components/ui/Button.tsx → Namespace: components.ui (only 2 parents available, filename excluded)Pros:
Cons:
'x-last-parent')Uses the last X parent directories (including filename) as the namespace. Replace x with the number of directories you want.
Examples:
'1-last-parent': File ./app/components/ui/Button.tsx → Namespace: Button (1 element: filename only)'2-last-parent': File ./app/components/ui/Button.tsx → Namespace: ui.Button (2 elements: 1 parent + filename)'2-last-parent': File ./app/[lang]/client/campaigns/[id]/page.tsx → Namespace: campaigns.id (2 elements: 1 parent + filename, normalized from campaigns.[id])'3-last-parent': File ./app/components/ui/Button.tsx → Namespace: components.ui.Button (3 elements: 2 parents + filename)Pros:
[lang], [id])Cons:
Handling Dynamic Route Segments:
For files with dynamic route segments like [lang], [id], or [...slug], the brackets are automatically removed:
[lang] → lang[id] → id[...slug] → slug'global')No namespace prefix - all translations are at the root level.
Example:
./app/components/Button.tsxhello_world (no namespace prefix)Pros:
Cons:
'content-hash')Uses a hash of the file content to create a stable namespace.
Example:
./app/components/Button.tsxa1b2c3d4 (first 8 characters of MD5 hash)a1b2c3d4.hello_worldPros:
Cons:
Regardless of the configured strategy, you can override the namespace by adding a comment at the top of your file:
Single-line comment:
// @namespace: common.buttons
// or
// @aidiomix-namespace: common.buttons
Multi-line comment:
/* @namespace: common.buttons */
/* or */
/* @aidiomix-namespace: common.buttons */
Example:
// @namespace: shared.components
const Button = () => {
return <div>Hello World</div>;
};
The explicit namespace takes precedence over the configured strategy. This is useful when:
You can also specify a namespace for individual translation keys by combining directives on the same line. This gives you fine-grained control over how specific keys are organized.
Syntax:
// @aidiomix-translate @aidiomix-namespace: <namespace>
// or
// @translate @namespace: <namespace>
Examples:
const message = "Hello"; // @aidiomix-translate @aidiomix-namespace: common
const button = "Click me"; // @translate @namespace: buttons
<div>
{/* @aidiomix-translate @aidiomix-namespace: common */}
Hello World
</div>
<Input
placeholder="Search..." // @aidiomix-translate @aidiomix-namespace: forms
/>
// File-level namespace: components.Button (from strategy)
const Button = () => {
const title = "Welcome";
// Uses file namespace: components.Button.text_xxx
const commonText = "Hello"; // @aidiomix-translate @aidiomix-namespace: common
// Uses specific namespace: common.text_xxx
return (
<div>
<h1>{title}</h1>
<p>{commonText}</p>
</div>
);
};
Behavior:
Use cases:
Use full-path (default) when:
Use filename when:
Use x-first-parent when:
components/, pages/, features/)Use x-last-parent when:
[id] or [lang]Use global when:
Use content-hash when: