cq: Format with black and isort
This commit is contained in:
@@ -1 +1,3 @@
|
||||
from .plugins_translations import PluginsTranslationsPlugin # type: ignore # noqa: F401
|
||||
from .plugins_translations import ( # type: ignore # noqa: F401
|
||||
PluginsTranslationsPlugin,
|
||||
)
|
||||
|
||||
@@ -23,49 +23,49 @@ 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')
|
||||
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.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'
|
||||
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:
|
||||
if cast(str, self.config["last_version"]) == current_version:
|
||||
return
|
||||
|
||||
files = glob(self.__path__ + '/*.mo')
|
||||
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...')
|
||||
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'
|
||||
dst = self.locale_dir / locale / "LC_MESSAGES"
|
||||
dst.mkdir(parents=True)
|
||||
shutil.copy2(os.path.join(self.__path__, '%s.mo' % locale),
|
||||
dst / 'gajim_plugins.mo')
|
||||
shutil.copy2(
|
||||
os.path.join(self.__path__, "%s.mo" % locale), dst / "gajim_plugins.mo"
|
||||
)
|
||||
|
||||
self.config['last_version'] = current_version
|
||||
self.config["last_version"] = current_version
|
||||
|
||||
def _remove_translations(self) -> None:
|
||||
log.info('Removing old translations...')
|
||||
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'
|
||||
self.config["last_version"] = "0"
|
||||
|
||||
Reference in New Issue
Block a user