Ticket #15006 (portneeded defect: port to stable)

Opened 4 months ago

Last modified 4 months ago

wxLocale::GetSystemLanguage() should ignore empty LANG_*/LC_* variables

Reported by: pm_kan Owned by:
Priority: normal Milestone:
Component: base Version: 2.8.12
Keywords: Cc:
Blocked By: Patch: yes
Blocking:

Description

In *NIX builds current version of wxLocale::GetSystemLanguage() returns wxLANGUAGE_UNKNOWN if LC_ALL is set but empty, ignoring non-empty LC_MESSAGES/LANG variables.

It's standard way to ignore empty (null) environment variables in that case. For example, man 7 locale says:

If the second argument to setlocale(3) is empty string, "", for
the default locale, it is determined using the following steps:

1. If there is a non-null environment variable LC_ALL, the

value of LC_ALL is used.

2. If an environment variable with the same name as one of

the categories above exists and is non-null, its value is
used for that category.

3. If there is a non-null environment variable LANG, the

value of LANG is used.

Steps to reproduce:
set environment variables to
LC_ALL=
LANG=ru_RU.UTF-8

GetSystemLanguage() will return wxLANGUAGE_UNKNOWN instead of wxLANGUAGE_RUSSIAN.

Attachments

intl.diff download (0.8 KB) - added by pm_kan 4 months ago.

Change History

Changed 4 months ago by pm_kan

follow-up: ↓ 2   Changed 4 months ago by neis

  • status changed from new to portneeded
  • resolution set to port to stable

Seems to have been fixed in the trunk, see #2996. So I'll mark it as needing a backport?

in reply to: ↑ 1   Changed 4 months ago by pm_kan

Replying to neis:

Seems to have been fixed in the trunk, see #2996. So I'll mark it as needing a backport?

#2996 is different from this. It seems, that before #2996 fix only LC_ALL was checked when detecting system locale. Current version in wx_2_8_branch and in master branch look for locale in LC_ALL, LC_MESSAGES and LANG variables, but don't check if variable is empty (so #2996 is already in 2.8).

Current code in master ( https://github.com/wxWidgets/wxWidgets/blob/7582edfbf9029a4f4a010329c1cd6bc7c1d084c4/src/common/intl.cpp#L595) have the same "if" as 2.8 branch:
if (!wxGetEnv(wxS("LC_ALL"), &langFull) &&

!wxGetEnv(wxS("LC_MESSAGES"), &langFull) &&
!wxGetEnv(wxS("LANG"), &langFull))

when LC_ALL="" and LANG="ru_RU.UTF-8" evaluation in "if" will be stopped after first condition (LC_ALL is defined) and langFull will contain empty string. Then lang variable will be empty too, so function result will be wxLANGUAGE_UNKNOWN.
If we add a check for langFull emptiness (for example, as in attached patch), evaluation in the "if" condition breaks only after extracting LANG value to langFull and function will return correct value.

  Changed 4 months ago by neis

  • status changed from portneeded to new

  Changed 4 months ago by VZ

  • status changed from new to closed
  • resolution changed from port to stable to fixed

(In [73466]) Ignore empty LC_XXX variables in locale detection code.

If LC_ALL or LC_MESSAGES is set but empty, ignore it and use the next
environment variable. This is consistent with the standard setlocale()
behaviour which only uses LC_ALL if it is set and not empty.

Closes #15006.

  Changed 4 months ago by neis

  • status changed from closed to portneeded
  • resolution changed from fixed to port to stable
Note: See TracTickets for help on using tickets.