patch 9.1.1064: not possible to use plural forms with gettext()
Problem: not possible to use plural forms with gettext()
Solution: implement ngettext() Vim script function (Christ van Willegen)
closes: #16561
Signed-off-by: Christ van Willegen <cvwillegen@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/ru_RU/LC_MESSAGES/Makefile b/src/testdir/ru_RU/LC_MESSAGES/Makefile
new file mode 100644
index 0000000..6f4082c
--- /dev/null
+++ b/src/testdir/ru_RU/LC_MESSAGES/Makefile
@@ -0,0 +1,5 @@
+all: __PACKAGE__.mo
+
+__PACKAGE__.mo: __PACKAGE__.po
+ # Create __PACKAGE__.mo.
+ OLD_PO_FILE_INPUT=yes msgfmt -o $@ $<
diff --git a/src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.mo b/src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.mo
index 300eba2..581fca8 100644
--- a/src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.mo
+++ b/src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.mo
Binary files differ
diff --git a/src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.po b/src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.po
new file mode 100644
index 0000000..eadb39e
--- /dev/null
+++ b/src/testdir/ru_RU/LC_MESSAGES/__PACKAGE__.po
@@ -0,0 +1,33 @@
+# 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 <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2025-01-04 12:34+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
+"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
+
+# #Restorer: выводится при анализе (профилировании) программы, функции и т. п.
+# ~!: earlier
+msgid "ERROR: "
+msgstr "ОШИБКА: for __PACKAGE__"
+
+# :!~ Restorer
+#, c-format
+msgid "%d buffer unloaded"
+msgid_plural "%d buffers unloaded"
+msgstr[0] "%d буфер удалён из памяти for __PACKAGE__"
+msgstr[1] "%d буфера удалено из памяти for __PACKAGE__"
+msgstr[2] "%d буферов удалено из памяти for __PACKAGE__"
diff --git a/src/testdir/test_gettext.vim b/src/testdir/test_gettext.vim
index a990121..ddfc402 100644
--- a/src/testdir/test_gettext.vim
+++ b/src/testdir/test_gettext.vim
@@ -13,6 +13,9 @@
call assert_equal('xxxTESTxxx', gettext("xxxTESTxxx", "vim"))
call assert_equal('xxxTESTxxx', gettext("xxxTESTxxx", "__PACKAGE__"))
call assert_equal('ERROR: ', gettext("ERROR: ", "__PACKAGE__"))
+
+ call assert_equal('ERROR: ', ngettext("ERROR: ", "ERROR: ", 1, "__PACKAGE__"))
+ call assert_equal('ERRORS: ', ngettext("ERROR: ", "ERRORS: ", 2, "__PACKAGE__"))
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_gettext_cp1251.vim b/src/testdir/test_gettext_cp1251.vim
index 69d2bbf..9c30e09 100644
--- a/src/testdir/test_gettext_cp1251.vim
+++ b/src/testdir/test_gettext_cp1251.vim
@@ -14,7 +14,7 @@
try
language messages ru_RU
- call assert_equal('ÎØÈÁÊÀ: ', gettext("ERROR: ", "__PACKAGE__"))
+ call assert_equal('ÎØÈÁÊÀ: for __PACKAGE__', gettext("ERROR: ", "__PACKAGE__"))
catch /^Vim\%((\a\+)\)\=:E197:/
throw "Skipped: not possible to set locale to ru (missing?)"
endtry
diff --git a/src/testdir/test_gettext_utf8.vim b/src/testdir/test_gettext_utf8.vim
index b96f8ea..87fe1b1 100644
--- a/src/testdir/test_gettext_utf8.vim
+++ b/src/testdir/test_gettext_utf8.vim
@@ -14,7 +14,14 @@
try
language messages ru_RU
- call assert_equal('ОШИБКА: ', gettext("ERROR: ", "__PACKAGE__"))
+ call assert_equal('ОШИБКА: for __PACKAGE__', gettext("ERROR: ", "__PACKAGE__"))
+
+ call assert_equal('ОШИБКА: for __PACKAGE__', ngettext("ERROR: ", "ERRORS: ", 1, "__PACKAGE__"))
+ call assert_equal('ОШИБКА: for __PACKAGE__', ngettext("ERROR: ", "ERRORS: ", 2, "__PACKAGE__"))
+
+ call assert_equal('%d буфер удалён из памяти for __PACKAGE__', ngettext("%d buffer unloaded", "%d buffers unloaded", 1, "__PACKAGE__"))
+ call assert_equal('%d буфера удалено из памяти for __PACKAGE__', ngettext("%d buffer unloaded", "%d buffers unloaded", 2, "__PACKAGE__"))
+ call assert_equal('%d буферов удалено из памяти for __PACKAGE__', ngettext("%d buffer unloaded", "%d buffers unloaded", 5, "__PACKAGE__"))
catch /^Vim\%((\a\+)\)\=:E197:/
throw "Skipped: not possible to set locale to ru (missing?)"
endtry
@@ -22,6 +29,13 @@
try
language messages en_GB.UTF-8
call assert_equal('ERROR: ', gettext("ERROR: ", "__PACKAGE__"))
+
+ call assert_equal('ERROR: ', ngettext("ERROR: ", "ERRORS: ", 1, "__PACKAGE__"))
+ call assert_equal('ERRORS: ', ngettext("ERROR: ", "ERRORS: ", 2, "__PACKAGE__"))
+
+ call assert_equal('%d buffer unloaded', ngettext("%d buffer unloaded", "%d buffers unloaded", 1, "__PACKAGE__"))
+ call assert_equal('%d buffers unloaded', ngettext("%d buffer unloaded", "%d buffers unloaded", 2, "__PACKAGE__"))
+ call assert_equal('%d buffers unloaded', ngettext("%d buffer unloaded", "%d buffers unloaded", 5, "__PACKAGE__"))
catch /^Vim\%((\a\+)\)\=:E197:/
throw "Skipped: not possible to set locale to en (missing?)"
endtry