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

Fix to only localize the primary localization and not the fall-throug… #856

Merged
merged 5 commits into from
Nov 23, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Sources/MapboxMaps/Style/Style+Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension Style {

if var stringExpression = String(data: try JSONEncoder().encode(symbolLayer.textField), encoding: .utf8),
stringExpression != "null" {
stringExpression.updateExpression(replacement: replacement, regex: expressionCoalesce)
stringExpression.updateOnceExpression(replacement: replacement, regex: expressionCoalesce)
stringExpression.updateExpression(replacement: replacement, regex: expressionAbbr)

// Turn the new json string back into an Expression
Expand Down Expand Up @@ -113,4 +113,19 @@ extension String {
range: range,
withTemplate: replacement)
}

/// 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)
macdrevx marked this conversation as resolved.
Show resolved Hide resolved
range = regex.rangeOfFirstMatch(in: self, options: [], range: range)
if (range.lowerBound == NSNotFound)
return
macdrevx marked this conversation as resolved.
Show resolved Hide resolved
self = regex.stringByReplacingMatches(in: self,
options: [],
range: range,
withTemplate: replacement)
}
}