Commit d5e46eb4 authored by GabMus's avatar GabMus

initial translation infrastructure

parent c42fd5b9
......@@ -21,6 +21,7 @@ import os
import sys
import signal
import gettext
import locale
sys.path.insert(1, '@pythondir@')
......@@ -36,7 +37,16 @@ if builddir:
signal.signal(signal.SIGINT, signal.SIG_DFL)
# gettext.install('trg', localedir)
# Why both locale and gettext?
# gettext works for the python part
# but not for the glade/xml files
# they need locale
# don't ask me, it's effin weird
# I copied this from uberwriter
locale.bindtextdomain('hydrapaper', localedir)
gettext.bindtextdomain('hydrapaper', localedir)
if __name__ == '__main__':
import gi
......@@ -4,6 +4,7 @@ conf.set('localedir', join_paths(prefix, get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir)
conf.set('PYTHON', python.find_python().path())
conf.set('pythondir', join_paths(prefix, pythondir))
conf.set('localedir', join_paths(prefix, localedir))
conf.set('projectname', meson.project_name())
conf.set('authorfullname', authorfullname)
conf.set('authoremail', authoremail)
......@@ -92,6 +92,7 @@ appdata_conf = configuration_data()
appdata_conf.set('description', description)
appdata_conf.set('authorfullname', authorfullname)
appdata_conf.set('gitrepo', gitrepo)
appdata_conf.set('website', website)
appdata_conf.set('authoremail', authoremail)
appdata_conf.set('prettyname', prettyname)
appdata_conf.set('appid', app_id)
......@@ -19,7 +19,7 @@
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">Add a wallpapers folder</property>
<property name="title" translatable="yes">Add a wallpapers folder</property>
<object class="GtkButton" id="addFolderFileChooserDialogCancelButton">
<property name="label">gtk-cancel</property>
......@@ -3,25 +3,25 @@
<menu id="generalMenu">
<attribute name="label">Set random wallpapers</attribute>
<attribute name="label" translatable="yes">Set random wallpapers</attribute>
<attribute name="action">app.set_random_wallpaper</attribute>
<attribute name="label">Settings</attribute>
<attribute name="label" translatable="yes">Settings</attribute>
<attribute name="action">app.settings</attribute>
<attribute name="label">Shortcuts</attribute>
<attribute name="label" translatable="yes">Shortcuts</attribute>
<attribute name="action">app.shortcuts</attribute>
<attribute name="label">About</attribute>
<attribute name="label" translatable="yes">About</attribute>
<attribute name="action">app.about</attribute>
<attribute name="label">Quit</attribute>
<attribute name="label" translatable="yes">Quit</attribute>
<attribute name="action">app.quit</attribute>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface domain="hydrapaper">
<requires lib="gtk+" version="3.20"/>
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
......@@ -137,7 +137,7 @@
<object class="GtkButton" id="resetFavoritesButton">
<property name="label">Clear favorites</property>
<property name="label" translatable="yes">Clear favorites</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
......@@ -34,7 +34,7 @@
<object class="GtkButton" id="favoriteBtn">
<property name="label" translatable="yes">❤️ Add favorite</property>
<property name="label" translatable="yes">Add favorite</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
......@@ -77,7 +77,6 @@
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="max_width_chars">30</property>
<property name="text" translatable="yes">/home/gabmus/Pictures/Wallpapers/some/other/folder/wp.jpg</property>
......@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
from gettext import gettext as _
import sys
import argparse
from gi.repository import Gtk, Gio
......@@ -117,14 +118,14 @@ class HydraPaperApplication(Gtk.Application):
monitors = build_monitors_from_gdk()
if len(wlist_cli) < len(monitors):
'Error: you passed {0} wallpapers for {1} monitors'.format(
_('Error: you passed {0} wallpapers for {1} monitors').format(
len(wlist_cli), len(monitors)
for wpath in wlist_cli:
if not is_image(wpath):
print('Error: {0} is not a valid image path'.format(wpath))
print(_('Error: {0} is not a valid image path').format(wpath))
for monitor, n_wp in zip(monitors, wlist_cli):
monitor.wallpaper = n_wp
......@@ -158,8 +159,8 @@ class HydraPaperApplication(Gtk.Application):
Gtk.Application.do_command_line(self, args) # call the default commandline handler
# make a command line parser
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--cli', dest='wallpaper_path', nargs='+', action='append', help='set wallpapers from command line')
parser.add_argument('-r', '--random', dest='set_random', action='store_true', help='set wallpapers randomly')
parser.add_argument('-c', '--cli', dest='wallpaper_path', nargs='+', action='append', help=_('set wallpapers from command line'))
parser.add_argument('-r', '--random', dest='set_random', action='store_true', help=_('set wallpapers randomly'))
# parse the command line stored in args, but skip the first element (the filename)
self.args = parser.parse_args(args.get_arguments()[1:])
# call the main program do_activate() to start up the app
from gettext import gettext as _
from os import environ as Env
from os.path import isfile
from hashlib import sha256
......@@ -28,7 +29,7 @@ def _apply_wallpapers_worker(monitors):
if isfile(save_path):
print(f'Hit cache for {save_path}. Skipping merge')
print(_('Hit cache for {0}. Skipping merge').format(save_path))
multi_setup_pillow(monitors, save_path)
from gettext import gettext as _
from gi.repository import Gtk
from .wallpapers_flowbox import HydraPaperWallpapersFlowbox
......@@ -8,6 +9,6 @@ class HydraPapaerMainStack(Gtk.Stack):
self.main_flowbox = HydraPaperWallpapersFlowbox()
self.favs_flowbox = HydraPaperWallpapersFlowbox(is_favorites = True)
self.add_titled(self.main_flowbox, 'Wallpapers', 'Wallpapers')
self.add_titled(self.favs_flowbox, 'Favorites', 'Favorites')
self.add_titled(self.main_flowbox, 'Wallpapers', _('Wallpapers'))
self.add_titled(self.favs_flowbox, 'Favorites', _('Favorites'))
from gettext import gettext as _
from gi.repository import Gdk
class Monitor:
......@@ -40,7 +41,7 @@ def build_monitors_from_gdk():
except Exception as e:
print('Error parsing monitors (Gdk)')
print(_('Error parsing monitors (Gdk)'))
import traceback
monitors = None
from gettext import gettext as _
from gi.repository import Gtk, Gdk, Gio, GdkPixbuf
import os
from . import threading_helper as ThreadingHelper
......@@ -74,5 +75,5 @@ class WallpaperBox(Gtk.FlowBoxChild):
thumb.thumbnail((250, 250), Image.ANTIALIAS), 'PNG')
except IOError:
print('ERROR: cannot create thumbnail for file', self.wallpaper_path)
print(_('ERROR: cannot create thumbnail for file'), self.wallpaper_path)
return self.cache_path
from gettext import gettext as _
from gi.repository import Gtk
from .confManager import ConfManager
from .wallpaper_flowbox_item import WallpaperBox
......@@ -104,9 +105,9 @@ class HydraPaperWallpapersFlowbox(Gtk.Bin):
if self.is_favorites or self.child_at_pos.is_fav:
self.favorite_btn.set_label('💔 Remove favorite')
self.favorite_btn.set_label(_('Remove favorite'))
self.favorite_btn.set_label('❤️ Add favorite')
self.favorite_btn.set_label(_('Add favorite'))
wp_path = self.child_at_pos.get_child().wallpaper_path
version: '1.7.3',
meson_version: '>= 0.40.0',
meson_version: '>= 0.50.0',
license: 'GPL3'
......@@ -30,10 +30,12 @@ bindir = get_option('bindir') # should be bin
datadir = get_option('datadir') # should be /usr/share
pkgdatadir = join_paths(prefix, datadir, meson.project_name())
pythondir = join_paths(prefix, python.sysconfig_path('purelib'))
localedir = join_paths(prefix, get_option('localedir'))
install_subdir(meson.project_name(), install_dir: pythondir)
# Please keep this list alphabetically sorted
data/ui/menu.xml data/ui/
data/ui/menu.xml data/ui/shortcutsWindow.xml
# Italian translations for HydraPaper package.
# Copyright (C) 2019 THE HydraPaper'S COPYRIGHT HOLDER
# This file is distributed under the same license as the HydraPaper package.
# Gabriele Musco <>, 2019.
msgid ""
msgstr ""
"Project-Id-Version: HydraPaper \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-14 11:23+0200\n"
"PO-Revision-Date: 2019-07-13 13:17+0200\n"
"Last-Translator: Gabriele Musco <>\n"
"Language-Team: Italian\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: ../hydrapaper/
msgid "ERROR: cannot create thumbnail for file"
msgstr "ERRORE: impossibile creare miniatura per il file"
#: ../hydrapaper/
msgid "Error parsing monitors (Gdk)"
msgstr "Errore nell'analisi dei monitor (Gdk)"
#: ../hydrapaper/
#, python-brace-format
msgid "Error: you passed {0} wallpapers for {1} monitors"
msgstr "Errore: hai passato {0} sfondi per {1} monitor"
#: ../hydrapaper/
#, python-brace-format
msgid "Error: {0} is not a valid image path"
msgstr "Errore: {0} non è il percorso di un'immagine valida"
#: ../hydrapaper/
msgid "set wallpapers from command line"
msgstr "imposta sfondi dalla linea di comando"
#: ../hydrapaper/
msgid "set wallpapers randomly"
msgstr "imposta sfondi casualmente"
#: ../hydrapaper/
msgid "Wallpapers"
msgstr "Sfondi"
#: ../hydrapaper/
msgid "Favorites"
msgstr "Preferiti"
#: ../hydrapaper/
#, python-brace-format
msgid "Hit cache for {0}. Skipping merge"
msgstr "Collisione cache per {0}. Sto saltando l'unione"
#: ../hydrapaper/
msgid "Remove favorite"
msgstr "Rimuovi preferito"
#: ../hydrapaper/
msgid "Add favorite"
msgstr "Aggiungi preferito"
#: ../data/ui/menu.xml:6
msgid "Set random wallpapers"
msgstr "Imposta sfondi casualmente"
#: ../data/ui/menu.xml:12 ../data/ui/
msgid "Settings"
msgstr "Preferenze"
#: ../data/ui/menu.xml:16
msgid "Shortcuts"
msgstr "Scorciatoie"
#: ../data/ui/menu.xml:20
msgid "About"
msgstr "Informazioni"
#: ../data/ui/menu.xml:24 ../data/ui/shortcutsWindow.xml:13
msgid "Quit"
msgstr "Esci"
#: ../data/ui/
msgid "Add a wallpapers folder"
msgstr "Aggiungi una cartella di sfondi"
#: ../data/ui/
msgid "Selected path has already been added"
msgstr "Il percorso selezionato è già stato aggiunto"
#: ../data/ui/
msgid "Close\n"
msgstr "Chiudi\n"
#: ../data/ui/shortcutsWindow.xml:9
msgid "General"
msgstr "Generale"
#: ../data/ui/
msgid "Select wallpapers with a double click"
msgstr "Seleziona gli sfondi con un doppio click"
#: ../data/ui/
msgid "Keep favorites in main wallpapers view"
msgstr "Mantieni i preferiti nella vista principale degli sfondi"
#: ../data/ui/
msgid "Clear all favorites"
msgstr "Pulisci tutti i preferiti"
#: ../data/ui/
msgid "Clear favorites"
msgstr "Pulisci i preferiti"
#: ../data/ui/
msgid "Clear all caches"
msgstr "Pulisci tutte le cache"
#: ../data/ui/
msgid "Clear caches"
msgstr "Pulisci le cache"
#: ../data/ui/
msgid "Add"
msgstr "Aggiungi"
#: ../data/ui/
msgid "Remove"
msgstr "Rimuovi"
#: ../data/ui/
msgid "Lower all other windows"
msgstr "Abbassa tutte le altre finestre"
#: ../data/ui/
msgid "Apply"
msgstr "Applica"
#: ../data/ui/
msgid "title"
msgstr "titolo"
#: ../data/ui/
msgid "Path:"
msgstr "Percorso:"
i18n = import('i18n')
message('Update translations')
preset: 'glib'
rm *.pot
find ../hydrapaper -iname "*.py" | xargs xgettext --from-code=UTF-8 --output=hydrapaper-python.pot
find ../data/ui -iname "*.glade" -or -iname "*.xml" | xargs xgettext --from-code=UTF-8 --output=hydrapaper-glade.pot -L Glade
msgcat --use-first hydrapaper-python.pot hydrapaper-glade.pot > hydrapaper.pot
version=$(fgrep "version: " ../ | grep -v "meson" | grep -o "'.*'" | sed "s/'//g")
sed -i "s/PACKAGE/HydraPaper/g;s/VERSION/$version/g" hydrapaper.pot
sed 's/#: //g;s/:[0-9]*//g;s/\.\.\///g' <(fgrep "#: " hydrapaper.pot) | sort | uniq >
echo "# Please keep this list alphabetically sorted" > LINGUAS
for l in $(ls *.po); do basename $l .po >> LINGUAS; done
for lang in $(sed "s/^#.*$//g" LINGUAS); do
mv "${lang}.po" "${lang}.po.old"
msginit --locale=$lang --input hydrapaper.pot
mv "${lang}.po" "${lang}"
msgmerge -N "${lang}.po.old" "${lang}" > ${lang}.po
rm "${lang}.po.old" "${lang}"
rm *.pot
# To create lang file use this command
# msginit --locale=LOCALE --input hydrapaper.pot
# where LOCALE is something like `de`, `it`, `es`...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment