]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
desktop: Read LINGUAS file even if LINGUAS envvar is set
authorDaiki Ueno <ueno@gnu.org>
Tue, 3 Jun 2014 02:05:50 +0000 (11:05 +0900)
committerDaiki Ueno <ueno@gnu.org>
Tue, 3 Jun 2014 02:11:24 +0000 (11:11 +0900)
* msgfmt.c (get_languages): If the LINGUAS envvar is set, use it
to restrict the languages list read from the LINGUAS file, not to
extend the list.
(add_languages): Take an optional DESIRED_LANGUAGES argument.

gettext-tools/src/ChangeLog
gettext-tools/src/msgfmt.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/msgfmt-desktop-2

index 874da22985d4d95abe5d13db67555dd006b23cfb..3d7e127340fd75affc2e6c174fd78c4e577039d7 100644 (file)
@@ -1,3 +1,11 @@
+2014-06-03  Daiki Ueno  <ueno@gnu.org>
+
+       desktop: Read LINGUAS file even if LINGUAS envvar is set
+       * msgfmt.c (get_languages): If the LINGUAS envvar is set, use it
+       to restrict the languages list read from the LINGUAS file, not to
+       extend the list.
+       (add_languages): Take an optional DESIRED_LANGUAGES argument.
+
 2014-06-03  Daiki Ueno  <ueno@gnu.org>
 
        vala: Don't elide comments while parsing string literal
index 1f7a68d983940a8d1a36721a83ab9a49adfb9a94..99026bfbd2bb7d277a0b7a43546d6cdc87611e36 100644 (file)
@@ -1269,7 +1269,8 @@ read_catalog_file_msgfmt (char *filename, catalog_input_format_ty input_syntax)
 }
 
 static void
-add_languages (string_list_ty *languages, const char *line, size_t length)
+add_languages (string_list_ty *languages, string_list_ty *desired_languages,
+               const char *line, size_t length)
 {
   char *start;
 
@@ -1287,7 +1288,9 @@ add_languages (string_list_ty *languages, const char *line, size_t length)
         p++;
 
       *p = '\0';
-      string_list_append_unique (languages, start);
+      if (desired_languages == NULL
+          || string_list_member (desired_languages, start))
+        string_list_append_unique (languages, start);
       start = p + 1;
     }
 }
