Improve translation system

merge-requests/64/head
Huluti 2016-12-09 17:28:22 +01:00
parent e813a6407a
commit ded0363653
10 changed files with 97 additions and 69 deletions

View File

@ -1,2 +1,2 @@
Generate main translation file: Generate main translation file:
xgettext -k_ -kN_ -L Glade -o messages.pot *.glade xgettext -k_ -kN_ -L Glade -o manjaro-hello.pot *.glade

Binary file not shown.

View File

@ -7,11 +7,11 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-12-08 17:07+0100\n" "POT-Creation-Date: 2016-12-09 17:26+0100\n"
"PO-Revision-Date: 2016-12-08 17:09+0100\n" "PO-Revision-Date: 2016-12-09 17:26+0100\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: fr\n" "Language: fr_FR\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
@ -63,11 +63,11 @@ msgstr "SUPPORT"
msgid "PROJECT" msgid "PROJECT"
msgstr "PROJET" msgstr "PROJET"
#: manjaro-hello.glade:178 manjaro-hello.glade:545 #: manjaro-hello.glade:178 manjaro-hello.glade:542
msgid "Read me" msgid "Read me"
msgstr "Lisez moi" msgstr "Lisez moi"
#: manjaro-hello.glade:192 manjaro-hello.glade:585 #: manjaro-hello.glade:192 manjaro-hello.glade:582
msgid "Release info" msgid "Release info"
msgstr "Informations de version" msgstr "Informations de version"
@ -75,7 +75,7 @@ msgstr "Informations de version"
msgid "Wiki" msgid "Wiki"
msgstr "Wiki" msgstr "Wiki"
#: manjaro-hello.glade:220 manjaro-hello.glade:646 #: manjaro-hello.glade:220 manjaro-hello.glade:643
msgid "Get involved" msgid "Get involved"
msgstr "S'investir" msgstr "S'investir"
@ -107,43 +107,30 @@ msgstr "Lancer au démarrage"
msgid "Use Calamares (Graphic method)" msgid "Use Calamares (Graphic method)"
msgstr "Utiliser Calamares (Méthode graphique)" msgstr "Utiliser Calamares (Méthode graphique)"
#: manjaro-hello.glade:458 #: manjaro-hello.glade:457
msgid "Use CLI-Installer (Command line)" msgid "Use CLI-Installer (Command line)"
msgstr "Utiliser CLI-Installer (Ligne de commande)" msgstr "Utiliser CLI-Installer (Ligne de commande)"
#: manjaro-hello.glade:482 #: manjaro-hello.glade:479
msgid "INSTALLATION" msgid "INSTALLATION"
msgstr "INSTALLATION" msgstr "INSTALLATION"
#: manjaro-hello.glade:501 #: manjaro-hello.glade:498
msgid "Welcome" msgid "Welcome"
msgstr "Bienvenue" msgstr "Bienvenue"
#: manjaro-hello.glade:601 #: manjaro-hello.glade:598
msgid "Documentation" msgid "Documentation"
msgstr "Documentation" msgstr "Documentation"
#: manjaro-hello.glade:667 #: manjaro-hello.glade:664
msgid "Project" msgid "Project"
msgstr "Projet" msgstr "Projet"
#~ msgid "SOCIAL" #: manjaro-hello.glade:687
#~ msgstr "SOCIAL" msgid "English (United States)"
msgstr "Anglais (États-Unis)"
#~ msgid "Google+" #: manjaro-hello.glade:688
#~ msgstr "Google+" msgid "French (France)"
msgstr "Français (France)"
#~ msgid "Facebook"
#~ msgstr "Facebook"
#~ msgid "Twitter"
#~ msgstr "Twitter"
#~ msgid "Reddit"
#~ msgstr "Reddit"
#~ msgid "Support"
#~ msgstr "Support"
#~ msgid "Social"
#~ msgstr "Social"

View File

@ -679,6 +679,19 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title">Manjaro Hello</property> <property name="title">Manjaro Hello</property>
<property name="show_close_button">True</property> <property name="show_close_button">True</property>
<child>
<object class="GtkComboBoxText" id="languages">
<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>
</items>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="visible">True</property> <property name="visible">True</property>
@ -689,6 +702,7 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</object> </object>
<packing> <packing>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">1</property>
</packing> </packing>
</child> </child>
</object> </object>

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -118,3 +118,11 @@ msgstr ""
#: manjaro-hello.glade:664 #: manjaro-hello.glade:664
msgid "Project" msgid "Project"
msgstr "" msgstr ""
#: manjaro-hello.glade:687
msgid "English (United States)"
msgstr ""
#: manjaro-hello.glade:688
msgid "French (France)"
msgstr ""

View File

@ -15,30 +15,8 @@ class ManjaroHello():
def __init__(self): def __init__(self):
# App vars # App vars
self.app = "manjaro-hello" self.app = "manjaro-hello"
self.default_locale = "en_US"
# Path vars self.sys_locale = locale.getlocale()[0]
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.social_urls = { self.social_urls = {
"google+": "https://plus.google.com/118244873957924966264", "google+": "https://plus.google.com/118244873957924966264",
"facebook": "https://www.facebook.com/ManjaroLinux", "facebook": "https://www.facebook.com/ManjaroLinux",
@ -46,31 +24,68 @@ class ManjaroHello():
"reddit": "https://www.reddit.com/r/ManjaroLinux" "reddit": "https://www.reddit.com/r/ManjaroLinux"
} }
# Init language # Path vars
locale.setlocale(locale.LC_ALL, "") config_path = os.path.expanduser("~") + "/.config/"
locale.bindtextdomain(self.app, self.locale_dir) #share_path = "/usr/share/"
gettext.bindtextdomain(self.app, self.locale_dir) self.preferences_path = config_path + self.app + ".json"
gettext.textdomain(self.app) 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 = Gtk.Builder()
self.builder.set_translation_domain(self.app) self.builder.set_translation_domain(self.app)
self.builder.add_from_file("manjaro-hello.glade") self.builder.add_from_file("manjaro-hello.glade")
self.builder.connect_signals(self) self.builder.connect_signals(self)
self.window = self.builder.get_object("window") 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 # Set window subtitle
if self.infos["codename"] and self.infos["release"]: 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["codename"] + " " + self.infos["release"] + " "
self.builder.get_object("headerbar").props.subtitle += self.infos["arch"] 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 # Set autostart switcher state
self.builder.get_object("autostart").set_active(self.preferences["autostart"]) 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 # Live systems
if self.infos["live"]: if self.infos["live"]:
can_install = False can_install = False
@ -114,10 +129,9 @@ class ManjaroHello():
return None return None
def read_page(self, name): def read_page(self, name):
filename = "pages/{}/{}".format(self.language, name) filename = "pages/{}/{}".format(self.preferences["locale"], name)
if not os.path.isfile(filename): if not os.path.isfile(filename):
filename = "pages/{}/{}".format(self.default_language, name) filename = "pages/{}/{}".format("en_US", name)
try: try:
with open(filename, "r") as f: with open(filename, "r") as f:
return f.read() return f.read()
@ -125,6 +139,11 @@ class ManjaroHello():
return None return None
# Handlers # 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): def on_about_clicked(self, btn):
dialog = self.builder.get_object("aboutdialog") dialog = self.builder.get_object("aboutdialog")
dialog.set_transient_for(self.window) dialog.set_transient_for(self.window)