Description
Style.localizeLabels(into:forLayerIds:)
is unable to localize the map’s labels into Simplified Chinese or, one of the locales supported by Mapbox Streets source v8. Attempting to localize the labels into Simplified Chinese results in a symbol layer that is either unlocalized or completely blank. This issue also affects Hong Kong Traditional Chinese.
Diagnosis
As of #480, Style.getLocaleValue(locale:)
hard-codes the locale codes supported by Mapbox Streets source v8:
However, it matches the passed-in Locale’s bare language code against that list:
mapbox-maps-ios/Sources/MapboxMaps/Style/Style+Localization.swift
Lines 40 to 43 in 34ea7ad
A phone may be set to a Locale with the identifier zh-Hant-HK
, meaning Hong Kong Traditional Chinese. But this Locale’s language code is just zh
, so despite zh-Hant
being supported by the Streets source, the method ends up localizing into zh
, which is just Chinese. The special logic to map zh-Hant-TW
to zh-Hant
does not apply to zh-Hant-HK
.
Another common identifier is zh-Hans-CN
, which also falls through the cracks and gets mapped to just zh
.
convertExpressionForLocalization(symbolLayer:localeValue:)
ends up replacing each name_en
get expression with a name_zh
get expression. But the Streets source no longer supports the generic zh
locale as of v8; instead, only name_zh-Hans
and name_zh-Hant
fields are provided. Depending on the style’s fallback rules, the label will either appear in the local language rather than Chinese, or it will be blank.
Suggestion
supportedLocaleIdentifiers
should be a list of locale codes that appear in the names of name_*
fields in the Streets source – nothing less, nothing more.
When matching against this array, check both Locale.languageCode
and Locale.regionCode
.
/cc @mapbox/maps-ios @mapbox/navigation-ios