diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 83a3922b..ea5fe1d8 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -17,6 +17,7 @@ from __future__ import unicode_literals from future.builtins import range import datetime +import gettext import os import future.moves.queue as queue import sqlite3 @@ -536,6 +537,8 @@ def start(): global _STARTED if _INITIALIZED: + set_locale(CONFIG.LOCALE) + # Start refreshes on a separate thread threading.Thread(target=startup_refresh).start() @@ -2700,3 +2703,11 @@ def get_tautulli_info(): 'tautulli_python_version': common.PYTHON_VERSION, } return tautulli + + +def set_locale(locale): + logger.info("Setting locale to '%s'", locale) + locale_dir = os.path.join(PROG_DIR, 'data/locales/') + translation = gettext.translation('tautulli', localedir=locale_dir, + languages=[locale, 'en'], fallback=True) + translation.install() diff --git a/plexpy/webserve.py b/plexpy/webserve.py index fc58ca7f..74b8e490 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -23,7 +23,6 @@ from backports import csv from io import open, BytesIO import base64 -import gettext import json import linecache import os @@ -116,8 +115,6 @@ else: def serve_template(templatename, **kwargs): - _ = gettext.gettext - interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/interfaces/') template_dir = os.path.join(str(interface_dir), plexpy.CONFIG.INTERFACE) @@ -3260,7 +3257,7 @@ class WebInterface(object): https_changed = False refresh_libraries = False refresh_users = False - refresh_page = False + change_locale = False # First run from the setup wizard if kwargs.pop('first_run', None): @@ -3325,7 +3322,7 @@ class WebInterface(object): # Refresh the page if locale changed if kwargs.get('locale') != plexpy.CONFIG.LOCALE: - refresh_page = True + change_locale = True # If we change any monitoring settings, make sure we reschedule tasks. if kwargs.get('check_github') != plexpy.CONFIG.CHECK_GITHUB or \ @@ -3427,9 +3424,12 @@ class WebInterface(object): if refresh_users: threading.Thread(target=users.refresh_users).start() + if change_locale: + plexpy.set_locale(plexpy.CONFIG.LOCALE) + result = {'result': 'success', 'message': 'Settings saved.'} - if refresh_page: - result['refresh'] = refresh_page + if change_locale: + result['refresh'] = True return result @cherrypy.expose