Localization

Supported Locales

English (US)

en-US

English (UK)

en-GB

German

de-DE

Spanish

es-ES

French

fr-FR

Italian

it-IT

Polish

pl-PL

Portuguese

pt-PT

Romanian

ro-RO

Russian

ru-RU

Turkish

tr-TR

Finnish

fi-FI

Norwegian

no-NO

Setting the Locale

You can set the locale when initializing the widget:

const widget = PaySightSDK.createWidget({
  targetId: 'payment-form',
  config: {
    // Required fields
    productId: 123,
    sessionId: 'session_xyz',
    amount: 9999,
    environment: 'production',
    
    // Set the locale
    locale: 'fr-FR', // French (France)
  }
});

Localization Effects

Custom Button Text

Localization Best Practices

1

Default to Browser Locale

Consider detecting the user’s browser locale and setting the widget locale accordingly:

// Get browser locale or default to en-US
const getBrowserLocale = () => {
  const browserLocale = navigator.language;
  const supportedLocales = [
    'en-US', 'en-GB', 'de-DE', 'es-ES', 'fr-FR', 
    'it-IT', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 
    'tr-TR', 'fi-FI', 'no-NO'
  ];
  
  // Check if browser locale is supported
  if (supportedLocales.includes(browserLocale)) {
    return browserLocale;
  }
  
  // Check if language part is supported (e.g., 'de' from 'de-CH')
  const languagePart = browserLocale.split('-')[0];
  const matchingLocale = supportedLocales.find(locale => 
    locale.startsWith(languagePart + '-')
  );
  
  return matchingLocale || 'en-US';
};
2

Provide Language Selection

Give users the ability to choose their preferred language:

// Example of a language selector implementation
const languageSelector = document.getElementById('language-selector');

languageSelector.addEventListener('change', (event) => {
  const newLocale = event.target.value;
  
  // Update the widget locale
  widget.updateConfig({
    locale: newLocale
  });
  
  // Optionally, save the user's preference
  localStorage.setItem('preferred-locale', newLocale);
});
3

Test with RTL Languages

If you plan to support right-to-left languages in the future, test your integration with RTL layout.

4

Ensure Consistent Experience

Make sure the rest of your application is localized to match the widget locale for a consistent user experience.

Complete Implementation Example

Next Steps