Internationalization
Learn how to translate c15t.com components to your language with i18n.
Understanding the Translation System
c15t.com uses a simple yet powerful translation system that allows you to:
- Provide translations for all UI text in multiple languages
- Set a default language
- Fall back to English when translations are missing
The translation system is built into the core package and is used by all components. Each component automatically uses the correct translations based on your configuration.
Basic Translation Setup
To provide your own translations, pass them through the ConsentManagerProvider
configuration:
Translation Structure
The translation object follows a specific structure with these main sections:
cookieBanner
: Translations for the cookie consent bannerconsentManagerDialog
: Translations for the detailed consent management dialogconsentManagerWidget
: Translations for the floating consent manager widgetconsentTypes
: Translations for different types of consent categories
Here's the complete structure of the translation object:
Best Practices
-
Complete Translations: Ensure you provide translations for all keys in your language object. Missing translations will fall back to English.
-
Testing: Test your translations in the actual UI to ensure text fits properly and doesn't break layouts.
-
Maintenance: Keep your translations in sync with the English version when updating to new versions of this package.
Default Language
The defaultLanguage
in the translation config determines which language to use. If translations for the specified language are not found or are incomplete, the system automatically falls back to English.
Using Translations Programmatically
If you're building custom components that need to access translations, you can use the useTranslations
hook:
This hook automatically handles language selection and fallback behavior, ensuring your component always has access to the correct translations.