Skip to content

Commit

Permalink
Merge pull request #1977 from jimklimov/msgfmt
Browse files Browse the repository at this point in the history
Use `msgfmt` to "compile" translations for NUT-Monitor (Python GUI app)
  • Loading branch information
jimklimov authored Jul 3, 2023
2 parents 470ede8 + 3317d55 commit 7d4745c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,12 @@ dnl installing these features or not.
dnl Note: more for tests than other reasons, there is also an option
dnl value to "force" the installation.

dnl The gettext "msgfmt" tool (or equivalent) can be used to maintain
dnl human-language text translations. Currently this is used specifically
dnl in the Python NUT-Monitor app sources (*.po => *.mo conversions).
AC_PATH_PROGS([MSGFMT], [msgfmt], [none])
AM_CONDITIONAL([HAVE_MSGFMT], [test "x${MSGFMT}" != "xnone"])

dnl ----------------------------------------------------------------------
dnl checks related to --with-serial

Expand Down
9 changes: 9 additions & 0 deletions docs/config-prereqs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ metadata about recently published package revisions:
# :; apt-get install python3 python3.9
# You can find a list of what is (pre-)installed with:
# :; dpkg -l | grep -Ei 'perl|python'
#
# For localization maintenance (currently in Python NUT-Monitor app),
# provide an `msgfmt` implementation, e.g.:
# :; apt-get install gettext
#
# To install the Python NUT-Monitor app, you may need some modules:
# :; apt-get install pip
# For Python3:
# :; python3 -m pip install PyQt5 configparser

# For spell-checking, highly recommended if you would propose pull requests:
:; apt-get install \
Expand Down
6 changes: 5 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3185 utf-8
personal_ws-1.1 en 3189 utf-8
AAS
ABI
ACFAIL
Expand Down Expand Up @@ -976,6 +976,7 @@ PwrOut
PyGTK
PyNUT
PyNUTClient
PyQt
QBDR
QBT
QBV
Expand Down Expand Up @@ -1710,6 +1711,7 @@ compat
compilerPath
conf
config
configparser
configs
configurationProvider
configureaz
Expand Down Expand Up @@ -1983,6 +1985,7 @@ getconf
getent
getenv
getopt
gettext
getvar
gitcache
github
Expand Down Expand Up @@ -2358,6 +2361,7 @@ monuser
morbo
mozilla
msec
msgfmt
msi
msvcrt
msys
Expand Down
32 changes: 31 additions & 1 deletion scripts/python/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ PYTHON3_SITE_PACKAGES = @PYTHON3_SITE_PACKAGES@

BINDIR = @BINDIR@

if HAVE_MSGFMT
MSGFMT = @MSGFMT@
endif HAVE_MSGFMT

NUT_MONITOR_PY2GTK2 = \
app/ui/gui-1.3.glade \
app/nut-monitor-py2gtk2.desktop
Expand Down Expand Up @@ -71,7 +75,7 @@ PYNUT_COMMON = \
module/README

# Note: we both distribute and install the generated *.mo translation files
# so they are listed above and not in NUT_MONITOR_COMMON_GENERATED
# so they are listed above and not in NUT_MONITOR_COMMON_TEMPLATE
NUT_MONITOR_COMMON_TEMPLATE = \
app/locale/NUT-Monitor.pot \
app/locale/fr/fr.po \
Expand Down Expand Up @@ -113,6 +117,32 @@ nutmonitordir = $(nut_with_nut_monitor_dir)
nobase_nutmonitor_DATA = $(NUT_MONITOR_DISPATCHER_NOEXEC) $(NUT_MONITOR_COMMON)
nobase_nutmonitor_SCRIPTS = $(NUT_MONITOR_DISPATCHER_SCRIPT)

if HAVE_MSGFMT
# Note lack of "$<" below - it is a non-portable GNU Make extension
# The POT-Creation-Date: is removed by current python gettext builder to avoid
# "spurious" changes that do not benefit (otherwise unmodified) contents; see:
# https://github.com/sphinx-doc/sphinx/pull/3490
# https://github.com/sphinx-doc/sphinx/issues/3443
# Note that OUTFILE may be in builddir (not necessarily same as srcdir)
ACT_MSGFMT = { \
$(GREP) -v -E '^.?POT-Creation-Date: ' < "$${SRCFILE}" > "$${OUTFILE}.tmpsrc" && \
$(MSGFMT) -o "$${OUTFILE}" "$${OUTFILE}.tmpsrc" && \
rm -f "$${OUTFILE}.tmpsrc" ; \
}

app/locale/fr/LC_MESSAGES/NUT-Monitor.mo: app/locale/fr/fr.po
@$(MKDIR_P) "$(builddir)/app/locale/fr/LC_MESSAGES"
SRCFILE="$^"; OUTFILE="$@"; $(ACT_MSGFMT)

app/locale/it/LC_MESSAGES/NUT-Monitor.mo: app/locale/it/it.po
@$(MKDIR_P) "$(builddir)/app/locale/it/LC_MESSAGES"
SRCFILE="$^"; OUTFILE="$@"; $(ACT_MSGFMT)

app/locale/ru/LC_MESSAGES/NUT-Monitor.mo: app/locale/ru/ru.po
@$(MKDIR_P) "$(builddir)/app/locale/ru/LC_MESSAGES"
SRCFILE="$^"; OUTFILE="$@"; $(ACT_MSGFMT)
endif HAVE_MSGFMT

if WITH_NUT_MONITOR_PY2GTK2
nobase_nutmonitor_DATA += $(NUT_MONITOR_PY2GTK2)
nobase_nutmonitor_SCRIPTS += $(NUT_MONITOR_PY2GTK2_GENERATED_SCRIPT)
Expand Down
Binary file modified scripts/python/app/locale/fr/LC_MESSAGES/NUT-Monitor.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/python/app/locale/fr/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Project-Id-Version: NUT Monitor\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-10-14 22:47+0200\n"
"PO-Revision-Date: 2013-10-14 22:50+0200\n"
Expand Down
Binary file modified scripts/python/app/locale/it/LC_MESSAGES/NUT-Monitor.mo
Binary file not shown.
Binary file modified scripts/python/app/locale/ru/LC_MESSAGES/NUT-Monitor.mo
Binary file not shown.

0 comments on commit 7d4745c

Please sign in to comment.