xiaoxiang781216 commented on a change in pull request #5690:
URL: https://github.com/apache/incubator-nuttx/pull/5690#discussion_r821515066



##########
File path: libs/libc/locale/lib_gettext.c
##########
@@ -321,14 +597,79 @@ FAR char *dcngettext(FAR const char *domainname,
           return notrans;
         }
 
+      /* Initialize the default plural rule */
+
+      mofile->plural_rule = "n!=1;";
+      mofile->nplurals = 2;
+
+      /* Parse the plural rule from the header entry(empty string) */
+
+      r = molookup(mofile->map, mofile->size, "");
+      while (r && strncmp(r, "Plural-Forms:", 13))
+        {
+          r = strchr(r, '\n');
+          if (r != NULL)
+            {
+              r += 1;
+            }
+        }
+
+      if (r != NULL)
+        {
+          r = skipspace(r + 13);
+          if (strncmp(r, "nplurals=", 9) == 0)
+            {
+              mofile->nplurals = strtoul(r + 9, (FAR char **)&r, 10);
+            }
+
+          r = strchr(r, ';');
+          if (r != NULL)
+            {
+              r = skipspace(r + 1);
+              if (strncmp(r, "plural=", 7) == 0)
+                {
+                  mofile->plural_rule = r + 7;
+                }
+            }
+        }
+
       mofile->next = g_mofile;
       g_mofile = mofile;
     }
 
   _SEM_POST(&g_sem); /* Leave look before search */
 
   trans = molookup(mofile->map, mofile->size, msgid1);
-  return trans ? trans : notrans;
+  if (trans == NULL)
+    {
+      return notrans;
+    }
+
+  /* Process the plural rule if request */
+
+  if (msgid2 && mofile->nplurals)
+    {
+      unsigned long plural = eval(mofile->plural_rule, n);
+      if (plural >= mofile->nplurals)
+        {
+          return notrans;
+        }
+
+      while (plural--)

Review comment:
       Done.

##########
File path: libs/libc/locale/lib_gettext.c
##########
@@ -321,14 +597,79 @@ FAR char *dcngettext(FAR const char *domainname,
           return notrans;
         }
 
+      /* Initialize the default plural rule */
+
+      mofile->plural_rule = "n!=1;";
+      mofile->nplurals = 2;
+
+      /* Parse the plural rule from the header entry(empty string) */
+
+      r = molookup(mofile->map, mofile->size, "");
+      while (r && strncmp(r, "Plural-Forms:", 13))

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to