7

I'm using Django 1.9, React and webpack, I used externals to load the django I18n functions such as gettext in my javascript files.

This is loaded like this from a view :

<script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}/0"></script>

Here is my webpack config :

externals: {
    // require("jquery") is external and available
    //  on the global var jQuery
    "jquery": "jQuery",
    "utils": "utils",
    "gettext":"gettext",
    "django":"django",//I18n functions are encapsulated in the django object

    },

In my jsx files I load gettext like this :

import {gettext, interpolate, ngettext} from 'django'

render(){
var login_header_text = gettext("blablabla.");
....

Actually almost everything works, when I use django-admin makemessages -d djangojs -l it recovers many gettext, however some gettext are ignored by the script so sometime I have to put the gettext at the beginning of my render function and then it works..., I don't know why this is happening.

In the end with my technic I can make it work totally but maybe I did something wrong. Maybe I should generate mo file with grunt and load it dynamically with po loader with webpack because I will need soon to load them dyamically into the page.

Maybe you can guide me a bit ? Thanks

minglyu
  • 2,958
  • 2
  • 13
  • 32
Alex
  • 487
  • 1
  • 6
  • 16
  • I need to implement django I18n javascript_catalog with react js in my project. Is it working fine?. What configurations I need to make?. Can you help me out regarding this?. Thanks in Advance – Ajaykumar Jun 14 '17 at 03:38

0 Answers0