The library includes complete translations for 10 languages, with automatic language detection and support for custom translations.
All language files are located in src/i18n/:
| Language | Code | File | Status |
|---|---|---|---|
| English | en | src/i18n/en.ts |
Complete |
| Spanish | es | src/i18n/es.ts |
Complete |
| German | de | src/i18n/de.ts |
Complete |
| French | fr | src/i18n/fr.ts |
Complete |
| Portuguese | pt | src/i18n/pt.ts |
Complete |
| Italian | it | src/i18n/it.ts |
Complete |
| Dutch | nl | src/i18n/nl.ts |
Complete |
| Polish | pl | src/i18n/pl.ts |
Complete |
| Japanese | ja | src/i18n/ja.ts |
Complete |
| Chinese (Simplified) | zh | src/i18n/zh.ts |
Complete |
Additional files:
src/i18n/index.ts- Exports all translations and utilitiessrc/i18n/localeMapping.ts- Country-to-locale mapping
The library can automatically detect the user's language based on their location or browser settings. Configure this with the localeDetection option:
<ConsentProvider
config={{
localeDetection: 'auto', // Detect from geo, then browser, then fallback
defaultLocale: 'en', // Fallback language
}}
>The detection modes are:
| Mode | Description |
|---|---|
| auto | Try geo-detection first, then browser settings, then fallback to default |
| geo | Detect only from geographic location |
| browser | Detect from browser settings (navigator.language) |
| manual | Use only the configured defaultLocale |
When using geo or auto mode, the library maps countries to their primary language. For example, users in Spain, Mexico, or Argentina see Spanish. Users in Brazil or Portugal see Portuguese. Users in countries not specifically mapped see English.
The library uses a comprehensive translation structure with the following sections:
banner: {
title: string; // "Cookie Settings"
description: string; // Main banner description
acceptAll: string; // "Accept All"
rejectAll: string; // "Reject All"
customize: string; // "Customize"
privacyPolicy: string; // "Privacy Policy"
requiredServices: string; // "Some services are required..."
acceptRequired: string; // "Accept Required"
geoFallbackWarning: string; // Location detection warning
shortAccept: string; // "Accept" (short version for compact variants)
shortReject: string; // "Reject" (short version for compact variants)
shortMore: string; // "More" (for minimal variant)
weUseCookies: string; // "We use cookies." (for minimal variant)
cookies: string; // "cookies" (word for cookie counting)
}modal: {
title: string; // "Cookie Preferences"
description: string; // Modal description
save: string; // "Save Preferences"
acceptAll: string; // "Accept All"
rejectAll: string; // "Reject All"
close: string; // "Close"
alwaysActive: string; // "Always Active"
showServices: string; // "View services"
hideServices: string; // "Hide services"
domains: string; // "Domains"
requiredByAdmin: string; // "Required by site administrator"
requiredReason: string; // Required service explanation
}categories: {
necessary: { name: string; description: string; }
functional: { name: string; description: string; }
analytics: { name: string; description: string; }
marketing: { name: string; description: string; }
personalization: { name: string; description: string; }
}ageVerification: {
yearLabel: string; // "Birth year:"
dateLabel: string; // "Birth date:"
confirmButton: string; // "Confirm age"
goBack: string; // "Go back"
invalidYear: string; // "Please enter a valid year"
invalidDate: string; // "Please enter your birth date"
checkboxConfirm: string; // "I confirm I am at least {age} years old"
}Note: The {age} placeholder in checkboxConfirm is automatically replaced with the configured minimum age.
You can override any translation or add new ones:
<ConsentProvider
config={{
translations: {
en: {
banner: {
title: 'Cookie notice',
description: 'We use cookies to improve your experience.',
acceptAll: 'Accept',
rejectAll: 'Decline',
customize: 'Preferences',
shortAccept: 'OK',
shortReject: 'No',
},
categories: {
analytics: {
name: 'Analytics',
description: 'Cookies that help us understand how you use our site.',
},
},
ageVerification: {
checkboxConfirm: 'I am {age} or older',
},
},
},
}}
>To change the language at runtime:
const { locale, setLocale } = useConsent();
// Get current locale
console.log(locale); // 'en'
// Change to Spanish
setLocale('es');You can also access locale utilities:
import {
getAvailableLocales,
isLocaleAvailable,
getBestLocaleForCountry,
} from 'react-consent-shield';
// Get all available locales
getAvailableLocales(); // ['en', 'es', 'de', 'fr', 'pt', 'it', 'nl', 'pl', 'ja', 'zh']
// Check if a locale is supported
isLocaleAvailable('de'); // true
isLocaleAvailable('ja'); // true
// Get the best locale for a country
getBestLocaleForCountry('ES'); // 'es'
getBestLocaleForCountry('BR'); // 'pt'
getBestLocaleForCountry('JP'); // 'ja'
getBestLocaleForCountry('CN'); // 'zh'
getBestLocaleForCountry('NL'); // 'nl'
getBestLocaleForCountry('PL'); // 'pl'The library includes automatic country-to-locale mapping for over 100 countries:
| Region | Countries | Primary Locale |
|---|---|---|
| East Asia | Japan | ja |
| East Asia | China, Taiwan, Hong Kong, Macau | zh |
| Europe | Netherlands, Belgium, Suriname | nl |
| Europe | Poland | pl |
| Europe | Spain, Mexico, Argentina, etc. | es |
| Europe | Germany, Austria, Liechtenstein | de |
| Europe | France, Canada (Quebec), etc. | fr |
| Europe | Italy, San Marino, Vatican | it |
| South America | Brazil, Portugal, etc. | pt |
| Global | USA, UK, Australia, etc. | en |
Countries without a specific mapping default to English (en).
Back to main documentation | Previous: Audit Logging | Next: Styling