Using language codes in URLs

We are in the process of supporting multiple languages on our Open edX site. Accordingly, we have the desired languages added to the dark lang config and have the SHOW_HEADER_LANGUAGE_SELECTOR setting set to true in our lms.yml file. Everything is working properly in terms of a language selector appearing in the header that a student can interact with to change the display language. However, we’d like to be able to have the language code appear in the URLs.

For example, the Demo Course URL is like this by default (even if viewing in a language that is not the default site language such as Spanish): https://our.openedxexample.org/courses/course-v1:edX+DemoX+Demo_Course/about where we’d like it to appear like: https://our.openedxexample.org/es/courses/course-v1:edX+DemoX+Demo_Course/about or https://our.openedxexample.org/courses/course-v1:edX+DemoX+Demo_Course/about?lang-code=es

It seems that the language is handled by a cookie called openedx-language-preference rather than using language codes in the URL, but the latter is preferable for us so we can send links and advertise our courses in target languages and have potential learners come to the site on a specific language.

@kory, modifying the URLs will require changing the urls.py file directly or via a plugin and I wouldn’t recommend doing that. However, you can create a custom domain and Site for each language like es-courses.example.com and configure the corresponding language (LANGUAGE_CODE) for each site in the SiteConfiguration model.

@guruprasad so if we want to support five different languages, you recommend having five separate installations of Open edX, each on its own subdomain? Is there any way to force a language by passing a parameter in the URL (eg. courses.example.com/?lang=es) to get the first page load to be in the desired language and then the cookie functionality would take over from there?

@kory,

No, I was suggesting that you use the “Sites” feature in Open edX that allows hosting multiple sites with their own configuration on a single instance of Open edX.

See 4.2. Configuring Open edX Sites — Installing, Configuring, and Running the Open edX Platform documentation