-
-
Notifications
You must be signed in to change notification settings - Fork 964
/
models.py
98 lines (84 loc) · 3.52 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2020 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from appconf import AppConf
from django.utils.functional import cached_property
from weblate.trans.util import delete_configuration_error
from weblate.utils.classloader import ClassLoader
class FileFormatLoader(ClassLoader):
def __init__(self):
super(FileFormatLoader, self).__init__('WEBLATE_FORMATS', False)
self.errors = {}
@cached_property
def autoload(self):
result = []
for fileformat in self.data.values():
for autoload in fileformat.autoload:
result.append((autoload, fileformat))
return result
def load_data(self):
result = super(FileFormatLoader, self).load_data()
for fileformat in list(result.values()):
error_name = 'File format: {0}'.format(fileformat.format_id)
delete_configuration_error(error_name)
try:
fileformat.get_class()
except (AttributeError, ImportError) as error:
result.pop(fileformat.format_id)
if fileformat.format_id != 'rc':
self.errors[fileformat.format_id] = str(error)
return result
FILE_FORMATS = FileFormatLoader()
class FormatsConf(AppConf):
FORMATS = (
'weblate.formats.ttkit.PoFormat',
'weblate.formats.ttkit.PoMonoFormat',
'weblate.formats.ttkit.TSFormat',
'weblate.formats.ttkit.XliffFormat',
'weblate.formats.ttkit.PoXliffFormat',
'weblate.formats.ttkit.StringsFormat',
'weblate.formats.ttkit.StringsUtf8Format',
'weblate.formats.ttkit.PropertiesUtf8Format',
'weblate.formats.ttkit.PropertiesUtf16Format',
'weblate.formats.ttkit.PropertiesFormat',
'weblate.formats.ttkit.JoomlaFormat',
'weblate.formats.ttkit.PhpFormat',
'weblate.formats.ttkit.RESXFormat',
'weblate.formats.ttkit.AndroidFormat',
'weblate.formats.ttkit.JSONFormat',
'weblate.formats.ttkit.JSONNestedFormat',
'weblate.formats.ttkit.WebExtensionJSONFormat',
'weblate.formats.ttkit.I18NextFormat',
'weblate.formats.ttkit.CSVFormat',
'weblate.formats.ttkit.CSVSimpleFormat',
'weblate.formats.ttkit.CSVSimpleFormatISO',
'weblate.formats.ttkit.YAMLFormat',
'weblate.formats.ttkit.RubyYAMLFormat',
'weblate.formats.ttkit.SubRipFormat',
'weblate.formats.ttkit.MicroDVDFormat',
'weblate.formats.ttkit.AdvSubStationAlphaFormat',
'weblate.formats.ttkit.SubStationAlphaFormat',
'weblate.formats.ttkit.DTDFormat',
'weblate.formats.ttkit.WindowsRCFormat',
'weblate.formats.ttkit.FlatXMLFormat',
'weblate.formats.external.XlsxFormat',
'weblate.formats.txt.AppStoreFormat',
)
class Meta(object):
prefix = 'WEBLATE'