Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate fails to run on Windows #19

Open
vds2212 opened this issue Dec 19, 2023 · 19 comments
Open

Translate fails to run on Windows #19

vds2212 opened this issue Dec 19, 2023 · 19 comments
Assignees
Labels

Comments

@vds2212
Copy link

vds2212 commented Dec 19, 2023

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.

@LucHermitte LucHermitte self-assigned this Dec 26, 2023
@LucHermitte
Copy link
Owner

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]') ?

@LucHermitte
Copy link
Owner

Let me know if the fix does the job for you.

@vds2212
Copy link
Author

vds2212 commented Dec 27, 2023

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.

@vds2212
Copy link
Author

vds2212 commented Dec 27, 2023

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"

@LucHermitte
Copy link
Owner

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.

@vds2212
Copy link
Author

vds2212 commented Dec 27, 2023

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()

@vds2212
Copy link
Author

vds2212 commented Dec 29, 2023

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.

@LucHermitte
Copy link
Owner

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.

@LucHermitte LucHermitte reopened this Jan 5, 2024
@vds2212
Copy link
Author

vds2212 commented Jan 5, 2024

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?

@LucHermitte
Copy link
Owner

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...

@LucHermitte
Copy link
Owner

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')

@vds2212
Copy link
Author

vds2212 commented Jan 5, 2024

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 :-)

@vds2212
Copy link
Author

vds2212 commented Jan 5, 2024

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)

@LucHermitte
Copy link
Owner

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...).)

@vds2212
Copy link
Author

vds2212 commented Jan 5, 2024

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]

@LucHermitte
Copy link
Owner

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 :/)

@vds2212
Copy link
Author

vds2212 commented Jan 5, 2024

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.

@LucHermitte
Copy link
Owner

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

@vds2212
Copy link
Author

vds2212 commented Jan 5, 2024

The files are there but translation doesn't seems to work :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants