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.textdomain('hydrapaper')
locale.bindtextdomain('hydrapaper', localedir)
gettext.textdomain('hydrapaper')
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>
<child>
<object class="GtkButton" id="addFolderFileChooserDialogCancelButton">
<property name="label">gtk-cancel</property>
......
......@@ -3,25 +3,25 @@
<menu id="generalMenu">
<section>
<item>
<attribute name="label">Set random wallpapers</attribute>
<attribute name="label" translatable="yes">Set random wallpapers</attribute>
<attribute name="action">app.set_random_wallpaper</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">Settings</attribute>
<attribute name="label" translatable="yes">Settings</attribute>
<attribute name="action">app.settings</attribute>
</item>
<item>
<attribute name="label">Shortcuts</attribute>
<attribute name="label" translatable="yes">Shortcuts</attribute>
<attribute name="action">app.shortcuts</attribute>
</item>
<item>
<attribute name="label">About</attribute>
<attribute name="label" translatable="yes">About</attribute>
<attribute name="action">app.about</attribute>
</item>
<item>
<attribute name="label">Quit</attribute>
<attribute name="label" translatable="yes">Quit</attribute>
<attribute name="action">app.quit</attribute>
</item>
</section>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<interface domain="hydrapaper">
<requires lib="gtk+" version="3.20"/>
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
......@@ -137,7 +137,7 @@
</child>
<child>
<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 @@
</child>
<child>
<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>
</object>
</child>
</object>
......
......@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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):
print(
'Error: you passed {0} wallpapers for {1} monitors'.format(
_('Error: you passed {0} wallpapers for {1} monitors').format(
len(wlist_cli), len(monitors)
)
)
exit(1)
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))
exit(1)
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):
).hexdigest()
)
if isfile(save_path):
print(f'Hit cache for {save_path}. Skipping merge')
print(_('Hit cache for {0}. Skipping merge').format(save_path))
else:
multi_setup_pillow(monitors, save_path)
set_wallpaper(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'))
self.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
from gettext import gettext as _
from gi.repository import Gdk
class Monitor:
......@@ -40,7 +41,7 @@ def build_monitors_from_gdk():
monitor.is_primary()
))
except Exception as e:
print('Error parsing monitors (Gdk)')
print(_('Error parsing monitors (Gdk)'))
import traceback
traceback.print_exc()
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)
thumb.save(self.cache_path, '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):
self.popover.set_relative_to(self.child_at_pos)
self.flowbox.select_child(self.child_at_pos)
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'))
else:
self.favorite_btn.set_label('❤️ Add favorite')
self.favorite_btn.set_label(_('Add favorite'))
wp_path = self.child_at_pos.get_child().wallpaper_path
self.wallpaper_path_entry.set_text(wp_path)
self.wallpaper_name_label.set_text(pathlib.Path(wp_path).name)
......
project('hydrapaper',
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)
subdir('data')
subdir('bin')
subdir('po')
meson.add_install_script('meson_post_install.py')
# Please keep this list alphabetically sorted
it
data/ui/choose_folder_dialog.glade
data/ui/headerbar.glade
data/ui/menu.xml
data/ui/menu.xml data/ui/settings_window.glade
data/ui/menu.xml data/ui/shortcutsWindow.xml
data/ui/settings_window.glade
data/ui/shortcutsWindow.xml
data/ui/wallpapers_flowbox.glade
data/ui/wallpapers_folders_view.glade
hydrapaper/apply_wallpapers.py
hydrapaper/__main__.py
hydrapaper/main_stack.py
hydrapaper/monitor_parser.py
hydrapaper/wallpaper_flowbox_item.py
hydrapaper/wallpapers_flowbox.py
# 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 <emaildigabry@gmail.com>, 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 <emaildigabry@gmail.com>\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/wallpaper_flowbox_item.py:78
msgid "ERROR: cannot create thumbnail for file"
msgstr "ERRORE: impossibile creare miniatura per il file"
#: ../hydrapaper/monitor_parser.py:44
msgid "Error parsing monitors (Gdk)"
msgstr "Errore nell'analisi dei monitor (Gdk)"
#: ../hydrapaper/__main__.py:121
#, python-brace-format
msgid "Error: you passed {0} wallpapers for {1} monitors"
msgstr "Errore: hai passato {0} sfondi per {1} monitor"
#: ../hydrapaper/__main__.py:128
#, python-brace-format
msgid "Error: {0} is not a valid image path"
msgstr "Errore: {0} non è il percorso di un'immagine valida"
#: ../hydrapaper/__main__.py:162
msgid "set wallpapers from command line"
msgstr "imposta sfondi dalla linea di comando"
#: ../hydrapaper/__main__.py:163
msgid "set wallpapers randomly"
msgstr "imposta sfondi casualmente"
#: ../hydrapaper/main_stack.py:12
msgid "Wallpapers"
msgstr "Sfondi"
#: ../hydrapaper/main_stack.py:13
msgid "Favorites"
msgstr "Preferiti"
#: ../hydrapaper/apply_wallpapers.py:32
#, python-brace-format
msgid "Hit cache for {0}. Skipping merge"
msgstr "Collisione cache per {0}. Sto saltando l'unione"
#: ../hydrapaper/wallpapers_flowbox.py:108
msgid "Remove favorite"
msgstr "Rimuovi preferito"
#: ../hydrapaper/wallpapers_flowbox.py:110
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/settings_window.glade:8
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/choose_folder_dialog.glade:22
msgid "Add a wallpapers folder"
msgstr "Aggiungi una cartella di sfondi"
#: ../data/ui/choose_folder_dialog.glade:89
msgid "Selected path has already been added"
msgstr "Il percorso selezionato è già stato aggiunto"
#: ../data/ui/choose_folder_dialog.glade:106
msgid "Close\n"
msgstr "Chiudi\n"
#: ../data/ui/shortcutsWindow.xml:9
msgid "General"
msgstr "Generale"
#: ../data/ui/settings_window.glade:30
msgid "Select wallpapers with a double click"
msgstr "Seleziona gli sfondi con un doppio click"
#: ../data/ui/settings_window.glade:80
msgid "Keep favorites in main wallpapers view"
msgstr "Mantieni i preferiti nella vista principale degli sfondi"
#: ../data/ui/settings_window.glade:130
msgid "Clear all favorites"
msgstr "Pulisci tutti i preferiti"
#: ../data/ui/settings_window.glade:140
msgid "Clear favorites"
msgstr "Pulisci i preferiti"
#: ../data/ui/settings_window.glade:184
msgid "Clear all caches"
msgstr "Pulisci tutte le cache"
#: ../data/ui/settings_window.glade:194
msgid "Clear caches"
msgstr "Pulisci le cache"
#: ../data/ui/wallpapers_folders_view.glade:51
msgid "Add"
msgstr "Aggiungi"
#: ../data/ui/wallpapers_folders_view.glade:73
msgid "Remove"
msgstr "Rimuovi"
#: ../data/ui/headerbar.glade:29
msgid "Lower all other windows"
msgstr "Abbassa tutte le altre finestre"
#: ../data/ui/headerbar.glade:60
msgid "Apply"
msgstr "Applica"
#: ../data/ui/wallpapers_flowbox.glade:19
msgid "title"
msgstr "titolo"
#: ../data/ui/wallpapers_flowbox.glade:61
msgid "Path:"
msgstr "Percorso:"
i18n = import('i18n')
message('Update translations')
i18n.gettext(meson.project_name(),
preset: 'glib'
)
#!/bin/bash
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: " ../meson.build | 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 > POTFILES.in
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}.po.new"
msgmerge -N "${lang}.po.old" "${lang}.po.new" > ${lang}.po
rm "${lang}.po.old" "${lang}.po.new"
done
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