1
1
import os
2
2
3
+ from datetime import datetime
4
+
5
+ from babel .messages .pofile import read_po , write_po
6
+ from babel .util import LOCALTZ
7
+
3
8
from invoke import task , call
4
9
5
10
ROOT = os .path .abspath (os .path .join (os .path .dirname (__file__ )))
6
11
12
+ PYTHON_I18N_ROOT = 'udata_metrics/translations'
13
+
14
+ LANGUAGES = ['fr' ]
15
+
7
16
TO_CLEAN = ['build' , 'dist' , '**/*.pyc' , 'reports' ]
8
17
9
18
@@ -64,7 +73,7 @@ def test(ctx, report=False):
64
73
@task
65
74
def cover (ctx , html = False ):
66
75
'''Run tests suite with coverage'''
67
- cmd = 'pytest --cov udata-metrics --cov-report term'
76
+ cmd = 'pytest --cov udata_metrics --cov-report term'
68
77
if html :
69
78
cmd = ' ' .join ((cmd , '--cov-report html:reports/cover' ))
70
79
with ctx .cd (ROOT ):
@@ -77,7 +86,7 @@ def qa(ctx):
77
86
header (qa .__doc__ )
78
87
with ctx .cd (ROOT ):
79
88
info ('Python Static Analysis' )
80
- flake8_results = ctx .run ('flake8 udata-metrics ' , pty = True , warn = True )
89
+ flake8_results = ctx .run ('flake8 udata_metrics ' , pty = True , warn = True )
81
90
if flake8_results .failed :
82
91
error ('There is some lints to fix' )
83
92
else :
@@ -94,6 +103,48 @@ def qa(ctx):
94
103
exit (flake8_results .return_code or readme_results .return_code )
95
104
success ('Quality check OK' )
96
105
106
+ def set_po_metadata (filename , locale ):
107
+ # Fix crowdin requiring Language with `2-digit` iso code in potfile
108
+ # to produce 2-digit iso code pofile
109
+ # Opening the catalog also allows to set extra metadata
110
+ with open (filename , 'rb' ) as infile :
111
+ catalog = read_po (infile , locale )
112
+ catalog .copyright_holder = 'Etalab'
113
+ catalog .
msgid_bugs_address = '[email protected] '
114
+ catalog .
language_team = 'Data.gouv.fr Team <[email protected] >'
115
+ catalog .
last_translator = 'Data.gouv.fr Team <[email protected] >'
116
+ catalog .revision_date = datetime .now (LOCALTZ )
117
+ with open (filename , 'wb' ) as outfile :
118
+ write_po (outfile , catalog , width = 80 )
119
+
120
+
121
+ @task
122
+ def i18n (ctx , update = False ):
123
+ '''Extract translatable strings'''
124
+ header (i18n .__doc__ )
125
+
126
+ # Python translations
127
+ info ('Extract python translations' )
128
+ with ctx .cd (ROOT ):
129
+ ctx .run ('python setup.py extract_messages' )
130
+ set_po_metadata (os .path .join (PYTHON_I18N_ROOT , 'udata_metrics.pot' ), 'en' )
131
+ for lang in LANGUAGES :
132
+ pofile = os .path .join (PYTHON_I18N_ROOT , lang , 'LC_MESSAGES' , 'udata_metrics.po' )
133
+ if not os .path .exists (pofile ):
134
+ ctx .run ('python setup.py init_catalog -l {}' .format (lang ))
135
+ set_po_metadata (pofile , lang )
136
+ elif update :
137
+ ctx .run ('python setup.py update_catalog -l {}' .format (lang ))
138
+ set_po_metadata (pofile , lang )
139
+
140
+
141
+ @task
142
+ def i18nc (ctx ):
143
+ '''Compile translations'''
144
+ header ('Compiling translations' )
145
+ with ctx .cd (ROOT ):
146
+ ctx .run ('python setup.py compile_catalog' )
147
+
97
148
98
149
@task
99
150
def dist (ctx , buildno = None ):
0 commit comments