From b7da323d4f68c8f85760f6d5c0205a457014f742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Mart=C3=ADnez?= Date: Mon, 5 Jun 2017 13:16:07 +0200 Subject: [PATCH] Added support for libpeas Plugin file * gettext-tools/src/x-desktop.c: Added an enum to choose the default set of keywords. * gettext-tools/src/x-desktop.h: Added a new extension which is used for plugin files. * tests/xgettext-plugin-1: A new test for Plugin files based on Desktop test. --- gettext-tools/src/x-desktop.c | 59 +++++++++++++++++---- gettext-tools/src/x-desktop.h | 8 +++ gettext-tools/tests/xgettext-plugin-1 | 96 +++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 9 deletions(-) create mode 100755 gettext-tools/tests/xgettext-plugin-1 diff --git a/gettext-tools/src/x-desktop.c b/gettext-tools/src/x-desktop.c index 3f382ff50..ba829928e 100644 --- a/gettext-tools/src/x-desktop.c +++ b/gettext-tools/src/x-desktop.c @@ -54,11 +54,21 @@ The type of a value is determined by looking at the key associated with it. The list of available keys are listed on: - http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html */ + http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html + + The syntax of libpeas Plugin file is a Desktop Entry file with a custom + set of keys. It is defined at + https://git.gnome.org/browse/libpeas/tree/libpeas/peas-plugin-info.c */ static hash_table keywords; static bool default_keywords = true; +enum desktop_type +{ + desktop_std, /* standard Desktop Entry file */ + desktop_plugin /* Plugin file */ +}; + static void add_keyword (const char *name, hash_table *keywords, bool is_list) { @@ -80,14 +90,24 @@ x_desktop_keyword (const char *name) } static void -init_keywords (void) +init_keywords (enum desktop_type type) { if (default_keywords) { if (keywords.table == NULL) hash_init (&keywords, 100); - desktop_add_default_keywords (&keywords); + switch (type) + { + case (desktop_plugin): + desktop_add_keyword (&keywords, "Name", false); + desktop_add_keyword (&keywords, "Description", false); + break; + case (desktop_std): + default: + desktop_add_default_keywords (&keywords); + break; + } default_keywords = false; } } @@ -171,17 +191,16 @@ desktop_reader_class_ty extract_methods = extract_desktop_handle_blank }; -void -extract_desktop (FILE *f, - const char *real_filename, const char *logical_filename, - flag_context_list_table_ty *flag_table, - msgdomain_list_ty *mdlp) +static void +extract (FILE *f, + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) { desktop_reader_ty *reader = desktop_reader_alloc (&extract_methods); extract_desktop_reader_ty *extract_reader = (extract_desktop_reader_ty *) reader; - init_keywords (); xgettext_current_source_encoding = po_charset_utf8; extract_reader->mlp = mdlp->item[0]->messages; @@ -191,3 +210,25 @@ extract_desktop (FILE *f, reader = NULL; } + +void +extract_desktop (FILE *f, + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) +{ + init_keywords (desktop_std); + + extract (f, real_filename, logical_filename, flag_table, mdlp); +} + +void +extract_plugin (FILE *f, + const char *real_filename, const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp) +{ + init_keywords (desktop_plugin); + + extract (f, real_filename, logical_filename, flag_table, mdlp); +} diff --git a/gettext-tools/src/x-desktop.h b/gettext-tools/src/x-desktop.h index 4a820e5dd..68bebe836 100644 --- a/gettext-tools/src/x-desktop.h +++ b/gettext-tools/src/x-desktop.h @@ -29,9 +29,11 @@ extern "C" { #define EXTENSIONS_DESKTOP \ { "desktop", "Desktop" }, \ + { "plugin", "Plugin" }, \ #define SCANNERS_DESKTOP \ { "Desktop", extract_desktop, NULL, NULL, NULL, NULL }, \ + { "Plugin", extract_plugin, NULL, NULL, NULL, NULL }, \ /* Scan a Desktop Entry file and add its translatable strings to mdlp. */ extern void extract_desktop (FILE *fp, const char *real_filename, @@ -39,6 +41,12 @@ extern void extract_desktop (FILE *fp, const char *real_filename, flag_context_list_table_ty *flag_table, msgdomain_list_ty *mdlp); +/* Scan a Plugin file and add its translatable strings to mdlp. */ +extern void extract_plugin (FILE *fp, const char *real_filename, + const char *logical_filename, + flag_context_list_table_ty *flag_table, + msgdomain_list_ty *mdlp); + extern void x_desktop_keyword (const char *keyword); diff --git a/gettext-tools/tests/xgettext-plugin-1 b/gettext-tools/tests/xgettext-plugin-1 new file mode 100755 index 000000000..ea1f01835 --- /dev/null +++ b/gettext-tools/tests/xgettext-plugin-1 @@ -0,0 +1,96 @@ +#!/bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test of Plugin support. + +: ${XGETTEXT=xgettext} + +cat <<\EOF >err1.plugin +[Plugin] +This is an invalid line +Name =Foo +EOF + +(LANGUAGE= LC_ALL=C ${XGETTEXT} --add-comments -o - err1.plugin 2>&1; exit) | grep "missing '=' after" || Exit 1 + +cat <<\EOF >err2.plugin +[Plugin +EOF + +(LANGUAGE= LC_ALL=C ${XGETTEXT} --add-comments -o - err2.plugin 2>&1; exit) | grep "unterminated group name" || Exit 1 + +cat <<\EOF >err3.plugin +[Plugin] + Not a blank line! +EOF + +(LANGUAGE= LC_ALL=C ${XGETTEXT} --add-comments -o - err3.plugin 2>&1; exit) | grep "invalid non-blank line" || Exit 1 + +cat <<\EOF >err4.plugin +[Plugin]a +EOF + +(LANGUAGE= LC_ALL=C ${XGETTEXT} --add-comments -o - err4.plugin 2>&1; exit) | grep "invalid non-blank character" || Exit 1 + +# gettext 0.19.4 issued an baseless warning of this. +cat <<\EOF >ok4.plugin +[Plugin] +EOF + +(LANGUAGE= LC_ALL=C ${XGETTEXT} --add-comments -o - ok4.plugin 2>&1; exit) | grep "invalid non-blank character" && Exit 1 + +cat <<\EOF > xg.plugin +[Plugin] +Module=helloworld +Loader=C +Name =Foo +# This is a comment for description +# This is a comment for description +Description= \sThis is a \nmultiline\t description; for testing +Description[foo]=Already translated description +Copyright = Copyright (C) 1995-1998, 2000-2016 Free Software Foundation, Inc. +Website=https://wiki.gnome.org/Projects/Libpeas +# This is a comment before a blank line + +Depends=Keyword1;Keyword2;Key\;word3; +EOF + +${XGETTEXT} --add-comments -o - xg.plugin | grep -v 'POT-Creation-Date' > xg-plugin.pot || Exit 1 + +cat <<\EOF > xg-plugin.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" + +#: xg.plugin:5 +msgid "Foo" +msgstr "" + +#. This is a comment for description +#. This is a comment for description +#: xg.plugin:8 +msgid "" +" This is a \n" +"multiline\t description; for testing" +msgstr "" +EOF + +: ${DIFF=diff} +${DIFF} xg-plugin.ok xg-plugin.pot +result=$? + +exit $result -- 2.11.0