From ffb2512d867dbe1beb0c1034732212d71146b231 Mon Sep 17 00:00:00 2001 From: "Caleb St. John" <30729806+yocalebo@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:37:42 -0500 Subject: [PATCH] remove dead code (#15038) --- src/middlewared/middlewared/i18n.py | 32 ------------------- .../middlewared/plugins/system/__init__.py | 1 - .../plugins/system_general/language.py | 8 +---- .../plugins/system_general/update.py | 3 -- 4 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 src/middlewared/middlewared/i18n.py diff --git a/src/middlewared/middlewared/i18n.py b/src/middlewared/middlewared/i18n.py deleted file mode 100644 index e247ad250f10..000000000000 --- a/src/middlewared/middlewared/i18n.py +++ /dev/null @@ -1,32 +0,0 @@ -from gettext import NullTranslations, GNUTranslations -import logging -import pkg_resources - -logger = logging.getLogger(__name__) - -translations = NullTranslations() - - -def set_language(language): - global translations - - try: - with open(pkg_resources.resource_filename("middlewared", f"locale/{language}/LC_MESSAGES/middlewared.mo"), "rb") as f: - translations = GNUTranslations(f) - - return True - except Exception as e: - if language != "en": - logger.warning("Failed to set language %r: %r", language, e) - - translations = NullTranslations() - - return False - - -def _(message): - return translations.gettext(message) - - -def __(singular, plural, n): - return translations.ngettext(singular, plural, n) diff --git a/src/middlewared/middlewared/plugins/system/__init__.py b/src/middlewared/middlewared/plugins/system/__init__.py index a3b0bf1aafe7..525f43f67b20 100644 --- a/src/middlewared/middlewared/plugins/system/__init__.py +++ b/src/middlewared/middlewared/plugins/system/__init__.py @@ -40,5 +40,4 @@ async def setup(middleware): settings = await middleware.call('system.general.config') middleware.logger.debug('Setting timezone to %r', settings['timezone']) await middleware.call('core.environ_update', {'TZ': settings['timezone']}) - await middleware.call('system.general.set_language') await middleware.call('sysctl.set_zvol_volmode', 2) diff --git a/src/middlewared/middlewared/plugins/system_general/language.py b/src/middlewared/middlewared/plugins/system_general/language.py index aafab5281a5f..daa97eb3822f 100644 --- a/src/middlewared/middlewared/plugins/system_general/language.py +++ b/src/middlewared/middlewared/plugins/system_general/language.py @@ -1,6 +1,5 @@ -from middlewared.i18n import set_language from middlewared.schema import accepts, Dict, returns -from middlewared.service import private, Service +from middlewared.service import Service LANGUAGES = dict([ @@ -109,8 +108,3 @@ async def language_choices(self): Returns language choices. """ return LANGUAGES - - @private - def set_language(self): - language = self.middleware.call_sync('system.general.config')['language'] - set_language(language) diff --git a/src/middlewared/middlewared/plugins/system_general/update.py b/src/middlewared/middlewared/plugins/system_general/update.py index e9091d3bdc27..be1f013d2baf 100644 --- a/src/middlewared/middlewared/plugins/system_general/update.py +++ b/src/middlewared/middlewared/plugins/system_general/update.py @@ -277,9 +277,6 @@ async def do_update(self, data): await self.middleware.call('service.reload', 'timeservices') await self.middleware.call('service.restart', 'cron') - if config['language'] != new_config['language']: - await self.middleware.call('system.general.set_language') - if config['ds_auth'] != new_config['ds_auth']: await self.middleware.call('etc.generate', 'pam_middleware')