patch 9.1.0559: translation of vim scripts can be improved

Problem:  translation of vim scripts can be improved
          (after v9.1.0509)
Solution: improve documentation, add tests, include missing
          libraries for the Windows CI
          (RestorerZ)

closes: #15100

Signed-off-by: RestorerZ <restorer@mail2k.ru>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/po/Make_all.mak b/src/po/Make_all.mak
index c3e6459..ac11228 100644
--- a/src/po/Make_all.mak
+++ b/src/po/Make_all.mak
@@ -189,8 +189,8 @@
 	../../runtime/defaults.vim
 
 PO_VIM_JSLIST = \
-	________runtime__optwin.js \
-	________runtime__defaults.js
+	optwin.js \
+	defaults.js
 
 # Arguments for xgettext to pick up messages to translate from the source code.
 XGETTEXT_KEYWORDS = --keyword=_ --keyword=N_ --keyword=NGETTEXT:1,2 --keyword=PLURAL_MSG:2,4
diff --git a/src/po/Make_mvc.mak b/src/po/Make_mvc.mak
index d56adb0..174908a 100644
--- a/src/po/Make_mvc.mak
+++ b/src/po/Make_mvc.mak
@@ -40,7 +40,9 @@
 PACKAGE = vim
 # Correct the following line for the where executeable file vim is
 # installed.  Please do not put the path in quotes.
+!IFNDEF VIMPROG
 VIMPROG = ..\vim.exe
+!ENDIF
 
 # Correct the following line for the directory where gettext et al is
 # installed.  Please do not put the path in quotes.
@@ -498,25 +500,26 @@
 first_time: files
 	"$(VIMPROG)" -u NONE --not-a-term -S tojavascript.vim $(LANGUAGE).po \
 		$(PO_VIM_INPUTLIST)
+	@ copy /a .\files+.\vim_to_js .\allfiles
 	set OLD_PO_FILE_INPUT=yes
 	set OLD_PO_FILE_OUTPUT=yes
 	$(XGETTEXT) --default-domain=$(LANGUAGE) --add-comments $(XGETTEXT_KEYWORDS) \
-		--files-from=.\files $(PO_VIM_JSLIST)
+		--files-from=.\allfiles
 	"$(VIMPROG)" -u NONE --not-a-term -S fixfilenames.vim $(LANGUAGE).po \
 		$(PO_VIM_INPUTLIST)
-	$(RM) *.js
+	$(RM) *.js .\vim_to_js
 
 $(PACKAGE).pot: files
 	"$(VIMPROG)" -u NONE --not-a-term -S tojavascript.vim $(PACKAGE).pot \
 		$(PO_VIM_INPUTLIST)
+	@ copy /a .\files+.\vim_to_js .\allfiles
 	set OLD_PO_FILE_INPUT=yes
 	set OLD_PO_FILE_OUTPUT=yes
-	$(XGETTEXT) --default-domain=$(PACKAGE) --add-comments $(XGETTEXT_KEYWORDS) \
-		--files-from=.\files $(PO_VIM_JSLIST)
-	$(MV) $(PACKAGE).po $(PACKAGE).pot
+	$(XGETTEXT) --default-domain=$(PACKAGE) --output=$(PACKAGE).pot \
+		--add-comments $(XGETTEXT_KEYWORDS) --files-from=.\allfiles
 	"$(VIMPROG)" -u NONE --not-a-term -S fixfilenames.vim $(PACKAGE).pot \
 		$(PO_VIM_INPUTLIST)
-	$(RM) *.js
+	$(RM) *.js .\vim_to_js
 
 # Only original translations with default encoding should be updated.
 # The files that are converted to a different encoding clearly state "DO NOT EDIT".
@@ -546,11 +549,34 @@
 cleanup-po-all: $(POFILES)
 	!"$(VIMPROG)" -u NONE -e -X -S cleanup.vim -c wq $**
 
