简体   繁体   中英

django: part of javascript translation doesnot work

here is my code:

 var text = `<div id='weather_data'>
            <img id='weather_icon' src='${weather_icon}'>
            <span id='centered'>${data[0].temperature}°c</span>
            </div>
            <h2>Steps:</h2>
            <ul id='journey_info'>`;

and

 text +=
                "<li>" +
                gettext(" Start from: ") +
                "<br>" +
                data[i].start_name +
                "<br>" +
                "<br>" +
                gettext(" Line ID: ") +
                line_id +
                "<br>" +
                "<br>" +
                gettext(" Departs at: ") +
                getTime(data, i) +
                `<div id='arrival_${stop_id}'></div>` +
                "<br>" +
                gettext(" Arrives to: ") +
                "<br>" +
                data[i].end_name +
                "<br>" +
                "<br>" +
                gettext(" Stops: ") +
                data[i].num_stops +
                " • " +
                data[i].travel_time +
                "mins <span id='arrow'>&#9660</span>" +
                "<div id='directions_stops_list'>";

in my djangojs.po file, there are only:

#: .\static\javascript\modals.js:49
msgid " Arrives to: "
msgstr " 到达:"

#: .\static\javascript\modals.js:54
msgid " Stops: "
msgstr "站点:"

so part of gettext are found by django. but Why can't it read: gettext(" Start from: "),gettext(" Line ID: ") and gettext(" Departs at: ")?

Notice: any code between var text = and `<div id='arrival_${stop_id}'></div>` + couldnot be recognized by gettext .

Sorry but it all works for me:

#: templates/modal.js:9
msgid " Start from: "
msgstr ""

#: templates/modal.js:14
msgid " Line ID: "
msgstr ""

#: templates/modal.js:18
msgid " Departs at: "
msgstr ""

#: templates/modal.js:22
msgid " Arrives to: "
msgstr ""

#: templates/modal.js:27
msgid " Stops: "
msgstr ""

But since we're missing ~27 lines, you should simply delete one statement at a time from the top, till it starts working. There's something that Django trips over and until you identify it, there's not much we can do to help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM