1
|
|
|
""" |
2
|
|
|
localization_compile - facilitates localization file compilation (from .po to .mo) |
3
|
|
|
""" |
4
|
|
|
import pathlib |
5
|
|
|
|
6
|
|
|
# specific to this project |
7
|
|
|
from localizations_common import LocalizationsCommon |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class CustomizedLocalizationCompiling(LocalizationsCommon): |
11
|
|
|
localisation_compilation_is_required = False |
12
|
|
|
|
13
|
|
|
def evaluate_compilation_necessity(self, in_list_localisation_source_files): |
14
|
|
|
list_size = len(in_list_localisation_source_files) |
15
|
|
|
self.operation_is_required = False |
16
|
|
|
file_list_paring_complete = False |
17
|
|
|
file_counter = 0 |
18
|
|
|
domains_to_compile = [] |
19
|
|
|
compiling_files_counter = 0 |
20
|
|
|
while not file_list_paring_complete: |
21
|
|
|
source_localisation_file = in_list_localisation_source_files[file_counter] |
22
|
|
|
folder_parts = pathlib.PurePath(source_localisation_file).parts |
23
|
|
|
current_locale = folder_parts[(len(folder_parts) - 3)] |
24
|
|
|
fn_dict = { |
25
|
|
|
'destination': source_localisation_file.replace('.po', '.mo'), |
26
|
|
|
'counter': file_counter, |
27
|
|
|
'locale': current_locale, |
28
|
|
|
'source': source_localisation_file, |
29
|
|
|
'source file type name': 'source', |
30
|
|
|
'destination operation name': 'compilation', |
31
|
|
|
} |
32
|
|
|
operation_check_result, operation_to_execute = self.check_file_pairs(fn_dict) |
33
|
|
|
if operation_check_result: |
34
|
|
|
domains_to_compile.append(compiling_files_counter) |
35
|
|
|
domains_to_compile[compiling_files_counter] = { |
36
|
|
|
'input-file': fn_dict['source'], |
37
|
|
|
'operation': 'compile_catalog', |
38
|
|
|
'operation final flags': ' --statistics', |
39
|
|
|
'output-file': fn_dict['destination'], |
40
|
|
|
'locale': fn_dict['locale'], |
41
|
|
|
} |
42
|
|
|
compiling_files_counter += 1 |
43
|
|
|
file_counter += 1 |
44
|
|
|
file_list_paring_complete = self.file_counter_limit(file_counter, list_size) |
45
|
|
|
return domains_to_compile |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
my_class = CustomizedLocalizationCompiling() |
49
|
|
|
|
50
|
|
|
locale_source_files = my_class.get_project_localisation_source_files('po') |
51
|
|
|
operation_locale_dict = my_class.evaluate_compilation_necessity(locale_source_files) |
52
|
|
|
my_class.operate_localisation_files(operation_locale_dict) |
53
|
|
|
|