blob: 75e837fbbf8c2e18ef8e55ab0d3c8676228f27b5 (
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
|
# -*- coding: utf-8 -*-
##
import os
from gajim.common import configpaths
from gajim.plugins import GajimPlugin
from gajim.plugins.helpers import log_calls
from gajim.plugins.plugins_i18n import _
class PluginsTranslationsPlugin(GajimPlugin):
@log_calls('PluginsTranslationsPlugin')
def init(self):
self.description = _('This plugin contains translation files '
'for Gajim plugins')
self.config_dialog = None
self.config_default_values = {'last_version': '0'}
self.locale_dir = os.path.join(
configpaths.get('PLUGINS_USER'), 'locale')
@log_calls('PluginsTranslationsPlugin')
def activate(self):
if self.config['last_version'] == self.version:
return
from glob import glob
import shutil
files = glob(self.__path__ + '/*.mo')
# remove old data
self.remove_translations()
# create dirs and copy files
os.mkdir(self.locale_dir)
locales = [os.path.splitext(os.path.basename(name))[0] for name in files]
for locale in locales:
dst = os.path.join(os.path.join(self.locale_dir, locale),
'LC_MESSAGES/gajim_plugins.mo')
os.makedirs(os.path.split(dst)[0])
shutil.copy2(os.path.join(self.__path__, '%s.mo' % locale), dst)
self.config['last_version'] = self.version
def remove_translations(self):
if os.path.isdir(self.locale_dir):
import shutil
shutil.rmtree(self.locale_dir)
@log_calls('PluginsTranslationsPlugin')
def deactivate(self):
self.remove_translations()
self.config['last_version'] = '0'
|