Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sosthoff opened this issue Nov 22, 2021 · 1 comment · Fixed by #856
Closed

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

sosthoff opened this issue Nov 22, 2021 · 1 comment · Fixed by #856
Labels
bug 🪲 Something is broken!

Comments

@sosthoff
Copy link
Contributor

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)

@sosthoff sosthoff added the bug 🪲 Something is broken! label Nov 22, 2021
@sosthoff
Copy link
Contributor Author

Commit for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something is broken!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant