Translate fails to run on Windows
I'm running on Windows 10 and bash is available on my system.
When the library is running on my system any call to translate launch a process of the kind:
C:\Windows\system32\cmd.exe /c (^(C:\Windows\system32\cmd.exe C:\Users\vds\AppData\Local\Temp\VWS6C41.tmp^) ^>C:\Users\vds\AppData\Local\Temp\V3F6C42.tmp 2^>^&1)
That doesn't return.
To solve the problem I have disabled the translation for win32 systems:
function! s:translate(id) dict abort
let cache = lh#dict#let(s:k_cached_translations, self._env.LANG .'.'. self._env.TEXTDOMAIN, {})
if !has_key(cache, a:id)
if executable('bash') && !has('win32')
let cache[a:id] = lh#os#system('bash -c '.shellescape('echo $"'.a:id.'"'), self._env)
else
" TODO: support windows
let cache[a:id] = a:id
endif
endif
return cache[a:id]
endfunction
Let me know if you would be interested by a Pull Request.
Actually, it's a bit more subtle as this works well with gvim-win32 + cygwin-bash + &shell==bash.
What I see is that it doesn't work at all when I revert my 'shell' option to cmd -- as I then execute a command file (with &shell) that sets environment variables with the syntax used with Unix shells instead of the Windows CMD syntax.
A quick and dirty patch would be to test &shell instead of has('win*'), but instead I'll try to fix this improper code behind lh#os#new_runner_script() if possible.
BTW, if you change your &shell to bash (it'll require to change a few other settings along the way -- see for instance my :GoBash command from system-tools), can you correctly execute things like : echo lh#po#context().translate('[Quickfix List]') ?
Let me know if the fix does the job for you.
If I trigger that command I get a cmd window with the following content hanging:
C:\Windows\system32\cmd.exe /c (^(C:\Windows\system32\cmd.exe C:\Users\vds\AppData\Local\Temp\VSK604D.tmp^) ^>C:\Users\vds\AppData\Local\Temp\VZ7604E.tmp 2^>^&1)
I'll try the same with :set shell=bash and let you know.
With :set shell=bash I got the following error message:
Error detected while processing function <SNR>165_translate[4]..lh#os#system[14]..function <SNR>165_translate[4]..lh#os#system[11]..<SNR>167_run_script:
line 2:
E282: Cannot read from "C:\Users\vds\AppData\Local\Temp\VZ7616D.tmp"
Hum. I see we don't use the same settings for the shell options -- I've forfeited on the official standard ones 2 decades ago.
Have you updated lh-vim-lib to use the latest version? I've tried to address a few issues. Even with shell==cmd, hopefully it should works (as long as it was already possible to run system("somebatchscript.cmd") with your configuration.
Here is the error message I got when I run: echo lh#po#context().translate('[Quickfix List]')
/bin/bash: line 1: Quickfix List: syntax error in expression (error token is "List")
Here is the error message I got with the new version when I try to decode a trace (WTF)
Error detected while processing function lh#exception#say_what:
line 3:
E767: Too many arguments for printf()
I have uninstalled WSL2 that was providing bash and without WSL2 it now works. But I suppose if I install it back I'll have the problem.
But this version is already more robust :-)
Thanks for the support. Vivian.
Unfortunately I don't have WSL/2 installed on my machines. I'll try to come up with a command file to execute from DOS console in a first time to see whether the problem comes from executing WSL2's bash from the command file or executing the command file with standard Vim settings for the &shell options.
Also, your Vim seems to be in English, I should be able to detect that and completely shortcut the localization of the messages.
I'll see what I can do.
Thanks for the update. If you have something I'll be glad to test. Do I understand correctly that Vim use the shell to translate its messages? Why do we need to run a shell command to get the translation?
That's the only way I've found to translate messages from the .po files -- without requiring to install 3rd party executables.
I guess I could have used python... hum...
Would you mind trying to execute the following .cmd file from a DOS prompt?
@echo off
set LANG=fr_FR.UTF-8
set TEXTDOMAINDIR=C:\Progra~1\dev\Vim\vim81/lang
set TEXTDOMAIN=vim
bash -c 'echo $"[Quickfix List]"'
You'll have to replace the TEXTDOMAINDIR with the lang/ directory under $VIMRUNTIME
If this works, the next step would be to execute it from Vim with system() command:
" Expecting &shell to be cmd
:echo system('test-po-translate.cmd')
I'll do that. I have to reinstall WSL it will take me a bit of time. I hope to complete it over the weekend. Thanks again for your support :-)
One difficulty I see is that bash is running in WSL but Vim is running in Windows (in WSL you could have Vim or not or not the same version than in Windows)
Take your time, I'm the on who should be thanking you for your time and feedbacks.
I haven't had the opportunity to use WSL yet. So far, I've struggled plenty to make gvim-win32 works when launched from Cygwin (there are quite a few issues related to pathname conversion).
(I did not know it was possible to directly run a WSL executable from a windows executable. I imagined it to be completely isolated, and to require specific proxy commands (like a docker run whatever...).)
I made two experiments:
within WSL:
After running the wsl command in a bash shell of Ubuntu with Vim 8.2 installed)
export TEXTDOMAINDIR=/usr/share/vim/vim82/lang
export LANG=fr_FR.UTF-8
export TEXTDOMAIN=vim
echo $"[Quickfix List]"
Output:
[Quickfix List]
within cmd:
Within a windows shell (cmd) with Vim 9.0 installed
set LANG=fr_FR.UTF-8
set TEXTDOMAINDIR=C:\Softs\vim90\lang
set TEXTDOMAIN=vim
bash -c 'echo $"[Quickfix List]"'
Output:
[Quickfix List]
While it doesn't seem to crash (which is a good start), it doesn't seem to work either (as the messages isn't translated into French :/)
How could I verify that the translation are correctly installed on the two systems. I'm a bit surprised that the first test fails since it should be a "pure" Linux system. I can start vim 8.2 on that system correctly.
In $VIMRUNTIME, there should be a lang/fr/LC_MESSAGES/vim.mo file. And many others for different LANG values.
I read shopt value may impact the required quote characters: https://www.gnu.org/software/bash/manual/html_node/Locale-Translation.html
The files are there but translation doesn't seems to work :-/