Using windows-1251 in Linux

32 views
Skip to first unread message

Сергей Коныгин

unread,
Jun 28, 2022, 2:50:05 PMJun 28
to wx-users
I created a large propgram for Windows unsing GCC and wxWidgets. An encoding of sources and a lot of data files is 8-bit windows-1251.
Now I'm trying to build this propgram also for Linux.
But there are no errors only if I use wxT() and convert all files to utf-8.
I'm searching for an easy way to continue using windows-1251.
How can I do it?

Igor Korot

unread,
Jun 28, 2022, 3:20:19 PMJun 28
to wx-u...@googlegroups.com
Hi,
Are you having a problem with compilation or working with data files?
If the former - what error messages did you get?
If the latter - how do you read the files?

Thank you.

>
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/55c8417e-18bc-460c-918a-831755a73697n%40googlegroups.com.

Vadim Zeitlin

unread,
Jun 28, 2022, 3:30:35 PMJun 28
to wx-u...@googlegroups.com
On Tue, 28 Jun 2022 11:50:05 -0700 (PDT) Сергей Коныгин wrote:

СК> I created a large propgram for Windows unsing GCC and wxWidgets. An
СК> encoding of sources and a lot of data files is 8-bit windows-1251.

For the sources you should be able to use -finput-charset option. For the
data files it really depends on how do you read them, wxWidgets provides
wxCSConv which can be used to convert them from CP-1251.

СК> I'm searching for an easy way to continue using windows-1251.

FWIW while you _can_ do it, I strongly recommend converting everything to
UTF-8 instead, it's the only sane way. But, again, if you really want to do
it in a more complicated confusing way, you can keep using CP-1251 too.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Сергей Коныгин

unread,
Jun 28, 2022, 3:53:42 PMJun 28
to wx-users
Ok. Is there some way to get round wxT()? Because I need to replace thousands strings :(

вторник, 28 июня 2022 г. в 23:30:35 UTC+4, Vadim Zeitlin:

Vadim Zeitlin

unread,
Jun 28, 2022, 4:00:55 PMJun 28
to wx-u...@googlegroups.com
On Tue, 28 Jun 2022 12:53:42 -0700 (PDT) Сергей Коныгин wrote:

СК> Ok. Is there some way to get round wxT()?

You never need wxT() with wx 3 or later, but if you have thousands of
strings using CP-1251 hard-coded into your program, you are still going to
do something about them because assigning them to wxString will only work
correctly if the runtime encoding is CP-1251 -- which is never going to be
the case under Linux (nor under many localized versions of Windows, BTW, so
it's not like your program could work correctly there neither).

Quentin Cosendey

unread,
Jun 28, 2022, 5:02:50 PMJun 28
to wx-u...@googlegroups.com
Hello,


If you want to keep source files in windows-1251, I don't see many
solutions except redefining the macro wxT to something like this:

#undef wxT

#define wxT(S) wxString(S, csConv, sizeof(S))

With an appropriate csConv:

wxMBConv csConv(wxFONTENCODING_CP1251);


However, I agree with VZ, it would be simpler to convert your source
files into UTF-8. It's perfectly doable in batch, once for all, and then
you won't be bothered with that ever again.

Under linux you can do it with iconv.

Under windows, I can suggest a little utility of my own

http://github.com/qtnc/chenc


Or, even better, move out all your strings into translation files. This
is quite some work, but it would allow your program to be translated.
Unless you are writing a region-specific software you are pretty sure to
never distribute outside, it's probably never a waste of effort to make
translation possible.

Kenneth Porter

unread,
Jun 28, 2022, 10:37:36 PMJun 28
to wx-u...@googlegroups.com
--On Wednesday, June 29, 2022 12:02 AM +0200 Quentin Cosendey
<quentin....@bluewin.ch> wrote:

> Or, even better, move out all your strings into translation files. This
> is quite some work, but it would allow your program to be translated.
> Unless you are writing a region-specific software you are pretty sure to
> never distribute outside, it's probably never a waste of effort to make
> translation possible.

What do people do about the what() strings in application exceptions? Those
are my only user-facing strings in my library. All other strings are XML
tags in ASCII. Is there a best practice for exception strings that get
translated by the client application before logging or display?

Сергей Коныгин

unread,
Jun 28, 2022, 11:30:15 PMJun 28
to wx-users
I created a new project. All files in UTF-8.
But my non-english string is empty.
Window titles is empty.
When I create a menu item there is an error "A non-stock menu item with an empty label?"
If I use wxT it works nice :(

среда, 29 июня 2022 г. в 00:00:55 UTC+4, Vadim Zeitlin:

Сергей Коныгин

unread,
Jun 29, 2022, 12:30:28 AMJun 29
to wx-users
If I use everywhere L"some string" it works nice

среда, 29 июня 2022 г. в 07:30:15 UTC+4, Сергей Коныгин:

Quentin Cosendey

unread,
Jun 29, 2022, 12:32:04 AMJun 29
to wx-u...@googlegroups.com
Hello,


> What do people do about the what() strings in application exceptions?
Those are my only user-facing strings in my library. All other strings
are XML tags in ASCII. Is there a best practice for exception strings
that get translated by the client application before logging or display?


Don't translate output in log files. This will help users to search the
error message in google.


In theory, the non-technical user isn't supposed to ever see the
contents of what(). It's anyway difficult to translate them, because as
far as I know, the exact content of the message aren't standard, they
are different across different compilers and versions.


For translations in general, wxWidgets provite tools to do it with
gettext. Personally I don't use it, tough. I prefer my own system with
plain old key=value files.

Lauri Nurmi

unread,
Jun 29, 2022, 2:59:03 AMJun 29
to wx-u...@googlegroups.com
On Wed, 29 Jun 2022, Quentin Cosendey wrote:

>> What do people do about the what() strings in application exceptions?
>> Those are my only user-facing strings in my library. Is there a best
>> practice for exception strings that get translated by the client
>> application before logging or display?
>
> Don't translate output in log files. This will help users to search the error
> message in google.

If the ability to search things with Google is the priority, then arguably
one should not translate any messages in the application.

The point of localization is to show messages in the user's preferred
language, and leaving user-readable log messages unlocalized for the sake
of Google sounds suboptimal. After all, in some cases the user may not be
able to understand the untranslated source language.

What I would do, if googlability is considered important, is to prefix
each log message with a unique numeric code, something like: "E1234: out
of disk space".

> In theory, the non-technical user isn't supposed to ever see the contents of
> what().

This entirely depends on how the code uses exceptions. If we are talking
about exceptions thrown by the standard C++ library, then yes, those tend
to be about pretty fatal conditions, and should not occur during normal
operation. But one's own exceptions may well be used for regular error
handling and returning user-readable error messages.
Reply all
Reply to author
Forward
0 new messages