annotate build_website.py @ 3:677c11228f33 default tip

Update Spanish translation’s fuzzy translations.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 07 Sep 2017 16:45:37 +0100
parents 0994ae3e4518
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 #!/usr/bin/env python3
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 '''Supervision script for PyTouhou’s website.'''
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 import sys
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 from django.conf import settings
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 AVAILABLE_LANGUAGES = ['de', 'en', 'es', 'fr', 'fi', 'it', 'pt']
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 def make_messages():
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 '''Extract translatable strings from the template.'''
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 from django.core.management.commands import makemessages
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 command = makemessages.Command()
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 command.stdout = sys.stdout
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 #command.handle(verbosity=True, ignore_patterns=[], domain='django', exclude=[], extensions=['xhtml'], locale=AVAILABLE_LANGUAGES, keep_pot=True)
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 command.handle(locale=AVAILABLE_LANGUAGES, exclude=[], domain='django', verbosity=True, all=True, extensions=['xhtml'], symlinks=False, ignore_patterns=[], use_default_ignore_patterns=True, no_wrap=True, no_location=True, no_obsolete=True, keep_pot=True)
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 def compile_messages():
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 '''For each locale we support, compile the po file into a mo.'''
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 from django.core.management.commands import compilemessages
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 command = compilemessages.Command()
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 command.verbosity = 1
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 command.stdout = sys.stdout
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 command.compile_messages(('locale/%s/LC_MESSAGES' % lang, 'django.po')
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 for lang in AVAILABLE_LANGUAGES)
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 def main():
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 '''Call everything in the correct order.'''
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 from subprocess import call
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 settings.configure()
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 make_messages()
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 compile_messages()
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 for language in AVAILABLE_LANGUAGES:
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 call([sys.argv[0], language])
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 def generate_page(language):
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 '''Write a single page, and gzip it for lower network usage.'''
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 assert language in AVAILABLE_LANGUAGES
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 import django
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 from django.template import Template, Context
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 import gzip
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
2
0994ae3e4518 Fix compilation on Django 1.10+.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
56 settings.configure(LANGUAGE_CODE=language, LOCALE_PATHS=['locale'], TEMPLATES=[{'BACKEND': 'django.template.backends.django.DjangoTemplates'}])
0
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 django.setup()
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 with open('index.tpl.xhtml') as template_file:
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 template = Template(template_file.read())
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 rendered = template.render(Context({'AVAILABLE_LANGUAGES':
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 AVAILABLE_LANGUAGES}))
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 filename = '../index.%s.xhtml' % language
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 with open(filename, 'w') as out:
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 out.write(rendered)
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 with gzip.open(filename + '.gz', 'w') as out:
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 out.write(rendered.encode('utf-8'))
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 if __name__ == '__main__':
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 if len(sys.argv) == 1:
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 main()
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 else:
0a1d0ab5f518 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 generate_page(sys.argv[1])