From a6553cd01e0f801a7cd40f6144aed5d69b8d57f1 Mon Sep 17 00:00:00 2001 From: Hugo Posnic Date: Tue, 20 Dec 2016 00:17:40 +0100 Subject: [PATCH] Move choice of locale to use in a function --- src/manjaro_hello.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/manjaro_hello.py b/src/manjaro_hello.py index 58331d9..91142e3 100644 --- a/src/manjaro_hello.py +++ b/src/manjaro_hello.py @@ -61,18 +61,7 @@ class ManjaroHello(): self.default_locale = "en" self.sys_locale = locale.getdefaultlocale()[0] self.default_texts = {} - # Choose best locale for user - if self.preferences["locale"] not in self.locales: - # If user's locale is supported - if self.sys_locale in self.locales: - self.preferences["locale"] = self.sys_locale - else: - # If two first letters of user's locale is supported (ex: en_US -> en) - if self.sys_locale[:2] in self.locales: - self.preferences["locale"] = self.sys_locale[:2] - else: - # Else use default locale - self.preferences["locale"] = self.default_locale + self.preferences["locale"] = self.get_best_locale() # Select current locale in languages menu self.builder.get_object("languages").set_active_id(self.preferences["locale"]); @@ -108,6 +97,19 @@ class ManjaroHello(): self.window.show(); + def get_best_locale(self): + if self.preferences["locale"] in self.locales: + return self.preferences["locale"] + else: + # If user's locale is supported + if self.sys_locale in self.locales: + return self.sys_locale + # If two first letters of user's locale is supported (ex: en_US -> en) + elif self.sys_locale[:2] in self.locales: + return self.sys_locale[:2] + else: + return self.default_locale + def set_locale(self, locale): """Set locale of ui and pages. :param locale: locale to use