Dictionary Customization Guide
Every drop-in includes a dictionary with all user-facing text. Customize it to localize for different languages, match your brand voice, or override default text. The drop-in deep-merges your custom values with defaults—you only specify what you want to change.
Quick start
-
Find the dictionary keys: Check your drop-in’s dictionary page (Cart, Checkout, and so on).
-
Create your overrides:
export const customDictionary = {Cart: {MiniCart: {heading: "Shopping Basket ({count})", // Only override what you wantcartLink: "View Basket"}}}; -
Pass it to
initialize():import { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-cart/api.js';import { customDictionary } from '../config/custom-dictionary.js';const langDefinitions = {default: {...customDictionary,},};await initializers.mountImmediately(initialize, { langDefinitions });
How deep merge works
Understanding the merge behavior is critical:
✅ Override specific keys, keep all the defaults:
// Your dictionary:{ Cart: { MiniCart: { heading: "My Cart" } } }
// Result (merged with defaults):{ Cart: { MiniCart: { heading: "My Cart", // ← Your value cartLink: "View Cart", // ← Default kept checkoutLink: "Checkout" // ← Default kept } }}✅ Nested objects merge recursively:
{ Cart: { PriceSummary: { promoCode: { errors: { invalid: "That code didn't work" // Only this changes // All other errors stay default } } } }}Multi-language support
Create dictionaries for each locale and load them dynamically:
export const cartEN = { Cart: { MiniCart: { heading: "Cart ({count})" } }};export const cartFR = { Cart: { MiniCart: { heading: "Panier ({count})" } }};import { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-cart/api.js';import { cartEN } from '../config/dictionaries/cart-en.js';import { cartFR } from '../config/dictionaries/cart-fr.js';
const userLocale = navigator.language.replace('-', '_');const translations = { en_US: cartEN, fr_FR: cartFR };const selectedLang = translations[userLocale] || cartEN;
const langDefinitions = { default: { ...selectedLang, },};
await initializers.mountImmediately(initialize, { langDefinitions });Advanced patterns
src/config/dictionaries/ cart.js checkout.js user-auth.jsimport { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-cart/api.js';import { cartDictionary } from '../config/dictionaries/cart.js';
const langDefinitions = { default: { ...cartDictionary, },};
await initializers.mountImmediately(initialize, { langDefinitions });{ "Cart": { "MiniCart": { "heading": "Cart ({count})" } }}import { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-cart/api.js';import enUS from '../config/dictionaries/en_US.json';
const langDefinitions = { default: { ...enUS, },};
await initializers.mountImmediately(initialize, { langDefinitions });import { initializers } from '@dropins/tools/initializer.js';import { initialize } from '@dropins/storefront-cart/api.js';
const translations = await fetch('/api/translations/cart/en_US') .then(res => res.json());
const langDefinitions = { default: { ...translations, },};
await initializers.mountImmediately(initialize, { langDefinitions });Best practices
- Keep placeholders - Values with
{count},{price}, and so on, must keep these placeholders for dynamic data injection - Use version control - Track all custom dictionaries in Git
- Start small - Override a few keys, test them, then iterate
- Document the changes - Add comments explaining why certain values were customized
- Test the text length - Longer translations can break the UI layouts
- Check for updates - New drop-in versions may add dictionary keys
Troubleshooting
Custom values not appearing:
- Verify that
langDefinitionsis passed toinitialize() - Check that the locale key matches exactly (
en_USnoten-US) - Ensure that the dictionary structure matches the defaults
- Check the console for initialization errors
Missing dynamic values (counts, prices):
// ❌ Badheading: "Shopping Cart"
// ✅ Good - keep {count} placeholderheading: "Shopping Cart ({count})"Language not switching:
Some components need to re-render after setLang(). Try refreshing the page or re-initializing the drop-in.
Related: Initialization • Labels • Branding