Add all the hooks required for translation

pull/145/head
Peter Hutterer 2019-07-16 21:48:37 +10:00
parent 5e0b7762d6
commit 7677ce60eb
7 changed files with 85 additions and 18 deletions

1
po/LINGUAS Normal file
View File

@ -0,0 +1 @@
# Language list must be in alphabetical order

19
po/POTFILES Normal file
View File

@ -0,0 +1,19 @@
data/org.freedesktop.TuhiGui.appdata.xml.in.in
data/org.freedesktop.TuhiGui.desktop.in
data/ui/AboutDialog.ui.in
data/ui/Drawing.ui
data/ui/DrawingPerspective.ui
data/ui/ErrorPerspective.ui
data/ui/MainWindow.ui
data/ui/SetupPerspective.ui
tuhigui/application.py
tuhigui/config.py
tuhigui/drawing.py
tuhigui/drawingperspective.py
tuhigui/errorperspective.py
tuhigui/setupdialog.py
tuhigui/svg.py
tuhigui/tuhi.py
tuhigui/window.py

37
po/README.md Normal file
View File

@ -0,0 +1,37 @@
i18n
====
This directory contains the translations of TuhiGui.
For errors in translations, please [file an
issue](https://github.com/tuhiproject/tuhi/issues/new).
New or updated translations are always welcome. To start a new translation, run:
$ meson translation-build
$ ninja -C translation-build tuhigui-pot
# Now you can optionally remove the build directory
$ rm -rf translation-build
$ cp po/tuhigui.pot po/$lang.po
where `$lang` is the language code of your target language, e.g. `nl` for Dutch
or `en_GB` for British English. Edit the
[LINGUAS](https://github.com/tuhiproject/tuhigui/blob/master/po/LINGUAS) file and
add your language code, keeping the list sorted alphabetically. Finally, open
the `.po` file you just created and translate all the strings. Don't forget to
fill in the information in the header!
To update an existing translation, run:
$ meson translation-build
$ ninja -C translation-build tuhigui-update-po
# Now you can optionally remove the build directory
$ rm -rf translation-build
and update the `po/$lang.po` file of your target language.
When you are done translating, file a pull request on
[GitHub](https://github.com/tuhiproject/tuhi) or, if you don't know how to, [open
an issue](https://github.com/tuhiproject/tuhi/issues/new) and attach the `.po`
file there.

View File

@ -10,6 +10,8 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
from gettext import gettext as _
from gi.repository import GObject, Gtk
from .config import Config
@ -27,9 +29,9 @@ def relative_date(timestamp):
diff = t - today
if diff.days == 0:
return 'Today'
return _('Today')
if diff.days == -1:
return 'Yesterday'
return _('Yesterday')
if diff.days > -4: # last 4 days we convert to weekdays
return t.strftime('%A')
@ -68,20 +70,23 @@ class Drawing(Gtk.Box):
@Gtk.Template.Callback('_on_download_button_clicked')
def _on_download_button_clicked(self, button):
dialog = Gtk.FileChooserDialog('Please choose a file',
dialog = Gtk.FileChooserDialog(_('Please choose a file'),
None,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
dialog.set_do_overwrite_confirmation(True)
dialog.set_current_name('untitled.svg')
# Translators: the default filename to save to
dialog.set_current_name(_('untitled.svg'))
filter_any = Gtk.FileFilter()
filter_any.set_name('Any files')
# Translators: filter name to show all/any files
filter_any.set_name(_('Any files'))
filter_any.add_pattern('*')
filter_svg = Gtk.FileFilter()
filter_svg.set_name('SVG files')
# Translators: filter to show svg files only
filter_svg.set_name(_('SVG files'))
filter_svg.add_pattern('*.svg')
dialog.add_filter(filter_svg)
dialog.add_filter(filter_any)

View File

@ -11,6 +11,7 @@
# GNU General Public License for more details.
#
from gettext import gettext as _
from gi.repository import GObject, Gtk
from .drawing import Drawing
from .config import Config
@ -32,19 +33,22 @@ def relative_time(seconds):
WEEK = 7 * DAY
if seconds < 30:
return 'just now'
return _('just now')
if seconds < 5 * MIN:
return 'a few minutes ago'
return _('a few minutes ago')
if seconds < H:
return f'{int(seconds/MIN/10) * 10} minutes ago'
minutes = int(seconds / MIN / 10) * 10
return _(f'{minutes} minutes ago')
if seconds < DAY:
return f'{int(seconds/H)} hours ago'
hours = int(seconds / H)
return _(f'{hours} hours ago')
if seconds < 4 * WEEK:
return f'{int(seconds/DAY)} days ago'
days = int(seconds / DAY)
return _(f'{days} days ago')
if seconds > 10 * 365 * DAY:
return 'never'
return _('never')
return 'a long time ago'
return _('a long time ago')
@Gtk.Template(resource_path="/org/freedesktop/TuhiGui/ui/DrawingPerspective.ui")

View File

@ -11,6 +11,7 @@
# GNU General Public License for more details.
#
from gettext import gettext as _
from gi.repository import GObject, Gtk
import gi
@ -39,7 +40,7 @@ class SetupDialog(Gtk.Dialog):
def _on_unregistered_device(self, tuhi, device):
tuhi.disconnect(self._sig)
self.label_devicename_p1.set_text(f'Connecting to {device.name}')
self.label_devicename_p1.set_text(_(f'Connecting to {device.name}'))
self.stack.set_visible_child_name('page1')
self._sig = device.connect('button-press-required', self._on_button_press_required)
device.register()

View File

@ -32,23 +32,23 @@ MENU_XML = """
<menu id="primary-menu">
<section>
<item>
<attribute name="label">Portrait</attribute>
<attribute name="label" translatable="yes">Portrait</attribute>
<attribute name="action">win.orientation</attribute>
<attribute name="target">portrait</attribute>
</item>
<item>
<attribute name="label">Landscape</attribute>
<attribute name="label" translatable="yes">Landscape</attribute>
<attribute name="action">win.orientation</attribute>
<attribute name="target">landscape</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">Help</attribute>
<attribute name="label" translatable="yes">Help</attribute>
<attribute name="action">app.help</attribute>
</item>
<item>
<attribute name="label">About</attribute>
<attribute name="label" translatable="yes">About</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>