# Adding Internationalization Support to my xblock - troubleshooting

**URL:** <https://discuss.openedx.org/t/adding-internationalization-support-to-my-xblock-troubleshooting/5286>\
**Category:** Development\
**Tags:** how-to\
**Created:** [June 28, 2021, 3:31pm UTC](https://discuss.openedx.org/t/adding-internationalization-support-to-my-xblock-troubleshooting/5286 "2021-06-28T15:31:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Tsabary](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/guy_tsabary/32/2197_2.png) [@Guy\_Tsabary](https://discuss.openedx.org/u/Guy_Tsabary)\
**Post date:** [June 28, 2021, 3:31pm UTC](https://discuss.openedx.org/t/adding-internationalization-support-to-my-xblock-troubleshooting/5286/1 "2021-06-28T15:31:25Z")

</div>

Hello,

I followed the [7.2.2 documentation](https://edx.readthedocs.io/projects/xblock-tutorial/en/latest/edx_platform/edx_lms.html#internationalization-support) about adding translations to my xblock:

1. Created a simple 1 string translations/‘lang’/LC\_MESSAGES/text.po and generated the text.mo file with ‘msgfmt text.po -o text.mo’

2. Changed the xblock setup.py last line to recognize the local translations directory with  
package\_data=package\_data(“xblock-name”, [“static”, “public”, “translations”])

3. Started the lms and studio containers with ‘make lms-up studio-up’

4. Changed the language with ‘translation.activate(‘lang’)’ in the student\_view() method and saw many translated strings other then the one I tested. The string tested showed its msgid rather than its msgstr

5. But - when manually inserting this string into the end of  
edx-platform/conf/locale/‘lang’/LC\_MESSAGES/django.po and creating the django.mo file, the  
string was translated properly into ‘lang’.

Any hint/suggestion how to “convince” edx-platform to use the xblock translations//text.mo file will be greatly appreciated

Regards,  
Guy

---

<div class="post-metadata">

**Author:** ![msaqib52](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/msaqib52/32/2090_2.png) [@msaqib52](https://discuss.openedx.org/u/msaqib52)\
**Post date:** [June 28, 2021, 4:17pm UTC](https://discuss.openedx.org/t/adding-internationalization-support-to-my-xblock-troubleshooting/5286/2 "2021-06-28T16:17:16Z")

</div>

If this string is part of an HTML template, Probably you are rendering the template using the _render\_template_ method in _student\_view_ instead of _render\_django\_template_(part of xblock-utils and renders the template using the XBlock i18n service). Changing your code to use _render\_django\_template_ should fix the issue. You can check this code for example usage [xblock-drag-and-drop-v2/drag\_and\_drop\_v2.py at master · edx-solutions/xblock-drag-and-drop-v2 · GitHub](https://github.com/edx-solutions/xblock-drag-and-drop-v2/blob/master/drag_and_drop_v2/drag_and_drop_v2.py#L314)

---

<div class="post-metadata">

**Author:** ![Guy\_Tsabary](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/guy_tsabary/32/2197_2.png) [@Guy\_Tsabary](https://discuss.openedx.org/u/Guy_Tsabary)\
**Post date:** [July 8, 2021, 2:58pm UTC](https://discuss.openedx.org/t/adding-internationalization-support-to-my-xblock-troubleshooting/5286/3 "2021-07-08T14:58:36Z")

</div>

Saqib hi and thanks for your answer + sorry for late response.

We followed your example and what finally worked out in our setup is  
that for using translations/‘lang’/LC\_MESSAGES/text.mo strings one should:

1. Add the i18n xblock service with the class preceding decorator  
@XBlock.needs(‘i18n’)

2. Use for each translated string either  
self.runtime.service(self, “i18n”).ugettext(text with vars).format(…)  
or its shortcut (less readable) call  
self.ugettext(text with vars).format(…)  
for example:  
return self.ugettext(“Your recorded (best) score is {old\_best} points from {max\_score} points.{attempts\_message}”).format(  
old\_best = str(self.best\_student\_score), max\_score = str(self.get\_max\_score()),  
attempts\_message = my\_attempts\_message )

This is also explained at  
[https://openedx.atlassian.net/wiki/spaces/AC/pages/161400730/Open+edX+Runtime+XBlock+API](https://openedx.atlassian.net/wiki/spaces/AC/pages/161400730/Open+edX+Runtime+XBlock+API)

1. I did notice in your example a more cautious programming approach that rather defined and used

We may consider its adoption as well

Thanks again  
Regards  
Guy
