Skip to content

django's gettext problem #69

Closed
Closed

Description

@sillygod

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 ?

Activity

  1. markfinger commented on Aug 12, 2016

    @markfinger
    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.

  2. markfinger commented on Feb 27, 2017

    @markfinger
    Owner

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions