From 07171e1b3c8b379c9f7b39afb943794e8e966e4b Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 29 Oct 2025 20:39:00 +0100 Subject: [PATCH 30/48] apparently for loop was unstable --- src/osx/core/uilocale.mm | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/osx/core/uilocale.mm b/src/osx/core/uilocale.mm index 1ee08f189e..2efcb77cd9 100644 --- a/src/osx/core/uilocale.mm +++ b/src/osx/core/uilocale.mm @@ -103,9 +103,9 @@ explicit wxUILocaleImplCF(NSLocale* nsloc) // completely invalid strings, so we need to check if the name is // actually in the list of the supported locales ourselves. bool isAvailable = false; - NSString* availableLocaleId = NULL; + NSArray* availableLocaleIds = [NSLocale availableLocaleIdentifiers]; - wxOBJC_FOR_LOOP( NSString* nsLocId, [NSLocale availableLocaleIdentifiers] ) + wxOBJC_FOR_LOOP( NSString* nsLocId, availableLocaleIds ) { // We can't simply compare the names here because the list returned // by NSLocale is incomplete and doesn't contain all synonyms, e.g. @@ -116,6 +116,7 @@ explicit wxUILocaleImplCF(NSLocale* nsloc) const auto availId = wxLocaleIdent::FromTag(strId); if ( availId.IsEmpty() ) { + // wxLogTrace("Failed to parse locale identifier %s" , [nsLocId UTF8String]); wxLogDebug("Failed to parse locale identifier \"%s\"", strId); continue; } @@ -135,31 +136,27 @@ explicit wxUILocaleImplCF(NSLocale* nsloc) isAvailable = availId.GetRegion() == locId.GetRegion(); } } - else if (!locId.GetRegion().empty() ) - { - isAvailable = availId.GetRegion() == locId.GetRegion(); - } else { - // No script or region specified, language match is enough. - isAvailable = true; + isAvailable = availId.GetRegion() == locId.GetRegion(); } } if ( isAvailable ) - { - availableLocaleId = nsLocId; break; - } } wxOBJC_END_FOR_LOOP if ( !isAvailable ) + { + wxLogTrace("locale", "no match found for %s" , locId.GetTag().c_str()); return nullptr; + } wxCFStringRef cfName(locId.GetName()); - NSLocale* nsloc = [[NSLocale alloc] initWithLocaleIdentifier: cfName.AsNSString()]; + NSLocale* nsloc = [[NSLocale alloc] initWithLocaleIdentifier:cfName.AsNSString()]; if ( !nsloc ) return nullptr; + [nsloc autorelease]; return new wxUILocaleImplCF(nsloc); -- 2.24.3 (Apple Git-128)