Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18n Internationalization and Localization in React Django

I am working on a Project where I am using React js for Front-End and Django for backend. I need to implement i18n Internationalization and Localization I saw Django documentation and came across django I18n javascript_catalog. How to use the same using getText() in React JS?. Is there any other way to implement?.

Thanks in Advance

like image 238
Ajaykumar Avatar asked Jun 14 '17 04:06

Ajaykumar


1 Answers

Update for: django > 2.0:

from django.views.i18n import JavaScriptCatalog

urlpatterns = [
    path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
]

Reference

Old:

Use below code in urls.py of project

from django.views.i18n import javascript_catalog
js_info_dict = {
    'domain': 'djangojs',
    'packages': ('name',)
}


urlpatterns += i18n_patterns(
    url(r'^jsi18n/$', javascript_catalog, js_info_dict),

Add below line to your base html file

<script type="text/javascript" src="/jsi18n/"></script>
like image 103
Neeraj Kumar Avatar answered Sep 19 '22 11:09

Neeraj Kumar