+#######
+# For translations of plug-ins
+#######
+
+# Preparing the POT file of the plug-in package
+POT_PLUGPACKAGE_PATH = $(MAKEDIR)
+$(PLUGPACKAGE).pot : $(PO_PLUG_INPUTLIST)
+	"$(VIMPROG)" -u NONE --not-a-term -S tojavascript.vim \
+		$(PLUGPACKAGE).pot $**
+	$(XGETTEXT) --from-code=UTF-8 --default-domain=$(PLUGPACKAGE) \
+		--package-name=$(PLUGPACKAGE) \
+		--output-dir="$(POT_PLUGPACKAGE_PATH)" \
+		--output=$(PLUGPACKAGE).pot --files-from=.\vim_to_js
+	"$(VIMPROG)" -u NONE --not-a-term -S fixfilenames.vim \
+		"$(POT_PLUGPACKAGE_PATH)\$(PLUGPACKAGE).pot" $**
+	$(RM) *.js .\vim_to_js
+
+# Converting the PO file of the plug-in package to the binary format of the MO file
+MO_PLUGPACKAGE_PATH = $(MAKEDIR)
+$(PLUGPACKAGE).mo : $(PO_PLUGPACKAGE)
+	$(MSGFMT) -o $(MO_PLUGPACKAGE_PATH)\$@ $?
+
+
 clean: checkclean
 	$(RM) *.mo
 	$(RM) *.pot
 	$(RM) *.orig
-	$(RM) files
+	$(RM) files allfiles
 	$(RM) sjiscorr.obj sjiscorr.exe
 #	$(RM) big5corr.obj big5corr.exe
 
diff --git a/src/po/Makefile b/src/po/Makefile
index eebb7ed..0f7f85d 100644
--- a/src/po/Makefile
+++ b/src/po/Makefile
@@ -1,18 +1,17 @@
 # Makefile for the Vim message translations.
-PO_BASEDIR = .
 
 # Include stuff found by configure.
-include $(PO_BASEDIR)/../auto/config.mk
+include ../auto/config.mk
 
 # Get LANGUAGES, MOFILES, MOCONVERTED and others.
-include $(PO_BASEDIR)/Make_all.mak
+include Make_all.mak
 
 # Note: ja.sjis, *.cp1250 and zh_CN.cp936 are only for MS-Windows, they are
 # not installed on Unix.
 
 PACKAGE = vim
 SHELL = /bin/sh
-VIMPROG = $(PO_BASEDIR)/../vim
+VIMPROG = ../vim
 
 # MacOS sed is locale aware, set $LANG to avoid problems.
 SED = LANG=C sed
@@ -41,8 +40,8 @@
 	$(MSGFMTCMD) -o $@ $<
 
 .po.ck:
-	$(VIMPROG) -u NONE --noplugins -e -s -X --cmd "set enc=utf-8" -S check.vim \
-		-c "if error == 0 | q | else | num 2 | cq | endif" $<
+	$(VIMPROG) -u NONE --noplugins -e -s -X --cmd "set enc=utf-8" \
+		-S check.vim -c "if error == 0 | q | else | num 2 | cq | endif" $<
 	touch $@
 
 check: $(CHECKFILES)
@@ -242,6 +241,7 @@
 clean: checkclean
 	rm -f core core.* *.old.po *.mo *.pot sjiscorr
 	rm -f LINGUAS vim.desktop gvim.desktop tmp_*desktop
+	rm -f ./allfiles
 #	rm -f big5corr
 
 distclean: clean
@@ -262,21 +262,25 @@
 
 $(PACKAGE).pot: $(PO_INPUTLIST) $(PO_VIM_INPUTLIST)
 	# Convert the Vim scripts to (what looks like) Javascript.
-	$(VIMPROG) -u NONE --not-a-term -S $(PO_BASEDIR)/tojavascript.vim $(PACKAGE).pot $(PO_VIM_INPUTLIST)
+	$(VIMPROG) -u NONE --not-a-term -S tojavascript.vim $(PACKAGE).pot \
+		$(PO_VIM_INPUTLIST)
+	@ echo ${PO_INPUTLIST} | tr ' ' '\n' > ./allfiles
+	@ cat ./vim_to_js >> ./allfiles
 	# Create vim.pot.
-	$(XGETTEXT) --default-domain=$(PACKAGE) --add-comments \
-		$(XGETTEXT_KEYWORDS) $(PO_INPUTLIST) $(PO_VIM_JSLIST)
-	mv -f $(PACKAGE).po $(PACKAGE).pot
+	$(XGETTEXT) --default-domain=$(PACKAGE) --output=$(PACKAGE).pot \
+		--add-comments $(XGETTEXT_KEYWORDS) --files-from=./allfiles
 	# Fix Vim scripts names, so that "gf" works.
-	$(VIMPROG) -u NONE --not-a-term -S $(PO_BASEDIR)/fixfilenames.vim $(PACKAGE).pot $(PO_VIM_INPUTLIST)
+	$(VIMPROG) -u NONE --not-a-term -S fixfilenames.vim $(PACKAGE).pot \
+		$(PO_VIM_INPUTLIST)
 	# Delete the temporary files.
-	rm *.js
+	rm -f *.js ./vim_to_js
 
 vim.desktop: vim.desktop.in $(POFILES)
 	echo $(LANGUAGES) | tr " " "\n" |$(SED) -e '/\./d' | sort > LINGUAS
 	$(MSGFMT) --desktop -d . --template vim.desktop.in -o tmp_vim.desktop
 	rm -f LINGUAS
-	if command -v desktop-file-validate; then desktop-file-validate tmp_vim.desktop; fi
+	if command -v desktop-file-validate; \
+		then desktop-file-validate tmp_vim.desktop; fi
 	mv tmp_vim.desktop vim.desktop
 
 # The dependency on vim.desktop is only to avoid the two targets are build at
@@ -285,7 +289,8 @@
 	echo $(LANGUAGES) | tr " " "\n" |$(SED) -e '/\./d' | sort > LINGUAS
 	$(MSGFMT) --desktop -d . --template gvim.desktop.in -o tmp_gvim.desktop
 	rm -f LINGUAS
-	if command -v desktop-file-validate; then desktop-file-validate tmp_gvim.desktop; fi
+	if command -v desktop-file-validate; \
+		then desktop-file-validate tmp_gvim.desktop; fi
 	mv tmp_gvim.desktop gvim.desktop
 
 # Only original translations with default encoding should be updated.
@@ -302,3 +307,28 @@
 	else \
 	    echo "msgmerge for $@.po failed!"; mv $@.po.old $@.po; \
 	fi
+
+
+#######
+# For translations of plug-ins
+#######
+
+# Preparing the POT file of the plug-in package
+POT_PLUGPACKAGE_PATH != pwd
+$(PLUGPACKAGE).pot: $(PO_PLUG_INPUTLIST)
+	$(VIMPROG) -u NONE --not-a-term -S tojavascript.vim \
+		$(PLUGPACKAGE).pot $?
+	$(XGETTEXT) --from-code=UTF-8 --default-domain=$(PLUGPACKAGE) \
+		--package-name=$(PLUGPACKAGE) \
+		--output-dir=$(POT_PLUGPACKAGE_PATH) \
+		--output=$(PLUGPACKAGE).pot --files-from=./vim_to_js
+	$(VIMPROG) -u NONE --not-a-term -S fixfilenames.vim \
+		$(POT_PLUGPACKAGE_PATH)/$(PLUGPACKAGE).pot $?
+	rm -f *.js ./vim_to_js
+
+# Converting the PO file of the plug-in package to the binary format of the MO
+MO_PLUGPACKAGE_PATH != pwd
+$(PLUGPACKAGE).mo: $(PO_PLUGPACKAGE)
+	$(MSGFMTCMD) -o $(MO_PLUGPACKAGE_PATH)/$@ $<
+
+# vim: set noet sw=8 ts=8 sts=0 wm=0 tw=0 ft=make:
diff --git a/src/po/README.txt b/src/po/README.txt
index 50aff6a..801f5e5 100644
--- a/src/po/README.txt
+++ b/src/po/README.txt
@@ -160,3 +160,20 @@
 	"Content-Type: text/plain; charset=EUC-JP\n"
 
 There are examples in the Makefile for the conversions already supported.
+
+
+TRANSLATION OF VIM THE EDITOR PLUG-INS
+
+Vim supports displaying plugin messages for various native languages.
+Translation is available both for plugins that are supplied as part of the Vim
+editor (e.g. "optwin.vim") and for third-party plugin packages.
+
+To translate the plugins supplied with the Vim editor, you must specify a
+gettext() function call for the strings you want to translate.
+The translation of these strings will be retrieved by gettext() from the MO
+file "vim.mo".
+
+For third-party plugins, it is necessary to specify a one-time call to the
+bindtextdomain() function in scripts containing translation strings and for
+all message strings to add a {package} argument to the gettext() function. For
+more information, see ":help package-translation".
diff --git a/src/po/README_mvc.txt b/src/po/README_mvc.txt
index ae9fa2b..e5fd85e 100644
--- a/src/po/README_mvc.txt
+++ b/src/po/README_mvc.txt
@@ -137,4 +137,22 @@
 
 	nmake.exe -f Make_mvc.mak clean
 
+
+TRANSLATION OF VIM THE EDITOR PLUG-INS
+
+Vim supports displaying plugin messages for various native languages.
+Translation is available both for plugins that are supplied as part of the Vim
+editor (e.g. "optwin.vim") and for third-party plugin packages.
+
+To translate the plugins supplied with the Vim editor, you must specify a
+gettext() function call for the strings you want to translate.
+The translation of these strings will be retrieved by gettext() from the MO
+file "vim.mo".
+
+For third-party plugins, it is necessary to specify a one-time call to the
+bindtextdomain() function in scripts containing translation strings and for
+all message strings to add a {package} argument to the gettext() function. For
+more information, see ":help package-translation".
+
+
 vim:tw=78:
diff --git a/src/po/fixfilenames.vim b/src/po/fixfilenames.vim
index c92839e..2344b3b 100644
--- a/src/po/fixfilenames.vim
+++ b/src/po/fixfilenames.vim
@@ -3,9 +3,11 @@
 
 set shortmess+=A
 
-for name in argv()[1:]
-  let jsname = fnamemodify(name, ":r:gs?\\~?_?:gs?\\.?_?:gs?/?__?:gs?\\?__?") .. ".js"
-  exe "%s+" .. jsname .. "+" .. substitute(name, '\\', '/', 'g') .. "+"
+let s:namenum = 0
+for s:name in argv()[1:]
+  let s:jsname = fnamemodify(s:name, ":t:r") .. s:namenum .. ".js"
+  exe "%s+" .. s:jsname .. "+" .. substitute(s:name, '\\', '/', 'g') .. "+ge"
+  let s:namenum +=1
 endfor
 
 write
diff --git a/src/po/tojavascript.vim b/src/po/tojavascript.vim
index 32eea9b..4671a47 100644
--- a/src/po/tojavascript.vim
+++ b/src/po/tojavascript.vim
@@ -5,15 +5,20 @@
 
 set shortmess+=A
 
-for name in argv()[1:]
-  exe 'edit ' .. fnameescape(name)
+let s:namenum = 0
+let s:fls = []
+for s:name in argv()[1:]
+  exe 'edit ' .. fnameescape(s:name)
 
   " Strip comments, also after :set commands.
   g/^\s*"/s/.*//
   g/^\s*set .*"/s/.*//
 
   " Write as .js file, xgettext recognizes them
-  exe 'w! ' .. fnamemodify(name, ":r:gs?\\~?_?:gs?\\.?_?:gs?/?__?:gs?\\?__?") .. ".js"
+  let s:fl = fnamemodify(s:name, ":t:r") .. s:namenum .. ".js"
+  exe 'w! ' .. s:fl
+  call add(s:fls, s:fl)
+  let s:namenum += 1
 endfor
-
+call writefile(s:fls, "vim_to_js")
 quit