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;








1















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.










share|improve this question




























    1















    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.










    share|improve this question
























      1












      1








      1








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 9 '17 at 19:08









      ALUWALUW

      104114




      104114






















          2 Answers
          2






          active

          oldest

          votes


















          0














          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.






          share|improve this answer























          • 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











          • 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











          • 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


















          0














          <script src="/jsi18n/"></script> 


          add this before jquery block. Hope this might help






          share|improve this answer























            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            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.






            share|improve this answer























            • 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











            • 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











            • 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















            0














            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.






            share|improve this answer























            • 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











            • 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











            • 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













            0












            0








            0







            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.






            share|improve this answer













            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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 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











            • 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

















            • 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











            • 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











            • 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













            0














            <script src="/jsi18n/"></script> 


            add this before jquery block. Hope this might help






            share|improve this answer



























              0














              <script src="/jsi18n/"></script> 


              add this before jquery block. Hope this might help






              share|improve this answer

























                0












                0








                0







                <script src="/jsi18n/"></script> 


                add this before jquery block. Hope this might help






                share|improve this answer













                <script src="/jsi18n/"></script> 


                add this before jquery block. Hope this might help







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 6:32









                prabakar.pyprabakar.py

                135




                135



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현