Django JavaScript Translation gettext is not defined The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceCreate GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
Semisimplicity of the category of coherent sheaves?
What aspect of planet Earth must be changed to prevent the industrial revolution?
Does Parliament hold absolute power in the UK?
Why can't devices on different VLANs, but on the same subnet, communicate?
Is this wall load bearing? Blueprints and photos attached
How do I add random spotting to the same face in cycles?
Is every episode of "Where are my Pants?" identical?
First use of “packing” as in carrying a gun
Is there a writing software that you can sort scenes like slides in PowerPoint?
"... to apply for a visa" or "... and applied for a visa"?
How many people can fit inside Mordenkainen's Magnificent Mansion?
The variadic template constructor of my class cannot modify my class members, why is that so?
Why does the Event Horizon Telescope (EHT) not include telescopes from Africa, Asia or Australia?
How should I replace vector<uint8_t>::const_iterator in an API?
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Finding the path in a graph from A to B then back to A with a minimum of shared edges
What is special about square numbers here?
How did passengers keep warm on sail ships?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
Can the prologue be the backstory of your main character?
What do you call a plan that's an alternative plan in case your initial plan fails?
Simulating Exploding Dice
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Django JavaScript Translation gettext is not defined
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceCreate GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
My javascript function contains the following:
document.getElementById("example").innerHTML = gettext("This is an example");
My urls.py looks like:
urlpatterns = [
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^admin/', admin.site.urls),
url(r'^', include('project.urls')),
url(r'^login/$', auth_views.login, 'template_name': 'login.html', 'authentication_form': LoginForm, name = 'login'),
url(r'^logout/$', auth_views.logout, 'next_page': '/login'),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
And in my template I have:
<script type="text/javascript" src="% url 'javascript-catalog' %"></script>
The translation above using gettext() does not work. A Reference Error comes up saying gettext() is not defined. However, in the same javascript file i have:
var monthNames = [gettext("January"), gettext("February"), gettext("March"), gettext("April"), gettext("May"), gettext("June"), gettext("July"), gettext("August"), gettext("September"), gettext("October"), gettext("November"), gettext("December")];
And that does not prompt a reference error. The month translations work but the example one does not.
javascript django
add a comment |
My javascript function contains the following:
document.getElementById("example").innerHTML = gettext("This is an example");
My urls.py looks like:
urlpatterns = [
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^admin/', admin.site.urls),
url(r'^', include('project.urls')),
url(r'^login/$', auth_views.login, 'template_name': 'login.html', 'authentication_form': LoginForm, name = 'login'),
url(r'^logout/$', auth_views.logout, 'next_page': '/login'),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
And in my template I have:
<script type="text/javascript" src="% url 'javascript-catalog' %"></script>
The translation above using gettext() does not work. A Reference Error comes up saying gettext() is not defined. However, in the same javascript file i have:
var monthNames = [gettext("January"), gettext("February"), gettext("March"), gettext("April"), gettext("May"), gettext("June"), gettext("July"), gettext("August"), gettext("September"), gettext("October"), gettext("November"), gettext("December")];
And that does not prompt a reference error. The month translations work but the example one does not.
javascript django
add a comment |
My javascript function contains the following:
document.getElementById("example").innerHTML = gettext("This is an example");
My urls.py looks like:
urlpatterns = [
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^admin/', admin.site.urls),
url(r'^', include('project.urls')),
url(r'^login/$', auth_views.login, 'template_name': 'login.html', 'authentication_form': LoginForm, name = 'login'),
url(r'^logout/$', auth_views.logout, 'next_page': '/login'),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
And in my template I have:
<script type="text/javascript" src="% url 'javascript-catalog' %"></script>
The translation above using gettext() does not work. A Reference Error comes up saying gettext() is not defined. However, in the same javascript file i have:
var monthNames = [gettext("January"), gettext("February"), gettext("March"), gettext("April"), gettext("May"), gettext("June"), gettext("July"), gettext("August"), gettext("September"), gettext("October"), gettext("November"), gettext("December")];
And that does not prompt a reference error. The month translations work but the example one does not.
javascript django
My javascript function contains the following:
document.getElementById("example").innerHTML = gettext("This is an example");
My urls.py looks like:
urlpatterns = [
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^admin/', admin.site.urls),
url(r'^', include('project.urls')),
url(r'^login/$', auth_views.login, 'template_name': 'login.html', 'authentication_form': LoginForm, name = 'login'),
url(r'^logout/$', auth_views.logout, 'next_page': '/login'),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
And in my template I have:
<script type="text/javascript" src="% url 'javascript-catalog' %"></script>
The translation above using gettext() does not work. A Reference Error comes up saying gettext() is not defined. However, in the same javascript file i have:
var monthNames = [gettext("January"), gettext("February"), gettext("March"), gettext("April"), gettext("May"), gettext("June"), gettext("July"), gettext("August"), gettext("September"), gettext("October"), gettext("November"), gettext("December")];
And that does not prompt a reference error. The month translations work but the example one does not.
javascript django
javascript django
asked Mar 9 '17 at 19:08
ALUWALUW
104114
104114
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I am not sure, but try checking the order of your script. See, if you are using the gettext() function for the example above before the script tag where you load the javascript-catalog.
Good catch! But it didn't solve the issue. The error still comes up. Thanks though!
– ALUW
Mar 9 '17 at 19:25
Check if other gettext() functions calls don't throw ReferenceError by removing thedocument.getElementById("example").innerHTML = gettext("This is an example");
line. If they work fine, then most probably, it is some issue of the script loading later after your function call or any other scope issue.
– Kishu Agarwal
Mar 9 '17 at 19:35
Changing where the script is called doesn't do anything. The same error is still there
– ALUW
Mar 9 '17 at 21:01
Can you show more of your code, how are you calling the gettext() function in theexample
case above?
– Kishu Agarwal
Mar 10 '17 at 5:27
What I wrote above is how I call it. Those are the only two times that i use it. So I'm not sure what other code to share.
– ALUW
Mar 10 '17 at 13:35
|
show 2 more comments
<script src="/jsi18n/"></script>
add this before jquery block. Hope this might help
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42703529%2fdjango-javascript-translation-gettext-is-not-defined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am not sure, but try checking the order of your script. See, if you are using the gettext() function for the example above before the script tag where you load the javascript-catalog.
Good catch! But it didn't solve the issue. The error still comes up. Thanks though!
– ALUW
Mar 9 '17 at 19:25
Check if other gettext() functions calls don't throw ReferenceError by removing thedocument.getElementById("example").innerHTML = gettext("This is an example");
line. If they work fine, then most probably, it is some issue of the script loading later after your function call or any other scope issue.
– Kishu Agarwal
Mar 9 '17 at 19:35
Changing where the script is called doesn't do anything. The same error is still there
– ALUW
Mar 9 '17 at 21:01
Can you show more of your code, how are you calling the gettext() function in theexample
case above?
– Kishu Agarwal
Mar 10 '17 at 5:27
What I wrote above is how I call it. Those are the only two times that i use it. So I'm not sure what other code to share.
– ALUW
Mar 10 '17 at 13:35
|
show 2 more comments
I am not sure, but try checking the order of your script. See, if you are using the gettext() function for the example above before the script tag where you load the javascript-catalog.
Good catch! But it didn't solve the issue. The error still comes up. Thanks though!
– ALUW
Mar 9 '17 at 19:25
Check if other gettext() functions calls don't throw ReferenceError by removing thedocument.getElementById("example").innerHTML = gettext("This is an example");
line. If they work fine, then most probably, it is some issue of the script loading later after your function call or any other scope issue.
– Kishu Agarwal
Mar 9 '17 at 19:35
Changing where the script is called doesn't do anything. The same error is still there
– ALUW
Mar 9 '17 at 21:01
Can you show more of your code, how are you calling the gettext() function in theexample
case above?
– Kishu Agarwal
Mar 10 '17 at 5:27
What I wrote above is how I call it. Those are the only two times that i use it. So I'm not sure what other code to share.
– ALUW
Mar 10 '17 at 13:35
|
show 2 more comments
I am not sure, but try checking the order of your script. See, if you are using the gettext() function for the example above before the script tag where you load the javascript-catalog.
I am not sure, but try checking the order of your script. See, if you are using the gettext() function for the example above before the script tag where you load the javascript-catalog.
answered Mar 9 '17 at 19:18
Kishu AgarwalKishu Agarwal
12826
12826
Good catch! But it didn't solve the issue. The error still comes up. Thanks though!
– ALUW
Mar 9 '17 at 19:25
Check if other gettext() functions calls don't throw ReferenceError by removing thedocument.getElementById("example").innerHTML = gettext("This is an example");
line. If they work fine, then most probably, it is some issue of the script loading later after your function call or any other scope issue.
– Kishu Agarwal
Mar 9 '17 at 19:35
Changing where the script is called doesn't do anything. The same error is still there
– ALUW
Mar 9 '17 at 21:01
Can you show more of your code, how are you calling the gettext() function in theexample
case above?
– Kishu Agarwal
Mar 10 '17 at 5:27
What I wrote above is how I call it. Those are the only two times that i use it. So I'm not sure what other code to share.
– ALUW
Mar 10 '17 at 13:35
|
show 2 more comments
Good catch! But it didn't solve the issue. The error still comes up. Thanks though!
– ALUW
Mar 9 '17 at 19:25
Check if other gettext() functions calls don't throw ReferenceError by removing thedocument.getElementById("example").innerHTML = gettext("This is an example");
line. If they work fine, then most probably, it is some issue of the script loading later after your function call or any other scope issue.
– Kishu Agarwal
Mar 9 '17 at 19:35
Changing where the script is called doesn't do anything. The same error is still there
– ALUW
Mar 9 '17 at 21:01
Can you show more of your code, how are you calling the gettext() function in theexample
case above?
– Kishu Agarwal
Mar 10 '17 at 5:27
What I wrote above is how I call it. Those are the only two times that i use it. So I'm not sure what other code to share.
– ALUW
Mar 10 '17 at 13:35
Good catch! But it didn't solve the issue. The error still comes up. Thanks though!
– ALUW
Mar 9 '17 at 19:25
Good catch! But it didn't solve the issue. The error still comes up. Thanks though!
– ALUW
Mar 9 '17 at 19:25
Check if other gettext() functions calls don't throw ReferenceError by removing the
document.getElementById("example").innerHTML = gettext("This is an example");
line. If they work fine, then most probably, it is some issue of the script loading later after your function call or any other scope issue.– Kishu Agarwal
Mar 9 '17 at 19:35
Check if other gettext() functions calls don't throw ReferenceError by removing the
document.getElementById("example").innerHTML = gettext("This is an example");
line. If they work fine, then most probably, it is some issue of the script loading later after your function call or any other scope issue.– Kishu Agarwal
Mar 9 '17 at 19:35
Changing where the script is called doesn't do anything. The same error is still there
– ALUW
Mar 9 '17 at 21:01
Changing where the script is called doesn't do anything. The same error is still there
– ALUW
Mar 9 '17 at 21:01
Can you show more of your code, how are you calling the gettext() function in the
example
case above?– Kishu Agarwal
Mar 10 '17 at 5:27
Can you show more of your code, how are you calling the gettext() function in the
example
case above?– Kishu Agarwal
Mar 10 '17 at 5:27
What I wrote above is how I call it. Those are the only two times that i use it. So I'm not sure what other code to share.
– ALUW
Mar 10 '17 at 13:35
What I wrote above is how I call it. Those are the only two times that i use it. So I'm not sure what other code to share.
– ALUW
Mar 10 '17 at 13:35
|
show 2 more comments
<script src="/jsi18n/"></script>
add this before jquery block. Hope this might help
add a comment |
<script src="/jsi18n/"></script>
add this before jquery block. Hope this might help
add a comment |
<script src="/jsi18n/"></script>
add this before jquery block. Hope this might help
<script src="/jsi18n/"></script>
add this before jquery block. Hope this might help
answered Mar 22 at 6:32
prabakar.pyprabakar.py
135
135
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42703529%2fdjango-javascript-translation-gettext-is-not-defined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown