Re[2]: Unexpected encoding issue with _() macro and UTF-8 source in Unicode build (wxWidgets 3.3.1)

Vadim Zeitlin <[email protected]> Fri, 14 Nov 2025 18:07:51 +0100
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
On Fri, 14 Nov 2025 17:46:51 +0100 Claudio Fabiano Rossato wrote:

CFR> Thanks for the explanation — it clarifies the behavior of |_()|.
CFR> 
CFR> I understand now that the argument is always treated as an ASCII key. I 
CFR> still find it surprising that this means a program cannot be written in 
CFR> Italian first and then translated to English. It seems that with 
CFR> wxWidgets, multi-language programs must always start with English strings.

 This is not quite correct, message IDs can use any encoding, it just needs
to be specified in the message catalog. OTOH _all_ "char*" string are
assumed to be in the current locale encoding by wxString, and this is not
specific to _() at all. Unfortunately, while the current locale encoding is
almost always UTF-8 under Unix systems (including macOS), this is almost
never the case under Windows. You may set it explicitly, but if you don't
change the current locale, its encoding will be CP1252 and not UTF-8 by
default.

 If you're sure that all your strings are in UTF-8, you may build wxWidgets
in UTF-8-only mode, but this is not the default. Alternatively, and
actually recommended if you are not working with a legacy code base where
this can be difficult to do, define wxNO_IMPLICIT_WXSTRING_ENCODING when
building your project (you do _not_ have to rebuild wxWidgets for this) to
get errors for all implicit conversions from "char*" as this will force you
to specify the (hopefully correct) encoding for all of them.

 See https://wxwidgets.org/blog/2020/08/implicit_explicit_encoding/ for
more details.

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
              https://www.tt-solutions.com/
signature.asc (application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE-----

iF0EABECAB0WIQQx+vLQdOwioQqkxtoG6kHeT2wehgUCaRdh5wAKCRAG6kHeT2we
hk8rAJ9j5PB4kAR3rAfXrhsnockVKcJpggCdHThSJOAIV8HXRcLPsmcX4na3cjc=
=8hGI
-----END PGP SIGNATURE-----