Merge pull request #17471 from edx/efischer/sfe_use_i18n
provide data to SFE in DOM
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
<div id="root" class="SFE"></div>
|
||||
<%static:studiofrontend entry="accessibilityPolicy">
|
||||
{
|
||||
"lang": "${language_code | n, js_escaped_string}",
|
||||
"lang": "${language_code | n, js_escaped_string}"
|
||||
}
|
||||
</%static:studiofrontend>
|
||||
</div>
|
||||
|
||||
0
common/djangoapps/pipeline_mako/helpers/__init__.py
Normal file
0
common/djangoapps/pipeline_mako/helpers/__init__.py
Normal file
23
common/djangoapps/pipeline_mako/helpers/studiofrontend.py
Normal file
23
common/djangoapps/pipeline_mako/helpers/studiofrontend.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Contains code that gets run inside our mako template
|
||||
Debugging python-in-mako is terrible, so we've moved the actual code out to its own file
|
||||
"""
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def load_sfe_i18n_messages(locale):
|
||||
"""
|
||||
Loads i18n data from studio-frontend's published files.
|
||||
"""
|
||||
messages = "{}"
|
||||
|
||||
if locale != 'en':
|
||||
# because en is the default, studio-frontend will have it loaded by default
|
||||
messages_path = "{base}/studio-frontend/dist/i18n/messages/{locale}.json".format(
|
||||
base=settings.STATIC_ROOT_BASE,
|
||||
locale=locale.replace('-', '_') # files from Transifex use _, platform follows RFC-5646 and uses -
|
||||
)
|
||||
with open(messages_path) as inputfile:
|
||||
messages = inputfile.read()
|
||||
|
||||
return messages
|
||||
@@ -4,6 +4,7 @@ import logging
|
||||
import json
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from pipeline_mako import compressed_css, compressed_js
|
||||
from pipeline_mako.helpers.studiofrontend import load_sfe_i18n_messages
|
||||
from django.utils.translation import get_language_bidi
|
||||
from mako.exceptions import TemplateLookupException
|
||||
from edxmako.shortcuts import marketing_link
|
||||
@@ -93,17 +94,22 @@ source, template_path = Loader(engine).load_template_source(path)
|
||||
<%doc>
|
||||
Loads a studio-frontend page, with the necessary context. Context is expected
|
||||
as a dictionary in the body of this tag.
|
||||
|
||||
Dev note: we could also add the locale-injection script in this block
|
||||
-use a better default than the hardcoded 'en'. There should be a setting or something?
|
||||
-lookup (webpack exported) locale-injection script using lang as key
|
||||
-include it as the first script in this block
|
||||
</%doc>
|
||||
<%
|
||||
body = capture(caller.body)
|
||||
body_dict = json.loads(body)
|
||||
locale = body_dict['lang']
|
||||
|
||||
messages = load_sfe_i18n_messages(locale)
|
||||
%>
|
||||
<script type="text/javascript" id='courseContext'>
|
||||
var studioContext = ${ body | n, decode.utf8};
|
||||
<script type="application/json" id="SFE_i18n_data">
|
||||
{
|
||||
"locale": "${ locale | n, decode.utf8}",
|
||||
"messages": ${ messages | n, decode.utf8}
|
||||
}
|
||||
</script>
|
||||
<script type="application/javascript" id='courseContext'>
|
||||
var studioContext = ${ body | n, decode.utf8};
|
||||
</script>
|
||||
<div id="root" class="SFE"></div>
|
||||
% if settings.STUDIO_FRONTEND_CONTAINER_URL:
|
||||
|
||||
48
package-lock.json
generated
48
package-lock.json
generated
@@ -62,9 +62,9 @@
|
||||
}
|
||||
},
|
||||
"@edx/studio-frontend": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@edx/studio-frontend/-/studio-frontend-1.3.3.tgz",
|
||||
"integrity": "sha512-whYOzcpdwkPuKdsqu7zZAHbaOlSmezHXqq05cefvRsfzjcr/fL/iMdOXG5qRUUyVjUHqtwzrg0cHETlhj8X5RQ==",
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/@edx/studio-frontend/-/studio-frontend-1.3.4.tgz",
|
||||
"integrity": "sha512-oLbSHH4Brxrkj+EPFF6/J0dr+g4yFeiZzia5kwxrJ9OSz3Tdj3UhNvJuDkPSdpwkAsxeSaIZie/D2r1gOszDgA==",
|
||||
"requires": {
|
||||
"@edx/edx-bootstrap": "0.4.3",
|
||||
"@edx/paragon": "2.0.1",
|
||||
@@ -81,7 +81,7 @@
|
||||
"react-intl": "2.4.0",
|
||||
"react-intl-translations-manager": "5.0.1",
|
||||
"react-paginate": "5.1.0",
|
||||
"react-redux": "5.0.6",
|
||||
"react-redux": "5.0.7",
|
||||
"redux": "3.7.2",
|
||||
"redux-devtools-extension": "2.13.2",
|
||||
"redux-thunk": "2.2.0",
|
||||
@@ -481,18 +481,11 @@
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"attr-accept": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-1.1.1.tgz",
|
||||
"integrity": "sha512-s0iErRnsYv078cW2Iy2Ty+PGGQdvoztSe+OXbDYPpZ3bKXYxbNptTPt+NW89Dge/3lukNfr0tUgoFIgfmSYuiQ==",
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-1.1.2.tgz",
|
||||
"integrity": "sha512-NUj0itVSnpFkUYCj3XKSRCZ7N9gPwWcyX/tF7HosqyDBPMSygALivvJIGI8VvlPcunns5khMkpxoNshvmhy/ZQ==",
|
||||
"requires": {
|
||||
"core-js": "1.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.2.tgz",
|
||||
"integrity": "sha1-9F7t5SSFV5tgJsioYoRyufeWDK4="
|
||||
}
|
||||
"core-js": "2.5.3"
|
||||
}
|
||||
},
|
||||
"autoprefixer": {
|
||||
@@ -4459,9 +4452,9 @@
|
||||
"integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0="
|
||||
},
|
||||
"hoist-non-react-statics": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz",
|
||||
"integrity": "sha1-ND24TGAYxlB3iJgkATWhQg7iLOA="
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz",
|
||||
"integrity": "sha512-6Bl6XsDT1ntE0lHbIhr4Kp2PGcleGZ66qu5Jqk8lc0Xc/IeG6gVLmwUGs/K0Us+L8VWoKgj0uWdPMataOsm31w=="
|
||||
},
|
||||
"home-or-tmp": {
|
||||
"version": "2.0.0",
|
||||
@@ -8139,7 +8132,7 @@
|
||||
"resolved": "https://registry.npmjs.org/react-dropzone/-/react-dropzone-4.2.8.tgz",
|
||||
"integrity": "sha512-L/q6ySfhdG9Md3P21jFumzlm92TxRT0FtYX6G793Nf8bt7Fzpwx6gJsPk0idV094koj/Y5vRpp0q9+e0bdsjxw==",
|
||||
"requires": {
|
||||
"attr-accept": "1.1.1",
|
||||
"attr-accept": "1.1.2",
|
||||
"prop-types": "15.6.0"
|
||||
}
|
||||
},
|
||||
@@ -8219,16 +8212,23 @@
|
||||
"integrity": "sha1-acLVdB5t9eCPIw82u8KUTuEiJVU="
|
||||
},
|
||||
"react-redux": {
|
||||
"version": "5.0.6",
|
||||
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-5.0.6.tgz",
|
||||
"integrity": "sha512-8taaaGu+J7PMJQDJrk/xiWEYQmdo3mkXw6wPr3K3LxvXis3Fymiq7c13S+Tpls/AyNUAsoONkU81AP0RA6y6Vw==",
|
||||
"version": "5.0.7",
|
||||
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-5.0.7.tgz",
|
||||
"integrity": "sha512-5VI8EV5hdgNgyjfmWzBbdrqUkrVRKlyTKk1sGH3jzM2M2Mhj/seQgPXaz6gVAj2lz/nz688AdTqMO18Lr24Zhg==",
|
||||
"requires": {
|
||||
"hoist-non-react-statics": "2.3.1",
|
||||
"hoist-non-react-statics": "2.5.0",
|
||||
"invariant": "2.2.2",
|
||||
"lodash": "4.17.4",
|
||||
"lodash": "4.17.5",
|
||||
"lodash-es": "4.17.5",
|
||||
"loose-envify": "1.3.1",
|
||||
"prop-types": "15.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": {
|
||||
"version": "4.17.5",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
|
||||
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"react-slick": {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"dependencies": {
|
||||
"@edx/edx-bootstrap": "0.4.3",
|
||||
"@edx/paragon": "1.7.1",
|
||||
"@edx/studio-frontend": "1.3.3",
|
||||
"@edx/studio-frontend": "1.3.4",
|
||||
"babel-core": "6.26.0",
|
||||
"babel-loader": "6.4.1",
|
||||
"babel-plugin-transform-class-properties": "6.24.1",
|
||||
|
||||
Reference in New Issue
Block a user