Recipe: Handling Multi-Language Content
This recipe explains how to handle multi-language content in your Archibald application.
For SAP Commerce (Hybris)
The SAP Commerce integration handles localization implicitly, based on the user's session.
How it Works
- For SAP Commerce, the language is typically part of the user's profile and session.
- When you call the
usePagehook, you do not need to pass alocaleparameter. - The
CommerceCMSProvideron the server uses the user's session to determine the correct language. - The underlying Hybris OCC APIs are then called with the appropriate language parameter, and the content is returned in the user's preferred language.
In short, for SAP Commerce, you don't need to do anything special in your components to handle multi-language content, as long as the user's language is correctly set in their session.
For Other CMS (e.g., Contentful)
For other CMS providers like Contentful, you typically need to pass the desired locale as a parameter.
How it Works
- Get the current locale in your component, likely from a localization context or a router.
- Pass the
localeto theusePagehook.
import { usePage } from '@archibald/cms';
import { useLocale } from 'your-localization-library'; // Example
function MyPageComponent() {
const { locale } = useLocale();
const { data, isLoading } = usePage({
pageLabelOrId: 'homepage',
locale: locale // Pass the locale here
});
// ...
}
Your custom CMSProvider on the server will then receive this locale and must use it when fetching data from the CMS API.