Opened 19 months ago

Closed 5 months ago

#15006 closed defect (port to stable)

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: Blocking:
Patch: yes

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.

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

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

intl.diff download (821 bytes) - added by pm_kan 19 months ago.

Download all attachments as: .zip

Change History (7)

Changed 19 months ago by pm_kan

comment:1 follow-up: Changed 19 months ago by neis

  • Resolution set to port to stable
  • Status changed from new to portneeded

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

comment:2 in reply to: ↑ 1 Changed 19 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.

comment:3 Changed 19 months ago by neis

  • Status changed from portneeded to new

comment:4 Changed 19 months ago by VZ

  • Resolution changed from port to stable to fixed
  • Status changed from new to closed

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

comment:5 Changed 19 months ago by neis

  • Resolution changed from fixed to port to stable
  • Status changed from closed to portneeded

comment:6 Changed 5 months ago by vadz

  • Status changed from portneeded to closed

As we don't plan to make any more 2.8 releases, closing all bugs with "port to 2.8 needed" status.

Note: See TracTickets for help on using tickets.