Commit ddc128ce authored by Philipp Hörist's avatar Philipp Hörist

[translations] Use pathlib

parent 08e390ab
import logging
import os
import shutil
from glob import glob
from pathlib import Path
from gajim.common import configpaths
......@@ -16,39 +19,33 @@ class PluginsTranslationsPlugin(GajimPlugin):
'enabling this plugin.')
self.config_dialog = None
self.config_default_values = {'last_version': '0'}
self.locale_dir = os.path.join(
configpaths.get('PLUGINS_USER'), 'locale')
self.locale_dir = Path(configpaths.get('PLUGINS_USER')) / 'locale'
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)
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 = 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)
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'] = self.version
def _remove_translations(self):
log.info('Removing old translations...')
if os.path.isdir(self.locale_dir):
import shutil
shutil.rmtree(self.locale_dir)
if self.locale_dir.exists():
shutil.rmtree(str(self.locale_dir))
def deactivate(self):
self._remove_translations()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment