aidiomix automatically detects translatable text in your codebase using a priority-based system.
@aidiomix-translate) - Highest priorityt('text'), formatMessage(), etc.)<Trans>, <FormattedMessage>, etc.)Text directly inside JSX elements is automatically detected:
<div>Hello World</div> // ✅ Detected
Common attributes that contain user-facing text are automatically detected:
placeholder - Input placeholderstitle - Tooltips and titlesalt - Image alt textaria-label - Accessibility labelsaria-describedby - Accessibility descriptionslabel - Form labels<Input placeholder="Search..." /> // ✅ Detected
<img alt="User avatar" /> // ✅ Detected
<button title="Click me"> // ✅ Detected
Functions configured in translationFunctions are automatically detected:
// i18next
{t('Hello World')}
i18n.t('Welcome')
// react-intl
formatMessage({ id: 'greeting' })
intl.formatMessage({ defaultMessage: 'Hello' })
// next-intl
t('Hello World')
Components configured in richTextComponents are automatically detected:
// i18next
<Trans i18nKey="greeting">Hello World</Trans>
// react-intl
<FormattedMessage id="greeting" defaultMessage="Hello World" />
You can explicitly control which texts should be translated using inline comments.
Use @aidiomix-translate (or @translate, @t) to mark texts that might not be automatically detected:
// In attributes
<Input
value="ACTIVE" // @aidiomix-translate
placeholder="vous@exemple.com" // @no-translate
/>
// In string literals
const statusLabels = {
ACTIVE: "Active", // @aidiomix-translate
INACTIVE: "Inactive", // @aidiomix-translate
};
// In JSX text
<div>
{/* @aidiomix-translate */}
Technical term that should be translated
</div>
// In expressions
{status === "ACTIVE" ? (
"Actif" // @aidiomix-translate
) : (
"Inactif" // @aidiomix-translate
)}
You can combine multiple directives on the same line to specify both translation and namespace:
Syntax:
// @aidiomix-translate @aidiomix-namespace: <namespace>
// or
// @translate @namespace: <namespace>
Examples:
// String literals with namespace
const message = "Hello"; // @aidiomix-translate @aidiomix-namespace: common
const button = "Click me"; // @translate @namespace: buttons
// JSX text with namespace
<div>
{/* @aidiomix-translate @aidiomix-namespace: common */}
Hello World
</div>
// JSX attributes with namespace
<Input
placeholder="Search..." // @aidiomix-translate @aidiomix-namespace: forms
/>
This allows you to override the namespace for individual keys, giving you fine-grained control over how translations are organized. See the Namespace Strategy documentation for more details.
Use @no-translate (or @skip-translation, @notranslate) to prevent automatic detection:
<Input placeholder="https://exemple.com" // @no-translate
<Input placeholder="vous@exemple.com" // @skip-translation
You can define custom rules for specific patterns in your codebase:
textDetection: {
customRules: [
{
// Detect status labels in Record objects
pattern: /STATUS_LABELS\[(\w+)\]\s*=\s*"([^"]+)"/g,
processor: (detectedString, match) => {
return {
stringToResolve: match[2] // The label value
};
},
priority: 10
},
{
// Detect error messages
pattern: /throw\s+new\s+Error\(["']([^"']+)["']\)/g,
processor: (detectedString, match) => {
return {
stringToResolve: match[1]
};
},
priority: 5
}
]
}
When detecting text in translation function calls, variables are automatically preserved:
// Before
t('Hello {name}', { name: 'John' })
// After (only the string is replaced)
t('common.greeting', { name: 'John' })
Variables in the second argument are preserved automatically.
@aidiomix-translate for Record values that should be translated@no-translate for URLs, IDs, and technical identifiers