blob: 684cb500d46acfcd17fba89bfed6ba47fcc720eb (
plain)
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
|
# This file is part of Gajim.
#
# Gajim 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; version 3 only.
#
# Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from typing import cast
import logging
import os
import shutil
from glob import glob
from pathlib import Path
from gajim.common import configpaths
from gajim.plugins import GajimPlugin
from gajim.plugins.plugins_i18n import _
log = logging.getLogger('gajim.p.plugins_translations')
class PluginsTranslationsPlugin(GajimPlugin):
def init(self) -> None:
self.description = _('This plugin contains translations for other '
'Gajim plugins. Please restart Gajim after '
'enabling this plugin.')
self.config_dialog = None
self.config_default_values = {'last_version': ('0', '')}
self.locale_dir = Path(configpaths.get('PLUGINS_USER')) / 'locale'
def activate(self) -> None:
current_version = str(self.manifest.version)
if cast(str, self.config['last_version']) == current_version:
return
files = glob(self.__path__ + '/*.mo')
self._remove_translations()
self.locale_dir.mkdir()
locales = [
os.path.splitext(os.path.basename(name))[0] for name in files
]
log.info('Installing new translations...')
for locale in locales:
dst = self.locale_dir / locale / 'LC_MESSAGES' / 'gajim_plugins.mo'
dst.mkdir(parents=True)
shutil.copy2(os.path.join(self.__path__, '%s.mo' % locale),
str(dst))
self.config['last_version'] = current_version
def _remove_translations(self) -> None:
log.info('Removing old translations...')
if self.locale_dir.exists():
shutil.rmtree(str(self.locale_dir))
def deactivate(self) -> None:
self._remove_translations()
self.config['last_version'] = '0'
|