Improve translation system

This commit is contained in:
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:
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 ""
"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)"

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="title">Manjaro Hello</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>
<object class="GtkButton">
<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>
<packing>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View File

@ -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)