Django provides a specific solution to handle this:
https://docs.djangoproject.com/en/2.2/topics/i18n/translation/#module-django.views.i18n
but when the number of messages used in js code which need translation is limited,
as commonly happens, I prefer to use a much simpler solution.
First, I create a "js message catalog" in the "templates" folder;
it just contains a list of global string literals.
Since the template engine isn't restricted to HTML, and can handle any file type,
you can {% load i18n %} at the beginning of the js file, and make use of 'trans' and other template tags as required to mark translatable string values; these values will be detected by "makemessages" as expected.
file "/myapp/templates/message_catalog.js"
{% load i18n %}
MESSAGE_HELLO = "{% trans 'hello' %}";
MESSAGE_GOODBYE = "{% trans 'goodbye' %}";
...
Then, just remember to include it in the main template, so the message catalog will
be accessible from js code:
file "/myapp/templates/base.html"
...
<script>
{% include 'message_catalog.js' %}
</script>
</body>
</html>
The 'real' js code can live in static as usual, and still has access to translated messages:
file "/myapp/static/frontend.js"
function hello() {
alert(MESSAGE_HELLO);
}
function goodbye() {
alert(MESSAGE_GOODBYE);
}