6.9. Internationalization#

Follow the internationalization coding guidelines in the edX Developer’s Guide when developing new features.

Languages are enabled in the settings file, for example in ecommerce/settings/base.py

  ('en', _('English')),
  ('es', _('Spanish')),
  ('es-419', _('Spanish (Latin American)')),

More details can be found in the Django documentation for Languages.

6.9.1. E-Commerce Language Negotiation#

Language negotiation for E-Commerce is handled by Django’s Locale Middleware. Django’s Language Negotiation rules, in priority order, are as follows.

  1. Language prefix is not enabled by default for the E-Commerce application.

  2. LANGUAGE_SESSION_KEY is not used.

  3. LANGUAGE_COOKIE_NAME is used to negotiate language. A user’s language is set in their account settings in edx-platform which sets the language cookie. The language cookie name that is set for the E-Commerce language should be the same as the language cookie name set in the edx-platform repo. This can be configured in ecommerce/settings/base.py.

    LANGUAGE_COOKIE_NAME = 'openedx-language-preference'
  4. The Accept-Language HTTP header is used.

  5. LANGUAGE_CODE is used as the last resort. This can be set in ecommerce/settings/base.py

6.9.2. PayPal Language Negotiation#

To enable localization for PayPal, follow these steps.

  1. Sign in to the LMS Django administration console for your base URL. For example, http://{your_URL}/admin.

  2. On the Site Administration page, locate Waffle.

  3. In the Waffle section, next to Switches, select Add.

  4. On the Add switch page, locate the Name field, and then add create_and_set_webprofile.

  5. On the Add switch page, select the Active checkbox.

  6. Select Save.

A language code for E-Commerce will be taken from a cookie as described in E-Commerce Language Negotiation. When the language code is fetched from the cookie, only the base language is used. For example, es-419 resolves to es. PayPal requires a country code. To get the country code, we use the language code to map it to a country. For example, the language code es will map to the country code MX when it is sent to PayPal. To add your language for PayPal, look up PayPal’s country to language mapping and add it to PAYPAL_LOCALES in ecommerce/extensions/payment/constants.py.

    'zh': 'CN',
    'fr': 'FR',
    'en': 'US',
    'es': 'MX',

If a language fetched from the cookie cannot be found in PAYPAL_LOCALES, the LANGUAGE_CODE is used. If the LANGUAGE_CODE does not exist in PAYPAL_LOCALES, PayPal will use its own language negotiation.