# HG changeset patch # User mathieui # Date 1590258818 -7200 # Node ID d3b943ac148fad39bd72c1100ae4614966c605e0 # Parent 021185105e2fd1d4dfd3ca0831fbfd87a8f85a3c Add translations Build script + {% trans %} in index.html diff --git a/build_website.py b/build_website.py new file mode 100644 --- /dev/null +++ b/build_website.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +'''Locale build script for XAM''' + +import sys +from os import makedirs, path +from django.conf import settings +from shutil import copytree, copy + +AVAILABLE_LANGUAGES = ['en', 'fr'] + + +def make_messages(): + '''Extract translatable strings from the template.''' + + from django.core.management.commands import makemessages + + command = makemessages.Command() + command.stdout = sys.stdout + command.handle( + locale=AVAILABLE_LANGUAGES, exclude=[], domain='django', verbosity=True, + all=True, extensions=['xhtml', 'js'], symlinks=False, ignore_patterns=[], + use_default_ignore_patterns=True, no_wrap=True, no_location=True, + no_obsolete=True, keep_pot=True, add_location=False + ) + + +def compile_messages(): + '''For each locale we support, compile the po file into a mo.''' + + from django.core.management.commands import compilemessages + + command = compilemessages.Command() + command.verbosity = 1 + command.stdout = sys.stdout + command.compile_messages(('locale/%s/LC_MESSAGES' % lang, 'django.po') + for lang in AVAILABLE_LANGUAGES) + + +def main(): + '''Call everything in the correct order.''' + + from subprocess import call + + settings.configure() + make_messages() + compile_messages() + + for language in AVAILABLE_LANGUAGES: + call([sys.argv[0], language]) + + +def generate_pages(language): + '''Write a single page, and gzip it for lower network usage.''' + + assert language in AVAILABLE_LANGUAGES + target_dir = path.join('.', 'build', language) + makedirs(target_dir, exist_ok=True) + + import django + from django.template import Template, Context + import gzip + + settings.configure(LANGUAGE_CODE=language, LOCALE_PATHS=['locale'], TEMPLATES=[{'BACKEND': 'django.template.backends.django.DjangoTemplates'}]) + + django.setup() + + static = ['share', 'prosody.css', 'prosody.svg', 'spinner.svg', 'ok.svg', 'error.svg'] + files = [ + 'index.xhtml', 'client.js', 'roster.js', 'avatar.js', 'client.js', 'index.xhtml', + 'mam.js', 'nickname.js', 'pep.js', 'roster.js', 'strophe.js', 'strophe.mam.js', + 'strophe.rsm.js', 'util.js', 'vcard.js' + ] + for file_to_localize in files: + with open(file_to_localize) as template_file: + template = Template(template_file.read()) + rendered = template.render(Context({'AVAILABLE_LANGUAGES': + AVAILABLE_LANGUAGES})) + filename = path.join(target_dir, file_to_localize) + with open(filename, 'w') as out: + out.write(rendered) + for static_resource in static: + if path.isdir(static_resource): + copytree(static_resource, target_dir, dirs_exist_ok=True) + else: + copy(static_resource, target_dir) + +if __name__ == '__main__': + if len(sys.argv) == 1: + main() + else: + generate_pages(sys.argv[1]) diff --git a/index.xhtml b/index.xhtml --- a/index.xhtml +++ b/index.xhtml @@ -1,9 +1,9 @@ - +
-- +
-Enter your nickname, so people you know can recognize you.
+{% trans 'Enter your nickname, so people you know can recognize you.' %}
- +
This image allows your contacts to quickly identify you.
+{% trans 'This image allows your contacts to quickly identify you.' %}
- - - + + +
- +
Who are you?
+{% trans 'Who are you?' %}
-
-
+
-This can be used if you forget your password.
+{% trans 'This can be used if you forget your password.' %}
-
+
-
+
JID | Name | Subscription | Groups | ⚠️ Delete |
---|---|---|---|---|
{% trans 'JID' %} | {% trans 'Name' %} | {% trans 'Subscription' %} | {% trans 'Groups' %} | {% trans '⚠️ Delete' %} |
- - + +
PEP node | Title | Description | Type | ⚠️ Delete |
---|---|---|---|---|
{% trans 'PEP node' %} | {% trans 'Title' %} | {% trans 'Description' %} | {% trans 'Type' %} | {% trans '⚠️ Delete' %} |
-
+
-
-
Always:
-Never:
+{% trans 'Always:' %}
+{% trans 'Never:' %}
-
-
-
+
+
+
+