Export JS translation files as static files

This commit is contained in:
Yohann D'ANELLO 2020-11-16 00:29:27 +01:00
parent 23243e09bb
commit b9d49d53f2
10 changed files with 156 additions and 15 deletions

View File

@ -272,12 +272,13 @@ Il faut penser à ignorer les dossiers ne contenant pas notre code, dont le virt
De plus, il faut aussi extraire les variables des fichiers JavaScript. De plus, il faut aussi extraire les variables des fichiers JavaScript.
```bash ```bash
django-admin makemessages -i env python3 manage.py makemessages -i env
django-admin makemessages -i env -e js -d djangojs python3 manage.py makemessages -i env -e js -d djangojs
``` ```
Une fois les fichiers édités, vous pouvez compiler les nouvelles traductions avec Une fois les fichiers édités, vous pouvez compiler les nouvelles traductions avec
```bash ```bash
django-admin compilemessages python3 manage.py compilemessages
python3 manage.py compilejsmessages
``` ```

View File

@ -1,4 +1,10 @@
--- ---
- name: Collect static files
command: /var/www/note_kfet/env/bin/python manage.py collectstatic --noinput
args:
chdir: /var/www/note_kfet
become_user: www-data
- name: Migrate Django database - name: Migrate Django database
command: /var/www/note_kfet/env/bin/python manage.py migrate command: /var/www/note_kfet/env/bin/python manage.py migrate
args: args:
@ -11,14 +17,14 @@
chdir: /var/www/note_kfet chdir: /var/www/note_kfet
become_user: www-data become_user: www-data
- name: Compile JavaScript messages
command: /var/www/note_kfet/env/bin/python manage.py compilejsmessages
args:
chdir: /var/www/note_kfet
become_user: www-data
- name: Install initial fixtures - name: Install initial fixtures
command: /var/www/note_kfet/env/bin/python manage.py loaddata initial command: /var/www/note_kfet/env/bin/python manage.py loaddata initial
args: args:
chdir: /var/www/note_kfet chdir: /var/www/note_kfet
become_user: postgres become_user: postgres
- name: Collect static files
command: /var/www/note_kfet/env/bin/python manage.py collectstatic --noinput
args:
chdir: /var/www/note_kfet
become_user: www-data

@ -1 +1 @@
Subproject commit 7e27c3b71b04af0867d5fbe4916e2d1278637599 Subproject commit dbe7bf65917df40b0ce476f357d04726e20b406f

View File

@ -14,6 +14,7 @@ fi
# Set up Django project # Set up Django project
python3 manage.py collectstatic --noinput python3 manage.py collectstatic --noinput
python3 manage.py compilemessages python3 manage.py compilemessages
python3 manage.py compilejsmessages
python3 manage.py migrate python3 manage.py migrate
if [ "$1" ]; then if [ "$1" ]; then

View File

