Skip to content

LCIDToLocaleName may return wrong language tag for transient language identifiers #82367

@DJm00n

Description

@DJm00n

It turns out that the LCIDToLocaleName API, which is used inside CultureInfo, can return incorrect names for transient language identifiers:

  • 0x2000 - LOCALE_TRANSIENT_KEYBOARD1
  • 0x2400 - LOCALE_TRANSIENT_KEYBOARD2
  • 0x2800 - LOCALE_TRANSIENT_KEYBOARD3
  • 0x2C00 - LOCALE_TRANSIENT_KEYBOARD4

For example, it returns "nqo-GN" and "jv-Java-ID" instead of the language tags "nqo" and "jv-Java" (as seen in the Get-WinUserLanguageList PowerShell cmdlet). In this case, both languages mapped to the same transient language identifier.

Consider add parent culture check into CultureData GetCultureData(int culture, bool bUseUserOverride) to look at the parent language if it has the same language identifier as we requested and use parent in such cases:

if (IsCustomCultureId(retVal.LCID) && PInvoke.LocaleNameToLCID(retVal.ParentName, 0) == culture)
{
    retVal = GetCultureData(culture.ParentName, bUseUserOverride);
}

Found this bug when testing dotnet/winforms#8573

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions