MINGW-packages icon indicating copy to clipboard operation
MINGW-packages copied to clipboard

GCC Localization Unsuccessful

Open zsd2024 opened this issue 1 year ago • 11 comments

I attempted to localize GCC in the MSYS2 environment but was unsuccessful. I have followed these steps:

  1. Generate the gcc.mo file using the gettext tool:

    msgfmt -o gcc.mo gcc.po
    
  2. Place the gcc.mo file in the /usr/share/locale/zh_CN/LC_MESSAGES/ directory:

    mkdir -p /usr/share/locale/zh_CN/LC_MESSAGES/
    cp gcc.mo /usr/share/locale/zh_CN/LC_MESSAGES/
    
  3. Set the environment variables:

    export LANG=zh_CN.UTF-8
    export LC_ALL=zh_CN.UTF-8
    
  4. Restart the terminal and run GCC, but the output is still in English.

Environment Information:

  • Operating System: Windows 11
  • MSYS2 Version: Latest
  • GCC Version: 14.2.0

Tried Solutions:

  • Ensure the gettext-devel package is installed:
    pacman -S gettext-devel
    

Error Messages or Logs: No specific error messages, but the GCC output is still in English.

What else should I check or try?

zsd2024 avatar Aug 08 '24 07:08 zsd2024

This is what I get here, without any changes:

$ LANG=zh_CN.utf8 gcc
gcc: 致命错误:没有输入文件
编译中断。

lazka avatar Aug 09 '24 14:08 lazka

4. Restart the terminal and run GCC, but the output is still in English.

Are you persisting the changed locale settings somewhere? Otherwise I don't see how that would work with a fresh environment.

lazka avatar Aug 11 '24 08:08 lazka

  1. 重新启动终端并运行 GCC,但输出仍为英文。

您是否在某处保留了更改的区域设置?否则,我看不出这在新鲜环境中如何工作。

Apologies, but I didn't quite catch your question. Could you please rephrase it in English? I'm having trouble understanding your statement: "您是否在某处保留了更改的区域设置?否则,我看不出这在新鲜环境中如何工作。"

However, when I run this command, I get:

$ LANG=zh_CN.utf8 gcc
gcc.exe: fatal error: no input files
compilation terminated.

zsd2024 avatar Aug 12 '24 09:08 zsd2024

This is my installation folder directory tree: tree.txt

zsd2024 avatar Aug 12 '24 09:08 zsd2024

@lazka Additionally, the system I am using is Windows 11 instead of Windows 10, and what I actually want to localize is g++.

zsd2024 avatar Aug 12 '24 09:08 zsd2024

~~Did you install MSYS2 to a non-default directory?~~

lhmouse avatar Aug 12 '24 11:08 lhmouse

Apologies, but I didn't quite catch your question. Could you please rephrase it in English? I'm having trouble understanding your statement: "您是否在某处保留了更改的区域设置?否则,我看不出这在新鲜环境中如何工作。"

export 仅是指定此处定义的环境变量会继承给子进程。如果你重启了终端,原来定义的环境变量就没有了。

你可以在 mintty 的 Text 设置中设定使用的语言,这会影响所有 mintty 内的进程。你也可以在系统设置里设定 LANG 环境变量,这会影响所有的进程,包括那些从 cmd 或者 PowerShell 中启动的。

However, when I run this command, I get:

$ LANG=zh_CN.utf8 gcc
gcc.exe: fatal error: no input files
compilation terminated.

which gcc 输出的是什么?目前只有 /usr/bin/gcc 支持本地化。

lhmouse avatar Aug 12 '24 11:08 lhmouse

Apologies, but I didn't quite catch your question. Could you please rephrase it in English? I'm having trouble understanding your statement: "您是否在某处保留了更改的区域设置?否则,我看不出这在新鲜环境中如何工作。"

export 仅是指定此处定义的环境变量会继承给子进程。如果你重启了终端,原来定义的环境变量就没有了。

你可以在 mintty 的 Text 设置中设定使用的语言,这会影响所有 mintty 内的进程。你也可以在系统设置里设定 LANG 环境变量,这会影响所有的进程,包括那些从 cmd 或者 PowerShell 中启动的。

However, when I run this command, I get:

$ LANG=zh_CN.utf8 gcc
gcc.exe: fatal error: no input files
compilation terminated.

which gcc 输出的是什么?目前只有 /usr/bin/gcc 支持本地化。

@lhmouse

MSYS:

which: no gcc in (/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)

UCRT64:

/ucrt64/bin/gcc

MINGW64:

/mingw64/bin/gcc

I am using gcc with UCRT64.

zsd2024 avatar Aug 13 '24 03:08 zsd2024

~Did you install MSYS2 to a non-default directory?~

Yes, I installed it in the D:\Greens\msys2 directory.

zsd2024 avatar Aug 13 '24 03:08 zsd2024

MINGW64:

/mingw64/bin/gcc

I am using gcc with UCRT64.

Native language support (NLS) is not enabled for UCRT64 GCC:

lh_mouse@lhmouse-pc ~ $ gcc -v 2>&1 | fgrep nls Configured with: ../gcc/configure --prefix=/ucrt64 --with-local-prefix=/ucrt64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/ucrt64/include --libexecdir=/ucrt64/lib --disable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=mcf --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --enable-__cxa_atexit --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/ucrt64 --with-mpfr=/ucrt64 --with-mpc=/ucrt64 --with-isl=/ucrt64 --with-pkgversion='GCC with MCF thread model, built by LH_Mouse' --with-bugurl=https://github.com/lhmouse/MINGW-packages/issues --disable-libstdcxx-debug --enable-plugin

You can try building GCC yourself, but the locale directory is quirky to setup. I don't remember much of the details. It's likely that only messages from gcc.exe are localized; those from a compiler e.g. cc1.exe or cc1plus.exe are not. The bindtextdomain() function assumes executables are placed in bin directory and looks for locale files via a relative path (..\share\locale I suspect). You will need to copy locale files to a location where they can be found by this relative path.

lhmouse avatar Aug 13 '24 03:08 lhmouse

See also: https://github.com/niXman/mingw-builds/issues/666

lhmouse avatar Sep 05 '24 00:09 lhmouse

is #24750 PR related to this issue?

ognevny avatar Jul 10 '25 12:07 ognevny

is #24750 PR related to this issue?

Maybe, if we want to do the same.

lhmouse avatar Jul 10 '25 12:07 lhmouse

It's not working, the output is invalid encoding:

$ ./riscv64-juntian-elf-cc.exe
riscv64-juntian-elf-cc.exe: 鑷村懡閿欒锛?[m娌℃湁杈撳叆鏂囦欢

缂栬瘧涓柇銆?

This is for mingw, not for msys2.

Maybe it's comes from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108865

Because --enable-win32-utf8-manifest is by default for windows 11,

Yeah, I am verified it, when use --disable-win32-utf8-manifest, it working.

lygstate avatar Dec 21 '25 09:12 lygstate