How gettext in js files works?

98 views
Skip to first unread message

Siavash Kavousi

unread,
Sep 19, 2016, 1:26:15 PM9/19/16
to General Open edX discussion
Hi,

I wonder how gettext function in javascript files of edx-platform works? 
And Is it possible to do the same thing on xblock? or Is there any other way to translate javascript strings in xblock?

Andy Armstrong

unread,
Sep 19, 2016, 2:06:21 PM9/19/16
to edx-...@googlegroups.com
Hi Siavash,

edX uses Django's built-in internationalization support, and this provides the gettext function. You can read about the JavaScript support here:


Unfortunately XBlock's don't currently support JavaScript i18n. See this JIRA ticket for details:


I hope this helps.

 - Andy


--
You received this message because you are subscribed to the Google Groups "General Open edX discussion" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/edx-code/fbc0ffa6-73b8-423c-a900-a04f105ba82b%40googlegroups.com.



--

Andy Armstrong

edX | UI Architect  | an...@edx.org  

141 Portland Street, 9th floor

Cambridge, MA 02139

http://www.edx.org

http://www.e-learn.nl/media/blogs/e-learn/edX_Logo_Col_RGB_FINAL.jpg?mtime=1336074566

Siavash Kavousi

unread,
Sep 19, 2016, 4:31:12 PM9/19/16
to General Open edX discussion
Thanks Andy,

But I can't see JIRA ticket... Is there any specific permission which I don't have?

Andy Armstrong

unread,
Sep 20, 2016, 2:41:15 PM9/20/16
to edx-...@googlegroups.com
Sorry about that. I've opened up the permissions on that ticket so you should be able to see it now.

 - Andy

On Mon, Sep 19, 2016 at 4:31 PM, Siavash Kavousi <siavash.k...@gmail.com> wrote:
Thanks Andy,

But I can't see JIRA ticket... Is there any specific permission which I don't have?

--
You received this message because you are subscribed to the Google Groups "General Open edX discussion" group.

Myles Fong

unread,
Oct 6, 2016, 6:12:03 AM10/6/16
to General Open edX discussion
Hi Andy,

I ran into the same problem and Google leads me here.

Can you also open the permission for me, too? I mean, for this https://openedx.atlassian.net/browse/WL-414.

Andy Armstrong

unread,
Oct 6, 2016, 9:09:40 AM10/6/16
to edx-...@googlegroups.com
Hi Myles,

You need to create a free JIRA/Confluence account to access our tickets. See this wiki page for details:


Thanks,

 - Andy

Juanan Pereira

unread,
Oct 6, 2016, 10:11:28 AM10/6/16
to edx-...@googlegroups.com

Hi Andy,

> You need to create a free JIRA/Confluence account to access our tickets. See this wiki page for details:

Same problem here. I have a JIRA account and I am logged-in, yet I can't see the bug description due to permission issues.

Greetings,

   Juanan

Screenshot_20161006-160804.png

Andy Armstrong

unread,
Oct 6, 2016, 10:44:07 AM10/6/16
to edx-...@googlegroups.com
Sorry for the misinformation. It seems that this ticket is within a JIRA project that is not open to the whole community. I've requested that a design document be made available.

In the meantime, here's the most recent proposal from Braden MacDonald:

As an XBlock developer, my ideal solution would look like this:

1. Some simple tool can scan my XBlock's code and extract strings for both python and JS and then output per-language files within my XBlock's python module directory, e.g. drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po and text_js.po
2. The XBlock JavaScript Runtime API (which provides e.g. the "runtime.handlerUrl(element, method)" method) should have three new methods: gettext(), ngettext(), and getLocale()
3. The runtime should guarantee that calls to gettext() and ngettext() are synchronous and non-blocking (i.e. that the appropriate strings .js file is optimistically loaded).
4. The runtime should provide a polyfill for the JavaScript Intl API (for Safari and mobile browsers)

Notes:

Re #2: It is important to implement all three methods - gettext is obvious, ngettext is very important, and getLocale() allows authors to use all rich, browser-native i18n formatting tools for dates, numbers, etc. For example, an XBlock in an accounting course can use

function myXBlock(runtime, element, args) {
    const locale = runtime.getLocale();
    // Format a currency amount like "USD $-1,234.56" in a locale-appropriate way, e.g. "-$1,234.56" for en-US or "-1.234,56\xa0$" for de-DE
    const amount = 1234.56;
    const usdAmountAsString = amount.toLocaleString(locale, {style: "currency", currency: "USD"});
    $(element).template(foo, {amtStr: usdAmountAsString});
}

In terms of LMS implementation, I think that at build time, the LMS static pipeline should scan for all installed XBlocks, and then build compressed .js string files - either:
1. a per-language file that combines the strings of all installed XBlocks (but keeps them separate, grouped by the python package name that contains them), or
2. a separate file per-language and per-XBlock-python-package. This is probably the only way to go for installations with lots of installed XBlocks like edx.org?

IMHO It is important to group the strings by python package and not by, say, block type or XBlock entry point, because some XBlocks consist of multiple related XBlocks within the same python package that will want to share strings.


--
You received this message because you are subscribed to the Google Groups "General Open edX discussion" group.
Reply all
Reply to author
Forward
0 new messages