Skip to content

Localisation replaces all instances of fallback languages of a layer #855

Closed
@sosthoff

Description

@sosthoff

Environment

  • Xcode version: 13.1
  • iOS version: 15.0.2
  • Devices affected: all
  • Maps SDK Version: 10.1.0

Observed behavior and steps to reproduce

Setting

let deLocale = Locale(identifier: "de")
            do {
                try style.localizeLabels(into: deLocale)

results in all name_* of every layer to be overridden with name_de

Expected behavior

Only the primary localized language should be overridden.

Notes / preliminary analysis

Style+Localization::updateExpression applies to all occurrences in range

Fix

Add

    /// Updates string once using the first occurrence of a regex
    /// - Parameters:
    ///   - replacement: New string to replace the matched pattern
    ///   - regex: The regex pattern that will be matched for replacement
    internal mutating func updateOnceExpression(replacement: String, regex: NSRegularExpression) {
        var range = NSRange(location: 0, length: self.count)
        range = regex.rangeOfFirstMatch(in: self, options: [], range: range)
        if (range.lowerBound == NSNotFound) {
            return
        }
        self = regex.stringByReplacingMatches(in: self,
                                              options: [],
                                              range: range,
                                              withTemplate: replacement)
    }

and replace
stringExpression.updateExpression(replacement: replacement, regex: expressionCoalesce)
with
stringExpression.updateOnceExpression(replacement: replacement, regex: expressionCoalesce)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something is broken!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions