Workaround to make translation works

This commit is contained in:
Huluti 2016-12-11 00:05:32 +01:00
parent 02400eb6bf
commit 58894fa9d3
5 changed files with 133 additions and 98 deletions

View File

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-09 17:26+0100\n"
"PO-Revision-Date: 2016-12-09 17:26+0100\n"
"POT-Creation-Date: 2016-12-10 23:59+0100\n"
"PO-Revision-Date: 2016-12-10 23:59+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr_FR\n"
@ -30,11 +30,11 @@ msgstr "Écran de bienvenue pour Manjaro"
msgid "Github"
msgstr "Github"
#: manjaro-hello.glade:104
#: manjaro-hello.glade:103
msgid "Welcome to Manjaro!"
msgstr "Bienvenue sur Manjaro !"
#: manjaro-hello.glade:121
#: manjaro-hello.glade:120
msgid ""
"Thank you for joining our community!\n"
"\n"
@ -51,86 +51,84 @@ msgstr ""
"Alors profitez de l'expérience, et n'hésitez pas à nous faire part de vos "
"commentaires."
#: manjaro-hello.glade:138
#: manjaro-hello.glade:137
msgid "DOCUMENTATION"
msgstr "DOCUMENTATION"
#: manjaro-hello.glade:152
#: manjaro-hello.glade:151
msgid "SUPPORT"
msgstr "SUPPORT"
#: manjaro-hello.glade:166
#: manjaro-hello.glade:165
msgid "PROJECT"
msgstr "PROJET"
#: manjaro-hello.glade:178 manjaro-hello.glade:542
#: manjaro-hello.glade:177 manjaro-hello.glade:537
msgid "Read me"
msgstr "Lisez moi"
#: manjaro-hello.glade:192 manjaro-hello.glade:582
#: manjaro-hello.glade:191 manjaro-hello.glade:577
msgid "Release info"
msgstr "Informations de version"
#: manjaro-hello.glade:206
#: manjaro-hello.glade:205
msgid "Wiki"
msgstr "Wiki"
#: manjaro-hello.glade:220 manjaro-hello.glade:643
#: manjaro-hello.glade:219 manjaro-hello.glade:638
msgid "Get involved"
msgstr "S'investir"
#: manjaro-hello.glade:234
#: manjaro-hello.glade:233
msgid "Forums"
msgstr "Forums"
#: manjaro-hello.glade:248
#: manjaro-hello.glade:247
msgid "Chat room"
msgstr "Salon de chat"
#: manjaro-hello.glade:262
#: manjaro-hello.glade:261
msgid "Mailling lists"
msgstr "Listes de diffusion"
#: manjaro-hello.glade:276
#: manjaro-hello.glade:275
msgid "Build Manjaro"
msgstr "Construire Manjaro"
#: manjaro-hello.glade:290
#: manjaro-hello.glade:289
msgid "Donate"
msgstr "Faire un don"
#: manjaro-hello.glade:406
#: manjaro-hello.glade:401
msgid "Launch at start"
msgstr "Lancer au démarrage"
#: manjaro-hello.glade:443
#: manjaro-hello.glade:438
msgid "Use Calamares (Graphic method)"
msgstr "Utiliser Calamares (Méthode graphique)"
#: manjaro-hello.glade:457
#: manjaro-hello.glade:452
msgid "Use CLI-Installer (Command line)"
msgstr "Utiliser CLI-Installer (Ligne de commande)"
#: manjaro-hello.glade:479
#: manjaro-hello.glade:474
msgid "INSTALLATION"
msgstr "INSTALLATION"
#: manjaro-hello.glade:498
#: manjaro-hello.glade:493
msgid "Welcome"
msgstr "Bienvenue"
#: manjaro-hello.glade:598
#: manjaro-hello.glade:593
msgid "Documentation"
msgstr "Documentation"
#: manjaro-hello.glade:664
#: manjaro-hello.glade:659
msgid "Project"
msgstr "Projet"
#: manjaro-hello.glade:687
msgid "English (United States)"
msgstr "Anglais (États-Unis)"
#~ msgid "English (United States)"
#~ msgstr "Anglais (États-Unis)"
#: manjaro-hello.glade:688
msgid "French (France)"
msgstr "Français (France)"
#~ msgid "French (France)"
#~ msgstr "Français (France)"

View File

@ -75,7 +75,7 @@
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkGrid">
<object class="GtkGrid" id="welcome">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
@ -97,7 +97,7 @@
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="welcomelabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Welcome to Manjaro!</property>
@ -113,7 +113,7 @@
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="welcometext">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -131,7 +131,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="documentationtitle">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">DOCUMENTATION</property>
@ -145,7 +145,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="supporttitle">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">SUPPORT</property>
@ -159,7 +159,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="projecttitle">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">PROJECT</property>
@ -173,7 +173,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="readmebtn">
<property name="label" translatable="yes">Read me</property>
<property name="name">readmebtn</property>
<property name="visible">True</property>
@ -187,7 +187,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="releasebtn">
<property name="label" translatable="yes">Release info</property>
<property name="name">releasebtn</property>
<property name="visible">True</property>
@ -201,7 +201,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="wikibtn">
<property name="label" translatable="yes">Wiki</property>
<property name="name">wikibtn</property>
<property name="visible">True</property>
@ -215,7 +215,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="involvedbtn">
<property name="label" translatable="yes">Get involved</property>
<property name="name">involvedbtn</property>
<property name="visible">True</property>
@ -229,7 +229,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="forumsbtn">
<property name="label" translatable="yes">Forums</property>
<property name="name">forumsbtn</property>
<property name="visible">True</property>
@ -243,7 +243,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="chatbtn">
<property name="label" translatable="yes">Chat room</property>
<property name="name">chatbtn</property>
<property name="visible">True</property>
@ -257,7 +257,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="maillingbtn">
<property name="label" translatable="yes">Mailling lists</property>
<property name="name">maillingbtn</property>
<property name="visible">True</property>
@ -271,7 +271,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="buildbtn">
<property name="label" translatable="yes">Build Manjaro</property>
<property name="name">buildbtn</property>
<property name="visible">True</property>
@ -285,7 +285,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="donatebtn">
<property name="label" translatable="yes">Donate</property>
<property name="name">donatebtn</property>
<property name="visible">True</property>
@ -394,7 +394,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="autostartlabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
@ -531,7 +531,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child type="tab">
<object class="GtkLabel">
<object class="GtkLabel" id="readmelabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Read me</property>
@ -571,7 +571,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child type="tab">
<object class="GtkLabel">
<object class="GtkLabel" id="releaselabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Release info</property>
@ -632,7 +632,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child type="tab">
<object class="GtkLabel">
<object class="GtkLabel" id="involvedlabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Get involved</property>
@ -679,8 +679,8 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item id="en_US" translatable="yes">English (United States)</item>
<item id="fr_FR" translatable="yes">French (France)</item>
<item id="en_US">English (United States)</item>
<item id="fr_FR">Français (France)</item>
</items>
</object>
<packing>

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-09 17:26+0100\n"
"POT-Creation-Date: 2016-12-10 23:58+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -29,11 +29,11 @@ msgstr ""
msgid "Github"
msgstr ""
#: manjaro-hello.glade:104
#: manjaro-hello.glade:103
msgid "Welcome to Manjaro!"
msgstr ""
#: manjaro-hello.glade:121
#: manjaro-hello.glade:120
msgid ""
"Thank you for joining our community!\n"
"\n"
@ -43,86 +43,78 @@ msgid ""
"your feedback."
msgstr ""
#: manjaro-hello.glade:138
#: manjaro-hello.glade:137
msgid "DOCUMENTATION"
msgstr ""
#: manjaro-hello.glade:152
#: manjaro-hello.glade:151
msgid "SUPPORT"
msgstr ""
#: manjaro-hello.glade:166
#: manjaro-hello.glade:165
msgid "PROJECT"
msgstr ""
#: manjaro-hello.glade:178 manjaro-hello.glade:542
#: manjaro-hello.glade:177 manjaro-hello.glade:537
msgid "Read me"
msgstr ""
#: manjaro-hello.glade:192 manjaro-hello.glade:582
#: manjaro-hello.glade:191 manjaro-hello.glade:577
msgid "Release info"
msgstr ""
#: manjaro-hello.glade:206
#: manjaro-hello.glade:205
msgid "Wiki"
msgstr ""
#: manjaro-hello.glade:220 manjaro-hello.glade:643
#: manjaro-hello.glade:219 manjaro-hello.glade:638
msgid "Get involved"
msgstr ""
#: manjaro-hello.glade:234
#: manjaro-hello.glade:233
msgid "Forums"
msgstr ""
#: manjaro-hello.glade:248
#: manjaro-hello.glade:247
msgid "Chat room"
msgstr ""
#: manjaro-hello.glade:262
#: manjaro-hello.glade:261
msgid "Mailling lists"
msgstr ""
#: manjaro-hello.glade:276
#: manjaro-hello.glade:275
msgid "Build Manjaro"
msgstr ""
#: manjaro-hello.glade:290
#: manjaro-hello.glade:289
msgid "Donate"
msgstr ""
#: manjaro-hello.glade:406
#: manjaro-hello.glade:401
msgid "Launch at start"
msgstr ""
#: manjaro-hello.glade:443
#: manjaro-hello.glade:438
msgid "Use Calamares (Graphic method)"
msgstr ""
#: manjaro-hello.glade:457
#: manjaro-hello.glade:452
msgid "Use CLI-Installer (Command line)"
msgstr ""
#: manjaro-hello.glade:479
#: manjaro-hello.glade:474
msgid "INSTALLATION"
msgstr ""
#: manjaro-hello.glade:498
#: manjaro-hello.glade:493
msgid "Welcome"
msgstr ""
#: manjaro-hello.glade:598
#: manjaro-hello.glade:593
msgid "Documentation"
msgstr ""
#: manjaro-hello.glade:664
#: manjaro-hello.glade:659
msgid "Project"
msgstr ""
#: manjaro-hello.glade:687
msgid "English (United States)"
msgstr ""
#: manjaro-hello.glade:688
msgid "French (France)"
msgstr ""

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
from locale import gettext as _
import gettext
import gi
import json
import locale
@ -53,7 +53,17 @@ class ManjaroHello():
"locale": None
}
# Load system infos
self.infos = get_infos()
# Init window
self.builder = Gtk.Builder()
self.builder.add_from_file("manjaro-hello.glade")
self.builder.connect_signals(self)
self.window = self.builder.get_object("window")
# Init translation
self.default_texts = {}
locales = os.listdir(self.locale_path)
locales.append(self.default_locale)
if self.preferences["locale"] not in locales:
@ -62,26 +72,18 @@ class ManjaroHello():
else:
self.preferences["locale"] = self.default_locale
locale.setlocale(locale.LC_ALL, self.preferences["locale"] + ".utf8")
locale.bindtextdomain(self.app, self.locale_path)
locale.textdomain(self.app)
# Select current locale in languages menu
self.builder.get_object("languages").set_active_id(self.preferences["locale"]);
self.builder.get_object("languages").connect("changed", self.on_languages_changed)
# Make translation
gettext.bindtextdomain(self.app, self.locale_path)
gettext.textdomain(self.app)
self.set_locale(self.preferences["locale"])
# Save locale used in config file
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")
# Select current locale in languages menu
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"]:
@ -115,6 +117,49 @@ class ManjaroHello():
self.window.show();
def set_locale(self, locale_code):
if self.preferences["locale"] != self.default_locale:
locale = gettext.translation(self.app, self.locale_path, [locale_code])
locale.install()
else:
gettext.install(self.app)
# Dirty code to fix an issue with gettext that can't translate text from glade interface
# TODO: Find a better solution
elts = {
"welcomelabel": "label",
"welcometext": "label",
"documentationtitle": "label",
"readmelabel": "label",
"releaselabel": "label",
"involvedlabel": "label",
"supporttitle": "label",
"projecttitle": "label",
"readmebtn": "label",
"releasebtn": "label",
"wikibtn": "label",
"involvedbtn": "label",
"forumsbtn": "label",
"chatbtn": "label",
"maillingbtn": "label",
"buildbtn": "label",
"donatebtn": "label",
"installlabel": "label",
"installgui": "label",
"installcli": "label",
"autostartlabel": "label",
"aboutdialog": "comments"
}
for elt in elts:
if elt not in self.default_texts:
self.default_texts[elt] = getattr(self.builder.get_object(elt), "get_" + elts[elt])()
getattr(self.builder.get_object(elt), "set_" + elts[elt])(_(self.default_texts[elt]))
for stack in ("welcome", "documentation", "project"):
if stack not in self.default_texts:
self.default_texts[stack] = self.builder.get_object("stack").child_get_property(self.builder.get_object(stack), "title")
self.builder.get_object("stack").child_set_property(self.builder.get_object(stack), "title", _(self.default_texts[stack]))
def change_autostart(self, state):
if state and not os.path.isfile(self.autostart_path):
try:
@ -156,8 +201,8 @@ class ManjaroHello():
# Handlers
def on_languages_changed(self, combobox):
self.preferences["locale"] = combobox.get_active_id()
self.set_locale(self.preferences["locale"])
self.save_preferences()
os.execv(sys.executable, ['python'] + sys.argv)
def on_about_clicked(self, btn):
dialog = self.builder.get_object("aboutdialog")