Posez votre question et obtenez un résumé du document en referencant cette page et le Provider AI de votre choix
Le contenu de cette page a été traduit à l'aide d'une IA.
Voir la dernière version du contenu original en anglaisIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Contenu Conditionnel / Condition dans Intlayer
Comment Fonctionne la Condition
To utilize conditional content within a React component, import and use the useIntlayer hook from the react-intlayer package. This hook fetches the content for the specified key and allows you to pass in a condition to select the appropriate output.
Copier le code dans le presse-papiers
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const ConditionalComponent: FC = () => {
const { myCondition } = useIntlayer("my_key");
return (
<div>
<p>
{
/* Output: my content when it's true */
myCondition(true)
}
</p>
<p>
{
/* Output: my content when it's false */
myCondition(false)
}
</p>
<p>
{
/* Output: my content when the condition fails */
myCondition("")
}
</p>
<p>
{
/* Output: my content when the condition fails */
myCondition(undefined)
}
</p>
</div>
);
};
export default ConditionalComponent;Configuration du Contenu Conditionnel
Pour configurer le contenu conditionnel dans votre projet Intlayer, créez un module de contenu qui inclut vos définitions conditionnelles. Voici des exemples dans différents formats.
Copier le code dans le presse-papiers
import { cond, type Dictionary } from "intlayer";
const myConditionalContent = {
key: "my_key",
content: {
myCondition: cond({
true: "mon contenu lorsque c'est vrai",
false: "mon contenu lorsque c'est faux",
fallback: "mon contenu lorsque la condition échoue", // Optionnel
}),
},
} satisfies Dictionary;
export default myConditionalContent;Si aucun fallback n'est déclaré, la dernière clé déclarée sera prise comme fallback si la condition n'est pas validée.
Utilisation du Contenu Conditionnel avec React Intlayer
To utilize conditional content within a React component, import and use the useIntlayer hook from the react-intlayer package. This hook fetches the content for the specified key and allows you to pass in a condition to select the appropriate output.
Copier le code dans le presse-papiers
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const ConditionalComponent: FC = () => {
const { myCondition } = useIntlayer("my_key");
return (
<div>
<p>
{
/* Output: my content when it's true */
myCondition(true)
}
</p>
<p>
{
/* Output: my content when it's false */
myCondition(false)
}
</p>
<p>
{
/* Output: my content when the condition fails */
myCondition("")
}
</p>
<p>
{
/* Output: my content when the condition fails */
myCondition(undefined)
}
</p>
</div>
);
};
export default ConditionalComponent;Ressources Supplémentaires
Pour plus d'informations détaillées sur la configuration et l'utilisation, consultez les ressources suivantes :
Ces ressources offrent des informations supplémentaires sur la configuration et l'utilisation d'Intlayer dans divers environnements et frameworks.