Skip to content

fix: fixed some translations in cms and lms#227

Open
Asespinel wants to merge 1 commit intoopen-craft:masterfrom
eduNEXT:ase/added-translations-support
Open

fix: fixed some translations in cms and lms#227
Asespinel wants to merge 1 commit intoopen-craft:masterfrom
eduNEXT:ase/added-translations-support

Conversation

@Asespinel
Copy link

@Asespinel Asespinel commented Oct 6, 2025

Description

The Poll XBlock had translation infrastructure (.po/.mo files in multiple languages) but translations were not being applied to the UI. Template strings remained in English regardless of the user's language preference.

Why not use Django's {% trans %} template tags?

We initially explored using Django's standard {% trans %} tags, which would be the typical Django approach. However, XBlocks run in a specialized runtime context that is incompatible with Django's translation system:

  1. Different translation contexts: XBlocks use their own i18n service (runtime.service(self, "i18n")) which is separate from Django's global translation system (django.utils.translation)
  2. The merge incompatibility problem: The XBlock framework includes custom template tags (ProxyTransNode) that attempt to bridge this gap by merging XBlock translations into Django's system. However, this requires
    The i18n service to have a _catalog attribute compatible with DjangoTranslation.merge()

Proposed solution

  1. Centralized i18n service in utils.py with the get_xblock_i18n function
  2. Context helper functions:
def add_translations_to_studio_context(context, i18n):
    """Centralize all studio view translations"""
    
def add_translations_to_student_context(context, i18n):
    """Centralize all student view translations"""
  1. Templates use simple variable substitution

Translation file fixes

  1. Fixed .po files where msgid entries had extra newlines and whitespace
  2. Ensured Python code strings exactly match .po file entries
  3. Used % formatting for variable interpolation to match existing .po format

Testing

Tested in teak environment with multiple languages (English, Spanish, French). All strings now translate correctly based on user language preference. To set your lang preference you can choose your language from the account MFE or change the lang cookie using your dev tools.

Screenshot from 2025-10-02 18-57-28 Screenshot from 2025-10-02 19-00-46

@Asespinel
Copy link
Author

Asespinel commented Oct 6, 2025

Hey @itsjeyd hope you’re doing well! 🙂
I wasn’t sure if it’s okay to ask you directly, but whenever you get a chance, could you please take a look at this PR? I’d really appreciate your feedback when you have some time.

@itsjeyd
Copy link
Member

itsjeyd commented Oct 8, 2025

Hi @Asespinel, thank you for this contribution!

I won't be reviewing this PR myself but I'll create an internal ticket for the next OpenCraft sprint to make sure you'll get feedback soon.

@itsjeyd itsjeyd requested a review from Agrendalath October 9, 2025 11:56
@Agrendalath
Copy link
Member

Hi @Asespinel, thank you for the detailed PR description! Would you mind adding an information about how you switch the user language? I tried the following approaches using the master branch (with xblock-poll==1.15.1 installed):

  1. Manually changing the openedx-language-preference cookie value to es for all subdomains.
  2. Going to http://local.openedx.io:8000/update_lang/ and updating the language to es.

In both cases, the Authoring MFE looked like this:
image

The poll_edit view looked like this:
image

The Preview looked like this:
image

I also tested this approach in one of our production Sumac instances (this time with the legacy Studio experience), and noticed that the XBlock was partially translated:
image

Is this something Teak-specific or are you using a different method to define the user's language?

@Asespinel
Copy link
Author

@Agrendalath sorry for the late reply, yeah to switch the user language you can modify the corresponding lang cookie like you said or you can navigate to the account MFE to switch it as needed. When We tested this we used a teak env but in my understanding, this was happening in sumac as well. We may have time to check this again in the following sprint. In the meantime would you like something to be changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants