From c4b012d2c83104a119faaf36c6890b681b423aad Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Sat, 9 Dec 2017 19:13:53 +0200 Subject: [PATCH] Set locale automatically during the first run Closes #235 See also: c4fa38ba8bd71ca4dcd7b8c217c58e7b8da5d191 --- youtube_dl_gui/optionsmanager.py | 5 +++-- youtube_dl_gui/utils.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/youtube_dl_gui/optionsmanager.py b/youtube_dl_gui/optionsmanager.py index 291c021..a36b64e 100644 --- a/youtube_dl_gui/optionsmanager.py +++ b/youtube_dl_gui/optionsmanager.py @@ -13,7 +13,8 @@ from .utils import ( os_path_exists, encode_tuple, decode_tuple, - check_path + check_path, + get_default_lang ) from .formats import ( @@ -282,7 +283,7 @@ class OptionsManager(object): 'enable_log': True, 'log_time': True, 'workers_number': 3, - 'locale_name': 'en_US', + 'locale_name': get_default_lang(), 'main_win_size': (740, 490), 'opts_win_size': (640, 490), 'selected_video_formats': ['webm', 'mp4'], diff --git a/youtube_dl_gui/utils.py b/youtube_dl_gui/utils.py index a966ae8..729c007 100644 --- a/youtube_dl_gui/utils.py +++ b/youtube_dl_gui/utils.py @@ -116,6 +116,9 @@ os_path_abspath = convert_on_bounds(os.path.abspath) os_path_realpath = convert_on_bounds(os.path.realpath) os_path_expanduser = convert_on_bounds(os.path.expanduser) +# Patch locale functions +locale_getdefaultlocale = convert_on_bounds(locale.getdefaultlocale) + # Patch Windows specific functions if os.name == 'nt': os_startfile = convert_on_bounds(os.startfile) @@ -376,3 +379,13 @@ def build_command(options_list, url): url = "\"{}\"".format(url) return " ".join([YOUTUBEDL_BIN] + options + [url]) + + +def get_default_lang(): + """Get default language using the 'locale' module.""" + default_lang, _ = locale_getdefaultlocale() + + if not default_lang: + default_lang = "en_US" + + return default_lang