From: Bruno Haible Date: Sun, 18 Aug 2019 11:27:30 +0000 (+0200) Subject: Don't extract Icon values from .desktop files into POT files. X-Git-Tag: v0.20.2~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5004837372309ce19e40b2ccbe5293dfe268329;p=thirdparty%2Fgettext.git Don't extract Icon values from .desktop files into POT files. Reported by Piotr Drąg at and by Will Thompson at . There was a discussion starting at . The most interesting posts in this thread were . * gettext-tools/doc/gettext.texi (Icons): New subsubsection. * gettext-tools/src/read-desktop.c (desktop_add_default_keywords): Don't add "Icon". * gettext-tools/src/x-desktop.c: Update comments. * gettext-tools/doc/xgettext.texi (Desktop): Remove 'Icon' from the list of extracted keys. * gettext-tools/tests/xgettext-desktop-2: New file. * gettext-tools/tests/msgfmt-desktop-3: New file. * gettext-tools/tests/Makefile.am (TESTS): Add them. * NEWS: Mention the change. --- diff --git a/NEWS b/NEWS index f8ad81ed0..8913a61a3 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ Version 0.20.2 - April 2020 +* Programming languages support: + - Desktop Entry: + The value of the 'Icon' property is no longer extracted into the POT file + by xgettext. The documentation explains how to localize icons. + * Runtime behaviour: - Fixed a multithread-safety bug on Cygwin and native Windows. diff --git a/gettext-tools/doc/gettext.texi b/gettext-tools/doc/gettext.texi index 310c9f70e..87c903af2 100644 --- a/gettext-tools/doc/gettext.texi +++ b/gettext-tools/doc/gettext.texi @@ -12730,6 +12730,60 @@ desktop entry file. For more information, see the example @code{hello-c-gnome3}. +@menu +* Icons:: Handling icons +@end menu + +@node Icons +@subsubsection How to handle icons in Desktop Entry files + +Icons are generally locale dependent, for the following reasons: + +@itemize @bullet +@item +Icons may contain signs that are considered rude in some cultures. For +example, the high-five sign, in some cultures, is perceived as an +unfriendly ``stop'' sign. +@item +Icons may contain metaphors that are culture specific. For example, a +mailbox in the U.S. looks different than mailboxes all around the world. +@item +Icons may need to be mirrored for right-to-left locales. +@item +Icons may contain text strings (a bad practice, but anyway). +@end itemize + +However, icons are not covered by GNU gettext localization, because +@itemize @bullet +@item +Icons cannot be easily embedded in PO files, +@item +The need to localize an icon is rare, and the ability to do so in a PO +file would introduce translator mistakes. +@c https://lists.freedesktop.org/archives/xdg/2019-June/014168.html +@end itemize + +Desktop Entry files may contain an @samp{Icon} property, and this +property is localizable. If a translator wishes to localize an icon, +she should do so by bypassing the normal workflow with PO files: +@enumerate +@item +The translator contacts the package developers directly, sending them +the icon appropriate for her locale, with a request to change the +template file. +@item +The package developers add the icon file to their repository, and a +line +@smallexample +Icon[@var{locale}]=@var{icon_file_name} +@end smallexample +@noindent +to the template file. +@end enumerate +@noindent +This line remains in place when this template file is merged with the +translators' PO files, through @code{msgfmt}. + @node XML @subsection XML files diff --git a/gettext-tools/doc/xgettext.texi b/gettext-tools/doc/xgettext.texi index 7a8b516a8..f12af6aca 100644 --- a/gettext-tools/doc/xgettext.texi +++ b/gettext-tools/doc/xgettext.texi @@ -345,7 +345,7 @@ For Vala: @code{_}, @code{Q_}, @code{N_}, @code{NC_}, @code{dgettext:2}, @item For Desktop: @code{Name}, @code{GenericName}, @code{Comment}, -@code{Icon}, @code{Keywords}. +@code{Keywords}. @end itemize To disable the default keyword specifications, the option @samp{-k} or diff --git a/gettext-tools/src/read-desktop.c b/gettext-tools/src/read-desktop.c index 41bde41e1..4de134f3c 100644 --- a/gettext-tools/src/read-desktop.c +++ b/gettext-tools/src/read-desktop.c @@ -1,5 +1,5 @@ /* Reading Desktop Entry files. - Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009, 2014-2018 Free + Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009, 2014-2019 Free Software Foundation, Inc. This file was written by Daiki Ueno . @@ -640,6 +640,8 @@ desktop_add_default_keywords (hash_table *keywords) desktop_add_keyword (keywords, "Name", false); desktop_add_keyword (keywords, "GenericName", false); desktop_add_keyword (keywords, "Comment", false); +#if 0 /* Icon values are localizable, but not supported by xgettext. */ desktop_add_keyword (keywords, "Icon", false); +#endif desktop_add_keyword (keywords, "Keywords", true); } diff --git a/gettext-tools/src/x-desktop.c b/gettext-tools/src/x-desktop.c index fc3d7e1fa..93e206ee9 100644 --- a/gettext-tools/src/x-desktop.c +++ b/gettext-tools/src/x-desktop.c @@ -1,5 +1,5 @@ /* xgettext Desktop Entry backend. - Copyright (C) 2014, 2018 Free Software Foundation, Inc. + Copyright (C) 2014, 2018-2019 Free Software Foundation, Inc. This file was written by Daiki Ueno , 2014. @@ -51,11 +51,13 @@ /* The syntax of a Desktop Entry file is defined at https://standards.freedesktop.org/desktop-entry-spec/latest/index.html - Basically, values with 'localestring' type can be translated. + Basically, values with 'localestring' type can be localized. + However, the values of 'Icon', while being localizable, are not supported + by xgettext. See the documentation for more info. The type of a value is determined by looking at the key associated with it. The list of available keys are listed on: - https://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html */ + https://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html */ static hash_table keywords; static bool default_keywords = true; diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 6aa3d5636..b200aa342 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -52,7 +52,7 @@ TESTS = gettext-1 gettext-2 \ msgfmt-15 msgfmt-16 msgfmt-17 msgfmt-18 msgfmt-19 \ msgfmt-properties-1 \ msgfmt-qt-1 msgfmt-qt-2 \ - msgfmt-desktop-1 msgfmt-desktop-2 \ + msgfmt-desktop-1 msgfmt-desktop-2 msgfmt-desktop-3 \ msgfmt-xml-1 msgfmt-xml-2 \ msggrep-1 msggrep-2 msggrep-3 msggrep-4 msggrep-5 msggrep-6 msggrep-7 \ msggrep-8 msggrep-9 msggrep-10 msggrep-11 \ @@ -122,7 +122,7 @@ TESTS = gettext-1 gettext-2 \ xgettext-javascript-7 \ xgettext-vala-1 xgettext-vala-2 \ xgettext-gsettings-1 \ - xgettext-desktop-1 \ + xgettext-desktop-1 xgettext-desktop-2 \ xgettext-its-1 xgettext-its-2 \ format-awk-1 format-awk-2 \ format-boost-1 format-boost-2 \ diff --git a/gettext-tools/tests/msgfmt-desktop-3 b/gettext-tools/tests/msgfmt-desktop-3 new file mode 100755 index 000000000..149d9c203 --- /dev/null +++ b/gettext-tools/tests/msgfmt-desktop-3 @@ -0,0 +1,70 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test of Icon handling in Desktop Entry support. + +cat <<\EOF > hello.desktop +[Desktop Entry] +Name=Hello +TryExec=hello +Exec=hello +Icon=handshake.jpg +Icon[en_US]=hifive.jpg +Icon[th]=wai.jpg +Type=Application +Keywords=Utility; +EOF + +cat <<\EOF > th.po +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-08-18 12:45+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: Thai \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: hello.desktop:3 +msgid "Hello" +msgstr "สวัสดี" + +#: hello.desktop:10 +msgid "Utility;" +msgstr "ประโยชน์;" +EOF + +cat <<\EOF > hello.desktop.ok +[Desktop Entry] +Name[th]=สวัสดี +Name=Hello +TryExec=hello +Exec=hello +Icon=handshake.jpg +Icon[en_US]=hifive.jpg +Icon[th]=wai.jpg +Type=Application +Keywords[th]=ประโยชน์; +Keywords=Utility; +EOF + +# Generate the merged .desktop file. + +${MSGFMT} --desktop --template=hello.desktop -l th th.po -o hello.desktop.tmp \ + || Exit 1 +LC_ALL=C tr -d '\r' < hello.desktop.tmp > hello.desktop.out || Exit 1 + +: ${DIFF=diff} +${DIFF} hello.desktop.ok hello.desktop.out +result=$? + +exit $result diff --git a/gettext-tools/tests/xgettext-desktop-2 b/gettext-tools/tests/xgettext-desktop-2 new file mode 100755 index 000000000..a01f7cfae --- /dev/null +++ b/gettext-tools/tests/xgettext-desktop-2 @@ -0,0 +1,55 @@ +#!/bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test of Icon handling in Desktop Entry support. + +: ${XGETTEXT=xgettext} + +cat <<\EOF > hello.desktop +[Desktop Entry] +Name=Hello +TryExec=hello +Exec=hello +Icon=handshake.jpg +Icon[en_US]=hifive.jpg +Icon[th]=wai.jpg +Type=Application +Keywords=Utility; +EOF + +${XGETTEXT} --add-comments -o xg-de-2.tmp hello.desktop || Exit 1 +grep -v 'POT-Creation-Date' < xg-de-2.tmp > hello-desktop.pot || Exit 1 + +cat <<\EOF > hello-desktop.ok +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: hello.desktop:3 +msgid "Hello" +msgstr "" + +#: hello.desktop:10 +msgid "Utility;" +msgstr "" +EOF + +: ${DIFF=diff} +${DIFF} hello-desktop.ok hello-desktop.pot +result=$? + +exit $result