Skip to documentation content
CookieBeam

Languages

How the banner picks a visitor's language, how translations are loaded, and how to override both.

Last updated:

CookieBeam ships seeded banner translations in 30 languages, and the banner picks one per visitor automatically. You can change the detection strategy, pin a default language, or supply your own translations.

Language and translation settings live in the banner designer: Dashboard → Banners → your banner → Design, in the Content section, where you can add languages, set the default, and edit per-language copy. Save in the designer, then Publish from the banner header; translation changes only reach visitors on publish. Verify by loading your site with a browser language (or geo location) that matches a configured language and checking the banner renders in it.

How the visitor's language is chosen

The banner's language configuration has an autoDetect mode. Each mode is a waterfall that stops at the first language you actually have content for:

  • geo: the visitor's country (resolved at the CDN edge) is mapped to a default language. If you don't bundle that language, the runtime fetches it on demand. If the country has no mapping or isn't configured, the visitor's browser language is tried next, then your configured default.
  • browser: the visitor's browser language preference list is tried in order, then the geo language, then the default. Only languages you can actually serve (bundled inline or declared for on-demand fetch) are considered.
  • document: the page's own lang attribute first, then the browser preference list, then geo, then the default.
  • none: your configured default language when the banner loads.

If the page changes its lang attribute from one language to another once the banner has started loading, including while its translation is still being fetched (for example a single-page app switching language), the banner follows it in every mode. In document mode detection runs again, so a page language you have no content for falls through to the browser language, then geo, then the default. Two kinds of write never change the banner: one that keeps the same language, and one that adds lang to a page that had none, as frameworks often do during hydration. To switch the banner yourself, call CookieBeam.setLanguage(code).

Language matching is case-insensitive and falls back from a regional variant to its base language: a visitor preferring pt-BR can be served your pt translation.

The default language itself is your configured default if you have a translation for it; otherwise the first translation in your configuration.

LanguageConfig reference

The runtime's language configuration has these fields:

FieldTypeDescription
defaultstringThe default language code. Used when detection finds nothing
autoDetect'browser' | 'document' | 'geo' | 'none'Detection strategy. See above
translationsRecord<string, TranslationData>Inline translations keyed by language code. These are bundled into the published script
rtlLanguagesstring[]?Language codes that trigger right-to-left layout (e.g. ar, he)
dynamicLanguagesstring[]?Languages that can be fetched on demand from CDN. See Dynamic language loading
cdnTranslationUrlstring?URL template with a {lang} placeholder for fetching dynamic translations
translationResolverTranslationResolver?Override how translations are loaded. See Overriding translations

Translation format

Each translation is a TranslationData object with two required top-level sections:

consentModal: the text shown on the initial consent banner:

FieldTypeRequiredDescription
titlestringYesModal heading
descriptionstringYesMain consent explanation
acceptAllBtnstringYes"Accept all" button label
acceptNecessaryBtnstringYes"Accept necessary" button label
showPreferencesBtnstringYes"Manage preferences" button label
closeIconLabelstringNoAccessible label for the close button
footerstringNoRaw HTML footer (legacy). Use footerLinks instead
footerLinksFooterLink[]NoStructured footer links. Takes precedence over raw footer

preferencesModal: the text shown in the detailed preferences view:

FieldTypeRequiredDescription
titlestringYesModal heading
acceptAllBtnstringYes"Accept all" button label
acceptNecessaryBtnstringYes"Accept necessary" button label
savePreferencesBtnstringYes"Save preferences" button label
closeIconLabelstringNoAccessible label for the close button
serviceCounterLabelstringNoLabel template for the service count (e.g. ({count} services))
sectionsTranslationSection[]YesCategory descriptions and toggle labels
footerstringNoRaw HTML footer
footerLinksFooterLink[]NoStructured footer links

Optional additional sections on the same object:

  • usPrivacy: text for the US opt-out panel (link text, panel title, toggle labels, confirmation button)
  • gpcToast: text for the GPC acknowledgment toast
  • tcfLayer1 and tcfLayer2: text for IAB TCF first-layer and second-layer disclosures

footerLinks is an array of { label, href, newTab? } objects. It renders structured links in the modal footer and takes precedence over the raw footer HTML field. Use it for privacy policy and imprint links.

Dynamic language loading

When you publish a banner, CookieBeam inlines the default language plus every language you customized, and declares the remaining platform languages as dynamic languages. If detection picks a dynamic language, the runtime fetches it from the CookieBeam CDN.

The default CDN URL template is:

https://cdn.cookiebeam.com/translations/platform/{lang}.json

You can override this with a custom cdnTranslationUrl that points to your own translation endpoint.

How the fetch works:

  1. Detection picks a language that isn't inlined (e.g. a geo-detected visitor from Thailand needs th).
  2. The runtime checks whether th is in the dynamicLanguages list.
  3. If it is, the runtime fetches from the CDN URL template, replacing {lang} with th.
  4. The fetched JSON is validated against the expected TranslationData shape. Invalid or missing fields are ignored and fall through to defaults.
  5. The translation is cached in memory for the page lifetime. A second resolution doesn't refetch.

If the fetch fails (network error, 404, invalid JSON), resolution falls through:

  1. Your configured default language
  2. English (en)
  3. A minimal built-in English copy

A failed fetch never strands the visitor; the banner always renders.

RTL support

When a language code is in the rtlLanguages array, the banner renders with dir="rtl". The layout mirrors: buttons, toggles, and text flow from right to left. The floating settings button and modal positions respect RTL.

Arabic (ar) and Hebrew (he) are the most common RTL languages. If you add a custom RTL translation, include its code in rtlLanguages or the layout won't mirror.

Overriding translations

Three resolver strategies are available in the language configuration:

  • Inline (the default); translations live in the banner configuration. If the resolved language isn't bundled, the runtime tries the platform CDN copy before giving up.
  • URL template: provide a URL containing a {lang} placeholder (for example https://example.com/i18n/{lang}.json); the runtime fetches and validates the JSON per language.
  • Function: self-hosted installs can supply a loader function that returns the translation object.

Fetched or supplied translations are validated against the expected shape (consent modal and preferences modal fields) before use, and cached for the page lifetime so repeat resolutions don't refetch.

The language switcher

When configured, a globe icon button appears at the end of the banner's footer row. Clicking it opens a dropdown with the available languages.

Configuration fields:

FieldTypeDescription
enabledtrueMust be true to render the switcher
languagesLanguageSwitcherOption[]Available languages. Each has a code (language code the runtime can resolve) and a label (native name shown in the menu, e.g. "Deutsch")
labelRecord<string, string>?Accessible button text per language code (e.g. { en: "Language", de: "Sprache" })

The switcher renders only when the list contains at least two languages. Selecting a language calls CookieBeam.setLanguage() internally and the banner re-renders in the new language.

Configure the switcher in the banner designer under Content → Language switcher. The languages you list should be a subset of the languages you've configured translations for; listing a language with no translation shows a broken entry.

Per-region wording

Regional rules can override banner text per language on top of everything above; use this for legally reviewed wording per jurisdiction rather than for general translation work. The override precedence is: base translation → framework preset text → per-rule translationOverrides. See Regional rules.

AltStyle によって変換されたページ (->オリジナル) /