Mercurial > xmpp-account-manager
annotate build_website.py @ 60:6d861d881b96
Add license headers to all source files.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 24 May 2020 13:09:16 +0200 |
parents | d5cfc04b9718 |
children | 46ca1aa08146 |
rev | line source |
---|---|
49 | 1 #!/usr/bin/env python3 |
2 '''Locale build script for XAM''' | |
3 | |
60
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
4 # SPDX-License-Identifier: AGPL-3.0-only |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
5 |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
6 # Copyright © 2017-2018 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
7 # Copyright © 2020 Mathieu Pasquet <mathieui@mathieui.net> |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
8 # |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
9 # Released under GNU AGPL v3 only, read the file 'LICENSE' for more information. |
6d861d881b96
Add license headers to all source files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
10 |
49 | 11 import sys |
12 from os import makedirs, path | |
13 from django.conf import settings | |
14 from shutil import copytree, copy | |
15 | |
16 AVAILABLE_LANGUAGES = ['en', 'fr'] | |
17 | |
18 | |
19 def make_messages(): | |
20 '''Extract translatable strings from the template.''' | |
21 | |
22 from django.core.management.commands import makemessages | |
23 | |
24 command = makemessages.Command() | |
25 command.stdout = sys.stdout | |
26 command.handle( | |
27 locale=AVAILABLE_LANGUAGES, exclude=[], domain='django', verbosity=True, | |
28 all=True, extensions=['xhtml', 'js'], symlinks=False, ignore_patterns=[], | |
29 use_default_ignore_patterns=True, no_wrap=True, no_location=True, | |
30 no_obsolete=True, keep_pot=True, add_location=False | |
31 ) | |
32 | |
33 | |
34 def compile_messages(): | |
35 '''For each locale we support, compile the po file into a mo.''' | |
36 | |
37 from django.core.management.commands import compilemessages | |
38 | |
39 command = compilemessages.Command() | |
40 command.verbosity = 1 | |
41 command.stdout = sys.stdout | |
42 command.compile_messages(('locale/%s/LC_MESSAGES' % lang, 'django.po') | |
43 for lang in AVAILABLE_LANGUAGES) | |
44 | |
45 | |
46 def main(): | |
47 '''Call everything in the correct order.''' | |
48 | |
49 from subprocess import call | |
50 | |
51 settings.configure() | |
52 make_messages() | |
53 compile_messages() | |
54 | |
55 for language in AVAILABLE_LANGUAGES: | |
56 call([sys.argv[0], language]) | |
57 | |
58 | |
59 def generate_pages(language): | |
60 '''Write a single page, and gzip it for lower network usage.''' | |
61 | |
62 assert language in AVAILABLE_LANGUAGES | |
63 target_dir = path.join('.', 'build', language) | |
64 makedirs(target_dir, exist_ok=True) | |
65 | |
66 import django | |
67 from django.template import Template, Context | |
68 import gzip | |
69 | |
70 settings.configure(LANGUAGE_CODE=language, LOCALE_PATHS=['locale'], TEMPLATES=[{'BACKEND': 'django.template.backends.django.DjangoTemplates'}]) | |
71 | |
72 django.setup() | |
73 | |
59
d5cfc04b9718
Remove prosody.svg.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
56
diff
changeset
|
74 static = ['share', 'prosody.css', 'spinner.svg', 'ok.svg', 'error.svg'] |
49 | 75 files = [ |
76 'index.xhtml', 'client.js', 'roster.js', 'avatar.js', 'client.js', 'index.xhtml', | |
77 'mam.js', 'nickname.js', 'pep.js', 'roster.js', 'strophe.js', 'strophe.mam.js', | |
78 'strophe.rsm.js', 'util.js', 'vcard.js' | |
79 ] | |
80 for file_to_localize in files: | |
81 with open(file_to_localize) as template_file: | |
56 | 82 template = Template('{% load i18n %}' + template_file.read()) |
49 | 83 rendered = template.render(Context({'AVAILABLE_LANGUAGES': |
84 AVAILABLE_LANGUAGES})) | |
85 filename = path.join(target_dir, file_to_localize) | |
86 with open(filename, 'w') as out: | |
87 out.write(rendered) | |
88 for static_resource in static: | |
89 if path.isdir(static_resource): | |
50
78f3f79c911b
mathieui: Add the CSS files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
49
diff
changeset
|
90 copytree(static_resource, path.join(target_dir, static_resource), dirs_exist_ok=True) |
49 | 91 else: |
92 copy(static_resource, target_dir) | |
93 | |
94 if __name__ == '__main__': | |
95 if len(sys.argv) == 1: | |
96 main() | |
97 else: | |
98 generate_pages(sys.argv[1]) |