Skip to content

Unable to localize labels into Chinese #652

Open
@1ec5

Description

@1ec5

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:

let supportedLocaleIdentifiers = ["ar", "de", "en", "es", "fr", "it", "ja", "ko", "pt", "ru", "vi", "zh", "zh-Hans", "zh-Hant", "zh-Hant-TW"]

However, it matches the passed-in Locale’s bare language code against that list:

// Do nothing if we do not support the locale
if !supportedLocaleIdentifiers.contains(locale.languageCode!) {
return nil
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something is broken!p3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions