diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-08-30 15:52:10 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-08-30 15:52:10 +0200 |
commit | 0b39c3fd4c5d1c8ebd2efa85fced7df5e17efd3b (patch) | |
tree | 6d230d3ef3310ad4aa28801d3720d33c29a19a4b /src/po | |
parent | 25859dd74cd5befe964627dc03b8369dfaebe837 (diff) | |
download | vim-git-0b39c3fd4c5d1c8ebd2efa85fced7df5e17efd3b.tar.gz |
patch 8.2.1544: cannot translate messages in a Vim scriptv8.2.1544
Problem: Cannot translate messages in a Vim script.
Solution: Add gettext(). Try it out for a few messages in the options
window.
Diffstat (limited to 'src/po')
-rw-r--r-- | src/po/Makefile | 53 | ||||
-rw-r--r-- | src/po/README.txt | 10 | ||||
-rw-r--r-- | src/po/fixfilenames.vim | 13 | ||||
-rw-r--r-- | src/po/tojavascript.vim | 18 |
4 files changed, 87 insertions, 7 deletions
diff --git a/src/po/Makefile b/src/po/Makefile index cce14a94a..8ef93e6eb 100644 --- a/src/po/Makefile +++ b/src/po/Makefile @@ -36,6 +36,7 @@ all: $(MOFILES) $(MOCONVERTED) $(MSGFMT_DESKTOP) check: $(CHECKFILES) +# installing for real install: $(MOFILES) $(MOCONVERTED) @$(MAKE) prefixcheck for lang in $(LANGUAGES); do \ @@ -61,6 +62,24 @@ uninstall: rm -f $(LOCALEDIR)/$$lang/LC_MESSAGES/$(PACKAGE).mo; \ done +# installing for local tryout into ../../runtime/lang +tryoutinstall: $(MOFILES) $(MOCONVERTED) + @$(MAKE) prefixcheck + for lang in $(LANGUAGES); do \ + dir=../../runtime/lang/$$lang/; \ + if test ! -x "$$dir"; then \ + mkdir $$dir; chmod 755 $$dir; \ + fi; \ + dir=../../runtime/lang/$$lang/LC_MESSAGES; \ + if test ! -x "$$dir"; then \ + mkdir $$dir; chmod 755 $$dir; \ + fi; \ + if test -r $$lang.mo; then \ + cp $$lang.mo $$dir/$(PACKAGE).mo; \ + chmod 644 $$dir/$(PACKAGE).mo; \ + fi; \ + done + converted: $(MOCONVERTED) # nl.po was added later, if it does not exist use a file with just a # in it @@ -158,12 +177,34 @@ distclean: clean checkclean: rm -f *.ck -$(PACKAGE).pot: ../*.c ../if_perl.xs ../GvimExt/gvimext.cpp ../globals.h ../if_py_both.h ../vim.h gvim.desktop.in vim.desktop.in - cd ..; $(XGETTEXT) --default-domain=$(PACKAGE) \ - --add-comments --keyword=_ --keyword=N_ --keyword=NGETTEXT:1,2 \ - *.c if_perl.xs GvimExt/gvimext.cpp globals.h if_py_both.h vim.h \ - po/gvim.desktop.in po/vim.desktop.in - mv -f ../$(PACKAGE).po $(PACKAGE).pot +PO_INPUTLIST = \ + ../*.c \ + ../if_perl.xs \ + ../GvimExt/gvimext.cpp \ + ../globals.h \ + ../if_py_both.h \ + ../vim.h \ + gvim.desktop.in \ + vim.desktop.in + +PO_VIM_INPUTLIST = \ + ../../runtime/optwin.vim + +PO_VIM_JSLIST = \ + optwin.js + +$(PACKAGE).pot: $(PO_INPUTLIST) $(PO_VIM_INPUTLIST) + # Convert the Vim scripts to (what looks like) Javascript + $(VIM) -u NONE --not-a-term -S tojavascript.vim $(PACKAGE).pot $(PO_VIM_INPUTLIST) + # create vim.pot + $(XGETTEXT) --default-domain=$(PACKAGE) --add-comments \ + --keyword=_ --keyword=N_ --keyword=NGETTEXT:1,2 \ + $(PO_INPUTLIST) $(PO_VIM_JSLIST) + mv -f $(PACKAGE).po $(PACKAGE).pot + # Fix Vim scripts names, so that "gf" works + $(VIM) -u NONE --not-a-term -S fixfilenames.vim $(PACKAGE).pot $(PO_VIM_INPUTLIST) + # Delete the temporary files + rm *.js vim.desktop: vim.desktop.in $(POFILES) echo $(LANGUAGES) | tr " " "\n" |sed -e '/\./d' | sort > LINGUAS diff --git a/src/po/README.txt b/src/po/README.txt index e60d1d216..68d267af1 100644 --- a/src/po/README.txt +++ b/src/po/README.txt @@ -78,7 +78,8 @@ language. (2) Translate See the gettext documentation on how to do this. You can also find - examples in the other po files. + examples in the other po files. You can use "gF" on the file name to see + the context of the message. Search the po file for items that require translation: /fuzzy\|^msgstr ""\(\n"\)\@! @@ -123,6 +124,13 @@ language. Look out for syntax errors and fix them. +(6) Local tryout: + Vim normally picks up the .mo files from: + $VIMRUNTIME/lang/{lang}/LC_MESSAGES/vim.mo + To try out the messages with Vim use: + make tryoutinstall + And run Vim with $VIMRUNTIME set to ../runtime + USING GETTEXT WITHOUT ICONV diff --git a/src/po/fixfilenames.vim b/src/po/fixfilenames.vim new file mode 100644 index 000000000..65d448ce4 --- /dev/null +++ b/src/po/fixfilenames.vim @@ -0,0 +1,13 @@ +" Invoked with the name "vim.pot" and a list of Vim script names. +" Converts them to a .js file, stripping comments, so that xgettext works. + +set shortmess+=A + +for name in argv()[1:] + let jsname = fnamemodify(name, ":t:r") .. ".js" + exe "%s+" .. jsname .. "+" .. name .. "+" +endfor + +write +last +quit diff --git a/src/po/tojavascript.vim b/src/po/tojavascript.vim new file mode 100644 index 000000000..7868570be --- /dev/null +++ b/src/po/tojavascript.vim @@ -0,0 +1,18 @@ +" Invoked with the name "vim.pot" and a list of Vim script names. +" Converts them to a .js file, stripping comments, so that xgettext works. +" Javascript is used because, like Vim, it accepts both single and double +" quoted strings. + +set shortmess+=A + +for name in argv()[1:] + exe 'edit ' .. fnameescape(name) + + " Strip comments + g/^\s*"/s/.*// + + " Write as .js file, xgettext recognizes them + exe 'w! ' .. fnamemodify(name, ":t:r") .. ".js" +endfor + +quit |