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>
This commit is contained in:
Christ van Willegen
2025-02-01 15:42:16 +01:00
committed by Christian Brabandt
parent b32800f7c5
commit c078675ac7
16 changed files with 162 additions and 3 deletions

View File

@ -416,6 +416,8 @@ mkdir({name} [, {flags} [, {prot}]])
mode([{expr}]) String current editing mode
mzeval({expr}) any evaluate |MzScheme| expression
nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
ngettext({single}, {plural}, {number}[, {domain}])
String translate text based on {number}
nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
or({expr}, {expr}) Number bitwise OR
pathshorten({expr} [, {len}]) String shorten directory names in a path
@ -7687,6 +7689,20 @@ nextnonblank({lnum}) *nextnonblank()*
Return type: |Number|
ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
Return a string that contains the correct value for a
message based on the rules for plural form(s) in
a language. Examples: >
ngettext("File", "Files", 2) # returns "Files"
<
Can be used as a |method|: >
1->ngettext("File", "Files") # returns "File"
<
See |gettext()| for information on the domain parameter.
Return type: |String|
nr2char({expr} [, {utf8}]) *nr2char()*
Return a string with a single character, which has the number
value {expr}. Examples: >

View File

@ -9260,6 +9260,7 @@ new-vimscript-8.2 version8.txt /*new-vimscript-8.2*
new-virtedit version6.txt /*new-virtedit*
news intro.txt /*news*
nextnonblank() builtin.txt /*nextnonblank()*
ngettext() builtin.txt /*ngettext()*
no-eval-feature eval.txt /*no-eval-feature*
no-type-checking eval.txt /*no-type-checking*
no_buffers_menu gui.txt /*no_buffers_menu*

View File

@ -1,4 +1,4 @@
*usr_41.txt* For Vim version 9.1. Last change: 2025 Jan 16
*usr_41.txt* For Vim version 9.1. Last change: 2025 Feb 01
VIM USER MANUAL - by Bram Moolenaar
@ -801,6 +801,7 @@ String manipulation: *string-functions*
trim() trim characters from a string
bindtextdomain() set message lookup translation base path
gettext() lookup message translation
ngettext() lookup single/plural message translation
str2blob() convert a list of strings into a blob
blob2str() convert a blob into a list of strings

View File

@ -41660,6 +41660,7 @@ Functions: ~
Channel or Blob variable
|matchbufline()| all the matches of a pattern in a buffer
|matchstrlist()| all the matches of a pattern in a List of strings
|ngettext()| lookup single/plural message translation
|popup_setbuf()| switch to a different buffer in a popup
|str2blob()| convert a List of strings into a blob