Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django's gettext problem #69

Closed
sillygod opened this issue Aug 12, 2016 · 2 comments
Closed

django's gettext problem #69

sillygod opened this issue Aug 12, 2016 · 2 comments

Comments

@sillygod
Copy link

how to resolve the problem gettext is not defined.

an example base template file

<html lang='zh-TW'>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1.0, width=device-width, height=device-height " />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}"></script>
    {% block extra_content %} {% endblock %} {% block js %} {% endblock %}
</head>
<body>
    <div id="now_lang" style="display: none">{{ LANG }}</div>
    {% csrf_token %}
    {% block content %}{% endblock %}
</body>
</html>

by add this <script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}"></script>, I can call gettext in my jsx file. However, the render server will not know what gettext is.

Is there any solution for this situation ?

@markfinger
Copy link
Owner

You'll need a way to pass that data to the renderer.

I'm not too familiar with internationalisation in django, but I assume you can interrogate the request for a lang and then dump all the data used for gettext, so you can pass it to renderer. If you're not too familiar with how to implement the interrogation, I'd recommend looking at the implementation details for django.views.i18n.javascript_catalog.

Note that once you're handling data like this, you'll probably need different entry points for your code so that you can handle the different contexts. It's a bit of a pain sometimes, but it does have the benefit that your system will end up less coupled to django's front-end.

@markfinger
Copy link
Owner

markfinger commented Feb 27, 2017

I've linked this question from the README. https://github.com/markfinger/python-react/blob/master/README.md#how-do-i-handle-djangos-translation-and-gettext-with-react-components

Everyone should feel free to continue the discussion if they're so inclined

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

No branches or pull requests

2 participants