From ded0363653edbb3a1dee806fc1dff622f5a55431 Mon Sep 17 00:00:00 2001 From: Huluti Date: Fri, 9 Dec 2016 17:28:22 +0100 Subject: [PATCH] Improve translation system --- reminder.txt | 2 +- src/locale/fr/LC_MESSAGES/manjaro-hello.mo | Bin 2230 -> 0 bytes src/locale/fr_FR/LC_MESSAGES/manjaro-hello.mo | Bin 0 -> 2346 bytes .../LC_MESSAGES/manjaro-hello.po | 47 ++++----- src/manjaro-hello.glade | 14 +++ src/{messages.pot => manjaro-hello.pot} | 10 +- src/manjaro-hello.py | 93 +++++++++++------- src/pages/{en => en_US}/involved | 0 src/pages/{en => en_US}/readme | 0 src/pages/{en => en_US}/release | 0 10 files changed, 97 insertions(+), 69 deletions(-) delete mode 100644 src/locale/fr/LC_MESSAGES/manjaro-hello.mo create mode 100644 src/locale/fr_FR/LC_MESSAGES/manjaro-hello.mo rename src/locale/{fr => fr_FR}/LC_MESSAGES/manjaro-hello.po (80%) rename src/{messages.pot => manjaro-hello.pot} (92%) rename src/pages/{en => en_US}/involved (100%) rename src/pages/{en => en_US}/readme (100%) rename src/pages/{en => en_US}/release (100%) diff --git a/reminder.txt b/reminder.txt index 64ac459..2c48e54 100644 --- a/reminder.txt +++ b/reminder.txt @@ -1,2 +1,2 @@ Generate main translation file: - xgettext -k_ -kN_ -L Glade -o messages.pot *.glade + xgettext -k_ -kN_ -L Glade -o manjaro-hello.pot *.glade diff --git a/src/locale/fr/LC_MESSAGES/manjaro-hello.mo b/src/locale/fr/LC_MESSAGES/manjaro-hello.mo deleted file mode 100644 index ee53c6923b96497c64dd0b4a91b8a93ecda50780..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2230 zcmaJ>O>7)B6gIT{Eq`tKEg*P3pfr$KvPGgHRV&i`X<;{6B^%ls^3Hg7oy^#S?b$T+ zf_g!fxFL`@AaNwX1##oLCyw081qsBN8=U#x>}&!Eu-5af?dRw3efE1lojLijKs$^6 z9Qv>5FQR{a7d~ij+%3dC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jJYe^+ojGm`XO&Cv6xSnDi zCCYmiEy+urDA*0mzKRxyuCHR8vop}zR|q9Hgu&Mt!Z(ICkXkNz#IR1Ysf9Dhi4Gd_ zHRhJG1l*}Q1-gwH>kanNC2*djX_b)zgHD+QIr{D}n4pKQz%3ui;n6lqpTXxpy`!nS z21JIDMib!%av*xxMOuS>ZXb%eWjjG+C&VR?>MK(yF}NP1P*}^>XpeGkgrkmfAWHsl Im#VJvFBemVtN;K2 literal 0 HcmV?d00001 diff --git a/src/locale/fr/LC_MESSAGES/manjaro-hello.po b/src/locale/fr_FR/LC_MESSAGES/manjaro-hello.po similarity index 80% rename from src/locale/fr/LC_MESSAGES/manjaro-hello.po rename to src/locale/fr_FR/LC_MESSAGES/manjaro-hello.po index b67be6d..886678c 100644 --- a/src/locale/fr/LC_MESSAGES/manjaro-hello.po +++ b/src/locale/fr_FR/LC_MESSAGES/manjaro-hello.po @@ -7,11 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-12-08 17:07+0100\n" -"PO-Revision-Date: 2016-12-08 17:09+0100\n" +"POT-Creation-Date: 2016-12-09 17:26+0100\n" +"PO-Revision-Date: 2016-12-09 17:26+0100\n" "Last-Translator: \n" "Language-Team: \n" -"Language: fr\n" +"Language: fr_FR\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -63,11 +63,11 @@ msgstr "SUPPORT" msgid "PROJECT" msgstr "PROJET" -#: manjaro-hello.glade:178 manjaro-hello.glade:545 +#: manjaro-hello.glade:178 manjaro-hello.glade:542 msgid "Read me" msgstr "Lisez moi" -#: manjaro-hello.glade:192 manjaro-hello.glade:585 +#: manjaro-hello.glade:192 manjaro-hello.glade:582 msgid "Release info" msgstr "Informations de version" @@ -75,7 +75,7 @@ msgstr "Informations de version" msgid "Wiki" msgstr "Wiki" -#: manjaro-hello.glade:220 manjaro-hello.glade:646 +#: manjaro-hello.glade:220 manjaro-hello.glade:643 msgid "Get involved" msgstr "S'investir" @@ -107,43 +107,30 @@ msgstr "Lancer au démarrage" msgid "Use Calamares (Graphic method)" msgstr "Utiliser Calamares (Méthode graphique)" -#: manjaro-hello.glade:458 +#: manjaro-hello.glade:457 msgid "Use CLI-Installer (Command line)" msgstr "Utiliser CLI-Installer (Ligne de commande)" -#: manjaro-hello.glade:482 +#: manjaro-hello.glade:479 msgid "INSTALLATION" msgstr "INSTALLATION" -#: manjaro-hello.glade:501 +#: manjaro-hello.glade:498 msgid "Welcome" msgstr "Bienvenue" -#: manjaro-hello.glade:601 +#: manjaro-hello.glade:598 msgid "Documentation" msgstr "Documentation" -#: manjaro-hello.glade:667 +#: manjaro-hello.glade:664 msgid "Project" msgstr "Projet" -#~ msgid "SOCIAL" -#~ msgstr "SOCIAL" +#: manjaro-hello.glade:687 +msgid "English (United States)" +msgstr "Anglais (États-Unis)" -#~ msgid "Google+" -#~ msgstr "Google+" - -#~ msgid "Facebook" -#~ msgstr "Facebook" - -#~ msgid "Twitter" -#~ msgstr "Twitter" - -#~ msgid "Reddit" -#~ msgstr "Reddit" - -#~ msgid "Support" -#~ msgstr "Support" - -#~ msgid "Social" -#~ msgstr "Social" +#: manjaro-hello.glade:688 +msgid "French (France)" +msgstr "Français (France)" diff --git a/src/manjaro-hello.glade b/src/manjaro-hello.glade index 27ce423..94a64c8 100644 --- a/src/manjaro-hello.glade +++ b/src/manjaro-hello.glade @@ -679,6 +679,19 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we False Manjaro Hello True + + + True + False + + English (United States) + French (France) + + + + 1 + + True @@ -689,6 +702,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we end + 1 diff --git a/src/messages.pot b/src/manjaro-hello.pot similarity index 92% rename from src/messages.pot rename to src/manjaro-hello.pot index 304a911..23100ec 100644 --- a/src/messages.pot +++ b/src/manjaro-hello.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-12-08 17:26+0100\n" +"POT-Creation-Date: 2016-12-09 17:26+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -118,3 +118,11 @@ msgstr "" #: manjaro-hello.glade:664 msgid "Project" msgstr "" + +#: manjaro-hello.glade:687 +msgid "English (United States)" +msgstr "" + +#: manjaro-hello.glade:688 +msgid "French (France)" +msgstr "" diff --git a/src/manjaro-hello.py b/src/manjaro-hello.py index d7cd382..a81e6bf 100644 --- a/src/manjaro-hello.py +++ b/src/manjaro-hello.py @@ -15,30 +15,8 @@ class ManjaroHello(): def __init__(self): # App vars self.app = "manjaro-hello" - - # Path vars - config_path = os.path.expanduser("~") + "/.config/" - #share_path = "/usr/share/" - - self.preferences_path = config_path + self.app + ".json" - self.desktop_path = os.getcwd() + "/" + self.app + ".desktop" # later use share_path - self.autostart_path = config_path + "autostart/" + self.app + ".desktop" - self.icon_path = self.app + ".png" # later use share_path - - # Languages vars - self.language = locale.getlocale()[0][:2] - self.default_language = "en" - self.locale_dir = "locale" - - # Settings vars - self.preferences = self.get_preferences() - if not self.preferences: - self.preferences = {"autostart": os.path.isfile(self.autostart_path)} - self.save_preferences() - - self.infos = get_infos() - - # Social urls + self.default_locale = "en_US" + self.sys_locale = locale.getlocale()[0] self.social_urls = { "google+": "https://plus.google.com/118244873957924966264", "facebook": "https://www.facebook.com/ManjaroLinux", @@ -46,31 +24,68 @@ class ManjaroHello(): "reddit": "https://www.reddit.com/r/ManjaroLinux" } - # Init language - locale.setlocale(locale.LC_ALL, "") - locale.bindtextdomain(self.app, self.locale_dir) - gettext.bindtextdomain(self.app, self.locale_dir) - gettext.textdomain(self.app) + # Path vars + config_path = os.path.expanduser("~") + "/.config/" + #share_path = "/usr/share/" + self.preferences_path = config_path + self.app + ".json" + self.desktop_path = os.getcwd() + "/" + self.app + ".desktop" # later use share_path + self.autostart_path = config_path + "autostart/" + self.app + ".desktop" + self.icon_path = "./" + self.app + ".png" # later use share_path + self.locale_path = "locale" - # Create window + # Load preferences + self.preferences = self.get_preferences() + if not self.preferences: + self.preferences = { + "autostart": os.path.isfile(self.autostart_path), + "locale": None + } + + # Init translation + locales = os.listdir(self.locale_path) + locales.append(self.default_locale) + if self.preferences["locale"] not in locales: + if self.sys_locale in locales: + self.preferences["locale"] = self.sys_locale + else: + self.preferences["locale"] = self.default_locale + + if self.preferences["locale"] != self.default_locale: + locale.bindtextdomain(self.app, self.locale_path) + gettext.bindtextdomain(self.app, self.locale_path) + gettext.textdomain(self.app) + lang = gettext.translation(self.app, localedir=self.locale_path, languages=[self.preferences["locale"]]) + lang.install() + + # Save new locale + self.save_preferences() + + # Load system infos + self.infos = get_infos() + + # Init window self.builder = Gtk.Builder() self.builder.set_translation_domain(self.app) self.builder.add_from_file("manjaro-hello.glade") self.builder.connect_signals(self) self.window = self.builder.get_object("window") + # Change selected language + self.builder.get_object("languages").set_active_id(self.preferences["locale"]); + self.builder.get_object("languages").connect("changed", self.on_languages_changed) + # Set window subtitle if self.infos["codename"] and self.infos["release"]: self.builder.get_object("headerbar").props.subtitle = self.infos["codename"] + " " + self.infos["release"] + " " self.builder.get_object("headerbar").props.subtitle += self.infos["arch"] - # Initialize pages - for page in ("readme", "release", "involved"): - self.builder.get_object(page + "text").set_markup(self.read_page(page)) - # Set autostart switcher state self.builder.get_object("autostart").set_active(self.preferences["autostart"]) + # Init pages + for page in ("readme", "release", "involved"): + self.builder.get_object(page + "text").set_markup(self.read_page(page)) + # Live systems if self.infos["live"]: can_install = False @@ -114,10 +129,9 @@ class ManjaroHello(): return None def read_page(self, name): - filename = "pages/{}/{}".format(self.language, name) + filename = "pages/{}/{}".format(self.preferences["locale"], name) if not os.path.isfile(filename): - filename = "pages/{}/{}".format(self.default_language, name) - + filename = "pages/{}/{}".format("en_US", name) try: with open(filename, "r") as f: return f.read() @@ -125,6 +139,11 @@ class ManjaroHello(): return None # Handlers + def on_languages_changed(self, combobox): + self.preferences["locale"] = combobox.get_active_id() + self.save_preferences() + os.execv(sys.executable, ['python'] + sys.argv) + def on_about_clicked(self, btn): dialog = self.builder.get_object("aboutdialog") dialog.set_transient_for(self.window) diff --git a/src/pages/en/involved b/src/pages/en_US/involved similarity index 100% rename from src/pages/en/involved rename to src/pages/en_US/involved diff --git a/src/pages/en/readme b/src/pages/en_US/readme similarity index 100% rename from src/pages/en/readme rename to src/pages/en_US/readme diff --git a/src/pages/en/release b/src/pages/en_US/release similarity index 100% rename from src/pages/en/release rename to src/pages/en_US/release