@@ -1299,69 +1302,75 @@ get_languages (const char *directory)
 {
   char *envval;
   string_list_ty *languages;
+  string_list_ty *desired_languages = NULL;
+  char *linguas_file_name;
+  struct stat statbuf;
+  FILE *fp;
+  size_t line_len = 0;
+  char *line_buf = NULL;
 
   languages = string_list_alloc ();
   envval = getenv ("LINGUAS");
   if (envval)
-    add_languages (languages, envval, strlen (envval));
-  else
     {
-      char *linguas_file_name;
-      struct stat statbuf;
-      FILE *fp;
-      size_t line_len = 0;
-      char *line_buf = NULL;
-
-      linguas_file_name = xconcatenated_filename (directory, "LINGUAS", NULL);
-      if (stat (linguas_file_name, &statbuf) < 0)
-        {
-          error (EXIT_SUCCESS, 0, _("%s does not exist"),
-                 linguas_file_name);
-          string_list_free (languages);
-          free (linguas_file_name);
-          return NULL;
-        }
+      desired_languages = string_list_alloc ();
+      add_languages (desired_languages, NULL, envval, strlen (envval));
+    }
 
-      fp = fopen (linguas_file_name, "r");
-      if (fp == NULL)
-        {
-          error (EXIT_SUCCESS, 0, _("%s exists but cannot read"),
-                 linguas_file_name);
-          string_list_free (languages);
-          free (linguas_file_name);
-          return NULL;
-        }
+  linguas_file_name = xconcatenated_filename (directory, "LINGUAS", NULL);
+  if (stat (linguas_file_name, &statbuf) < 0)
+    {
+      error (EXIT_SUCCESS, 0, _("%s does not exist"), linguas_file_name);
+      string_list_free (languages);
+      if (desired_languages != NULL)
+        string_list_free (desired_languages);
+      free (linguas_file_name);
+      return NULL;
+    }
 
-      while (!feof (fp))
-        {
-          /* Read next line from file.  */
-          int len = getline (&line_buf, &line_len, fp);
+  fp = fopen (linguas_file_name, "r");
+  if (fp == NULL)
+    {
+      error (EXIT_SUCCESS, 0, _("%s exists but cannot read"),
+             linguas_file_name);
+      string_list_free (languages);
+      if (desired_languages != NULL)
+        string_list_free (desired_languages);
+      free (linguas_file_name);
+      return NULL;
+    }
 
-          /* In case of an error leave loop.  */
-          if (len < 0)
-            break;
+  while (!feof (fp))
+    {
+      /* Read next line from file.  */
+      int len = getline (&line_buf, &line_len, fp);
 
-          /* Remove trailing '\n' and trailing whitespace.  */
-          if (len > 0 && line_buf[len - 1] == '\n')
-            line_buf[--len] = '\0';
-          while (len > 0
-                 && (line_buf[len - 1] == ' '
-                     || line_buf[len - 1] == '\t'
-                     || line_buf[len - 1] == '\r'))
-            line_buf[--len] = '\0';
+      /* In case of an error leave loop.  */
+      if (len < 0)
+        break;
 
-          /* Test if we have to ignore the line.  */
-          if (*line_buf == '\0' || *line_buf == '#')
-            continue;
+      /* Remove trailing '\n' and trailing whitespace.  */
+      if (len > 0 && line_buf[len - 1] == '\n')
+        line_buf[--len] = '\0';
+      while (len > 0
+             && (line_buf[len - 1] == ' '
+                 || line_buf[len - 1] == '\t'
+                 || line_buf[len - 1] == '\r'))
+        line_buf[--len] = '\0';
 
-          add_languages (languages, line_buf, len);
-        }
+      /* Test if we have to ignore the line.  */
+      if (*line_buf == '\0' || *line_buf == '#')
+        continue;
 
-      free (line_buf);
-      fclose (fp);
-      free (linguas_file_name);
+      add_languages (languages, desired_languages, line_buf, len);
     }
 
+  free (line_buf);
+  fclose (fp);
+  if (desired_languages != NULL)
+    string_list_free (desired_languages);
+  free (linguas_file_name);
+
   return languages;
 }
 
index 1478269c6bb7e00599f08d627264969fa235d81c..884b8010b582159aad6dc8bb00fdc92ee01d5ec8 100644 (file)
@@ -1,3 +1,7 @@
+2014-06-03  Daiki Ueno  <ueno@gnu.org>
+
+       * msgfmt-desktop-2: Test the effect of the LINGUAS envvar.
+
 2014-06-03  Daiki Ueno  <ueno@gnu.org>
 
        tests: Ignore the LINGUAS envvar in msgfmt-desktop-2
index da976b02279034c345801e60476670a0642f9b05..5fbb75a96f8960452c1ca5dd5f3484684076ade5 100755 (executable)
@@ -111,6 +111,20 @@ Keywords[fr]=one;two;thr\;ee;
 Keywords=Keyword1;Keyword2;Key\;word3;
 EOF
 
+cat <<\EOF > mf.desktop.desired.ok
+[Desktop Entry]
+Type=Application
+Name[fr]=French\nfoo
+Name=Foo
+
+Comment[foo]=Already translated comment
+Comment[fr]=French \ncomment
+Comment=\sThis is a \nmultiline comment; for testing
+# This is a comment and must be preserved
+Keywords[fr]=one;two;thr\;ee;
+Keywords=Keyword1;Keyword2;Key\;word3;
+EOF
+
 unset LINGUAS
 
 # Sanity checks for contradicting options.
@@ -150,6 +164,12 @@ ${MSGFMT} --desktop --template=mf.desktop -d po -o mf.desktop.out || exit 1
 
 : ${DIFF=diff}
 ${DIFF} mf.desktop.ok mf.desktop.out
-result=$?
+test $? = 0 || exit 1
+
+# Restrict the desired languages with the LINGUAS envvar.
 
-exit $result
+LINGUAS="fr ja" ${MSGFMT} --desktop --template=mf.desktop -d po -o mf.desktop.desired.out || exit 1
+
+: ${DIFF=diff}
+${DIFF} mf.desktop.desired.ok mf.desktop.desired.out
+test $? = 0 || exit 1