@ -0,0 +1,134 @@
/*
* You should never see this file.
* It is here only for compatibility reasons in case of the command `compilejsmessages` was never executed.
* Please execute this command to generate translation strings.
*/
(function(globals) {
var django = globals.django || (globals.django = {});
django.pluralidx = function(n) {
var v=(n != 1);
if (typeof(v) == 'boolean') {
return v ? 1 : 0;
} else {
return v;
}
};
/* gettext library */
django.catalog = django.catalog || {};
if (!django.jsi18n_initialized) {
django.gettext = function(msgid) {
var value = django.catalog[msgid];
if (typeof(value) == 'undefined') {
return msgid;
} else {
return (typeof(value) == 'string') ? value : value[0];
}
};
django.ngettext = function(singular, plural, count) {
var value = django.catalog[singular];
if (typeof(value) == 'undefined') {
return (count == 1) ? singular : plural;
} else {
return value.constructor === Array ? value[django.pluralidx(count)] : value;
}
};
django.gettext_noop = function(msgid) { return msgid; };
django.pgettext = function(context, msgid) {
var value = django.gettext(context + '\x04' + msgid);
if (value.indexOf('\x04') != -1) {
value = msgid;
}
return value;
};
django.npgettext = function(context, singular, plural, count) {
var value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count);
if (value.indexOf('\x04') != -1) {
value = django.ngettext(singular, plural, count);
}
return value;
};
django.interpolate = function(fmt, obj, named) {
if (named) {
return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
} else {
return fmt.replace(/%s/g, function(match){return String(obj.shift())});
}
};
/* formatting library */
django.formats = {
"DATETIME_FORMAT": "j \\d\\e F \\d\\e Y \\a \\l\\a\\s H:i",
"DATETIME_INPUT_FORMATS": [
"%d/%m/%Y %H:%M:%S",
"%d/%m/%Y %H:%M:%S.%f",
"%d/%m/%Y %H:%M",
"%d/%m/%y %H:%M:%S",
"%d/%m/%y %H:%M:%S.%f",
"%d/%m/%y %H:%M",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %H:%M:%S.%f",
"%Y-%m-%d %H:%M",
"%Y-%m-%d"
],
"DATE_FORMAT": "j \\d\\e F \\d\\e Y",
"DATE_INPUT_FORMATS": [
"%d/%m/%Y",
"%d/%m/%y",
"%Y-%m-%d"
],
"DECIMAL_SEPARATOR": ",",
"FIRST_DAY_OF_WEEK": 1,
"MONTH_DAY_FORMAT": "j \\d\\e F",
"NUMBER_GROUPING": 3,
"SHORT_DATETIME_FORMAT": "d/m/Y H:i",
"SHORT_DATE_FORMAT": "d/m/Y",
"THOUSAND_SEPARATOR": ".",
"TIME_FORMAT": "H:i",
"TIME_INPUT_FORMATS": [
"%H:%M:%S",
"%H:%M:%S.%f",
"%H:%M"
],
"YEAR_MONTH_FORMAT": "F \\d\\e Y"
};
django.get_format = function(format_type) {
var value = django.formats[format_type];
if (typeof(value) == 'undefined') {
return format_type;
} else {
return value;
}
};
/* add to global namespace */
globals.pluralidx = django.pluralidx;
globals.gettext = django.gettext;
globals.ngettext = django.ngettext;
globals.gettext_noop = django.gettext_noop;
globals.pgettext = django.pgettext;
globals.npgettext = django.npgettext;
globals.interpolate = django.interpolate;
globals.get_format = django.get_format;
django.jsi18n_initialized = true;
}
}(this));

View File

@ -0,0 +1 @@
_default.js

View File

@ -0,0 +1 @@
_default.js

View File

@ -0,0 +1 @@
_default.js

View File

@ -39,7 +39,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<script src="{% static "js/konami.js" %}"></script> <script src="{% static "js/konami.js" %}"></script>
{# Translation in javascript files #} {# Translation in javascript files #}
<script src="{% url "javascript-catalog" %}"></script> <script src="{% static "js/jsi18n/jsi18n."|add:LANGUAGE_CODE|add:".js" %}"></script>
{# If extra ressources are needed for a form, load here #} {# If extra ressources are needed for a form, load here #}
{% if form.media %} {% if form.media %}

View File

@ -6,7 +6,6 @@ from django.conf.urls.static import static
from django.urls import path, include from django.urls import path, include
from django.views.defaults import bad_request, permission_denied, page_not_found, server_error from django.views.defaults import bad_request, permission_denied, page_not_found, server_error
from django.views.generic import RedirectView from django.views.generic import RedirectView
from django.views.i18n import JavaScriptCatalog
from member.views import CustomLoginView from member.views import CustomLoginView
@ -35,9 +34,6 @@ urlpatterns = [
# Make coffee # Make coffee
path('coffee/', include('django_htcpcp_tea.urls')), path('coffee/', include('django_htcpcp_tea.urls')),
# Translate js
path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'),
] ]
# During development, serve media files # During development, serve media files