Skip to content

Commit 45550b4

Browse files
authored
Display localized road name (#4375)
* Display localized road name * Update changelog * Fix code docs for localizedRoadName
1 parent 2fc3a46 commit 45550b4

14 files changed

+139
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes to the Mapbox Navigation SDK for iOS
22

3+
## v2.12.0
4+
5+
### Visual instructions
6+
* `MapboxRoadNameView` now renders localized road names. ([#4375](https://github.com/mapbox/mapbox-navigation-ios/pull/4375))
7+
* Added `localizedRoadNameKey` to the user info dictionary of `Notification.Name.passiveLocationManagerDidUpdate` posted by `PassiveLocationManager`, and the `Notification.Name.currentRoadNameDidChange` posted by `RouteController`. The corresponding string value contains localized road name. ([#4375](https://github.com/mapbox/mapbox-navigation-ios/pull/4375))
8+
39
## v2.11.0
410

511
### Packaging

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
2C9DDBE42934D8FD007F8CFD /* MapboxCoreNavigationIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C58516229252FE20077A558 /* MapboxCoreNavigationIntegrationTests.swift */; };
122122
2CAEABD12930D25300DE851A /* MapboxNavigationServiceIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAEABD02930D25300DE851A /* MapboxNavigationServiceIntegrationTests.swift */; };
123123
2CAEABD32930D87B00DE851A /* RouterSpy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAEABD22930D87B00DE851A /* RouterSpy.swift */; };
124+
2CC3043529A3DCDE00A3318F /* NavigationStatusTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC3043429A3DCDE00A3318F /* NavigationStatusTests.swift */; };
124125
2CDF5C972919628100C41082 /* NavigationLocationManagerSpy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CDF5C962919628100C41082 /* NavigationLocationManagerSpy.swift */; };
125126
2CE25130291A56D900C0FA15 /* IdleTimerManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CE2512E291A56CE00C0FA15 /* IdleTimerManagerTests.swift */; };
126127
2CE89C2B299E6C2A000A2E34 /* InterchangeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CE89C2A299E6C2A000A2E34 /* InterchangeTests.swift */; };
@@ -788,6 +789,7 @@
788789
2C9DDBE12934C006007F8CFD /* MapboxCoreNavigationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapboxCoreNavigationTests.swift; sourceTree = "<group>"; };
789790
2CAEABD02930D25300DE851A /* MapboxNavigationServiceIntegrationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapboxNavigationServiceIntegrationTests.swift; sourceTree = "<group>"; };
790791
2CAEABD22930D87B00DE851A /* RouterSpy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouterSpy.swift; sourceTree = "<group>"; };
792+
2CC3043429A3DCDE00A3318F /* NavigationStatusTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationStatusTests.swift; sourceTree = "<group>"; };
791793
2CDF5C962919628100C41082 /* NavigationLocationManagerSpy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationLocationManagerSpy.swift; sourceTree = "<group>"; };
792794
2CE2512E291A56CE00C0FA15 /* IdleTimerManagerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdleTimerManagerTests.swift; sourceTree = "<group>"; };
793795
2CE89C2A299E6C2A000A2E34 /* InterchangeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterchangeTests.swift; sourceTree = "<group>"; };
@@ -2460,6 +2462,7 @@
24602462
E2B4B228272A814600FF0F57 /* ReplayLocationManagerTests.swift */,
24612463
2C2880A0291A82630063E5B7 /* RerouteControllerTests.swift */,
24622464
2C295AB8299B9E9600FC74E8 /* AccountsTests.swift */,
2465+
2CC3043429A3DCDE00A3318F /* NavigationStatusTests.swift */,
24632466
);
24642467
name = MapboxCoreNavigationTests;
24652468
path = Tests/MapboxCoreNavigationTests;
@@ -3539,6 +3542,7 @@
35393542
2C9DDBE32934C457007F8CFD /* RouteControllerTests.swift in Sources */,
35403543
359574AA1F28CCBB00838209 /* LocationTests.swift in Sources */,
35413544
E2814D982693412E000AD987 /* BillingHandlerTests.swift in Sources */,
3545+
2CC3043529A3DCDE00A3318F /* NavigationStatusTests.swift in Sources */,
35423546
C582BA2C2073E77E00647DAA /* StringTests.swift in Sources */,
35433547
352762A4225B751A0015B632 /* OptionsTests.swift in Sources */,
35443548
DA7A97CF26A7613D001B6A9A /* RouteOptionsTests.swift in Sources */,

Sources/MapboxCoreNavigation/CoreConstants.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public extension Notification.Name {
147147
/**
148148
Posted when `PassiveLocationManager` receives a user location update representing movement along the expected route.
149149

150-
The user info dictionary contains the keys `PassiveLocationManager.NotificationUserInfoKey.locationKey`, `PassiveLocationManager.NotificationUserInfoKey.rawLocationKey`, `PassiveLocationManager.NotificationUserInfoKey.matchesKey`, `PassiveLocationManager.NotificationUserInfoKey.roadNameKey`, `PassiveLocationManager.NotificationUserInfoKey.mapMatchingResultKey` and `PassiveLocationManager.NotificationUserInfoKey.routeShieldRepresentationKey`.
150+
The user info dictionary contains the keys `PassiveLocationManager.NotificationUserInfoKey.locationKey`, `PassiveLocationManager.NotificationUserInfoKey.rawLocationKey`, `PassiveLocationManager.NotificationUserInfoKey.matchesKey`, `PassiveLocationManager.NotificationUserInfoKey.roadNameKey`,
151+
`PassiveLocationManager.NotificationUserInfoKey.localizedRoadNameKey`,
152+
`PassiveLocationManager.NotificationUserInfoKey.mapMatchingResultKey` and `PassiveLocationManager.NotificationUserInfoKey.routeShieldRepresentationKey`.
151153

152154
- seealso: `routeControllerProgressDidUpdate`
153155
*/
@@ -253,7 +255,8 @@ public extension Notification.Name {
253255
/**
254256
Posted when `RouteController` detects the road name.
255257

256-
The user info dictionary contains the key `RouteController.NotificationUserInfoKey.roadNameKey` and `RouteController.NotificationUserInfoKey.routeShieldRepresentationKey`.
258+
The user info dictionary contains the key `RouteController.NotificationUserInfoKey.roadNameKey`,
259+
`RouteController.NotificationUserInfoKey.roadNameKey`, and `RouteController.NotificationUserInfoKey.routeShieldRepresentationKey`.
257260
*/
258261
static let currentRoadNameDidChange: Notification.Name = .init(rawValue: "CurrentRoadNameDidChange")
259262

@@ -327,11 +330,16 @@ extension RouteController {
327330
A key in the user info dictionary of a `Notification.Name.routeControllerProgressDidChange` notification. The corresponding value is a `MapMatchingResult` object representing the map matching state.
328331
*/
329332
public static let mapMatchingResultKey: NotificationUserInfoKey = .init(rawValue: "mapMatchingResult")
330-
333+
331334
/**
332335
A key in the user info dictionary of a `Notification.Name.currentRoadNameDidChange` notification. The corresponding value is a `NSString` object representing the current road name.
333336
*/
334337
public static let roadNameKey: NotificationUserInfoKey = .init(rawValue: "roadName")
338+
339+
/**
340+
A key in the user info dictionary of a `Notification.Name.currentRoadNameDidChange` notification. The corresponding value is a `NSString` object representing the localized current road name.
341+
*/
342+
public static let localizedRoadNameKey: NotificationUserInfoKey = .init(rawValue: "localizedRoadName")
335343

336344
/**
337345
A key in the user info dictionary of a `Notification.Name.currentRoadNameDidChange` notification. The corresponding value is a `MapboxDirections.VisualInstruction.Component.ImageRepresentation` object representing the road shield the user is currently traveling on.
@@ -429,10 +437,15 @@ extension PassiveLocationManager {
429437

430438
/**
431439
A key in the user info dictionary of a `Notification.Name.passiveLocationManagerDidUpdate` notification. The corresponding value is a string representing the name of the road the user is currently traveling on.
432-
433-
- seealso: `WayNameView`
434440
*/
435441
public static let roadNameKey: NotificationUserInfoKey = .init(rawValue: "roadName")
442+
443+
/**
444+
A key in the user info dictionary of a `Notification.Name.passiveLocationManagerDidUpdate` notification. The corresponding value is a string representing the full name of the road the user is currently traveling on. It might include road names in the local language and the device language.
445+
446+
- seealso: `WayNameView`
447+
*/
448+
public static let localizedRoadNameKey: NotificationUserInfoKey = .init(rawValue: "localizedRoadName")
436449

437450
/**
438451
A key in the user info dictionary of a `Notification.Name.passiveLocationManagerDidUpdate` notification. The corresponding value is a `MapboxDirections.VisualInstruction.Component.ImageRepresentation` object representing the road shield the user is currently traveling on.

Sources/MapboxCoreNavigation/NavigationStatus.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ import MapboxNavigationNative
33
import MapboxDirections
44

55
extension NavigationStatus {
6+
private static let nameDelimeter = "/"
7+
68
/// Legacy `roadName` property that returns first road name based on the `roads` array.
79
var roadName: String {
8-
roads.map({ $0.text }).prefix(while: { $0 != "/" }).joined(separator: " ")
10+
roads.map({ $0.text }).prefix(while: { $0 != NavigationStatus.nameDelimeter }).joined(separator: " ")
11+
}
12+
13+
/// Returns the localized road name.
14+
/// - Parameter locale: The locale that determines the chosen language.
15+
/// - Returns: The localized road name.
16+
func localizedRoadName(locale: Locale = .nationalizedCurrent) -> String {
17+
roads.first { $0.language == locale.languageCode }?.text ?? roadName
918
}
1019

1120
// This `routeShieldRepresentation` property returns the image representation of current road shield based on the `roads` array as the `VisualInstruction.Component.ImageRepresentation`.

Sources/MapboxCoreNavigation/PassiveLocationManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ open class PassiveLocationManager: NSObject {
240240
.rawLocationKey: rawLocation,
241241
.matchesKey: matches,
242242
.roadNameKey: status.roadName,
243+
.localizedRoadNameKey: status.localizedRoadName(),
243244
.routeShieldRepresentationKey: status.routeShieldRepresentation
244245
]
245246
if let speedLimit = speedLimit {

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ open class RouteController: NSObject {
467467
func updateRoadName(status: NavigationStatus) {
468468
let userInfo: [NotificationUserInfoKey: Any] = [
469469
NotificationUserInfoKey.roadNameKey: status.roadName,
470+
NotificationUserInfoKey.localizedRoadNameKey: status.localizedRoadName(),
470471
NotificationUserInfoKey.routeShieldRepresentationKey: status.routeShieldRepresentation
471472
]
472473
NotificationCenter.default.post(name: .currentRoadNameDidChange, object: self, userInfo: userInfo)

Sources/MapboxNavigation/CarPlayMapViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ open class CarPlayMapViewController: UIViewController {
316316
speedLimitView.signStandard = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.signStandardKey] as? SignStandard
317317
speedLimitView.speedLimit = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.speedLimitKey] as? Measurement<UnitSpeed>
318318

319-
let roadNameFromStatus = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.roadNameKey] as? String
319+
let roadNameFromStatus = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.localizedRoadNameKey] as? String
320320
if let roadName = roadNameFromStatus?.nonEmptyString {
321321
let representation = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.routeShieldRepresentationKey] as? VisualInstruction.Component.ImageRepresentation
322322
wayNameView.label.updateRoad(roadName: roadName, representation: representation, idiom: .carPlay)

Sources/MapboxNavigation/CarPlayNavigationViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
866866
}
867867

868868
@objc func didUpdateRoadNameFromStatus(_ notification: Notification) {
869-
let roadNameFromStatus = notification.userInfo?[RouteController.NotificationUserInfoKey.roadNameKey] as? String
869+
let roadNameFromStatus = notification.userInfo?[RouteController.NotificationUserInfoKey.localizedRoadNameKey] as? String
870870
if let roadName = roadNameFromStatus?.nonEmptyString {
871871
let representation = notification.userInfo?[RouteController.NotificationUserInfoKey.routeShieldRepresentationKey] as? VisualInstruction.Component.ImageRepresentation
872872
wayNameView.label.updateRoad(roadName: roadName, representation: representation, idiom: .carPlay)

Sources/MapboxNavigation/OrnamentsController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class OrnamentsController: NavigationComponent, NavigationComponentDelegate {
167167
var labelRoadNameCompletionHandler: (LabelRoadNameCompletionHandler)?
168168

169169
@objc func didUpdateRoadNameFromStatus(_ notification: Notification) {
170-
let roadNameFromStatus = notification.userInfo?[RouteController.NotificationUserInfoKey.roadNameKey] as? String
170+
let roadNameFromStatus = notification.userInfo?[RouteController.NotificationUserInfoKey.localizedRoadNameKey] as? String
171171
if let roadName = roadNameFromStatus?.nonEmptyString {
172172
let representation = notification.userInfo?[RouteController.NotificationUserInfoKey.routeShieldRepresentationKey] as? VisualInstruction.Component.ImageRepresentation
173173
navigationView.wayNameView.label.updateRoad(roadName: roadName, representation: representation)

Sources/MapboxNavigation/PreviewViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public class PreviewViewController: UIViewController {
211211
navigationView.speedLimitView.speedLimit = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.speedLimitKey] as? Measurement<UnitSpeed>
212212

213213
// Update current road name. In case if road name is not available `WayNameView` is hidden.
214-
let roadNameFromStatus = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.roadNameKey] as? String
214+
let roadNameFromStatus = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.localizedRoadNameKey] as? String
215215
if let roadName = roadNameFromStatus?.nonEmptyString {
216216
let representation = notification.userInfo?[PassiveLocationManager.NotificationUserInfoKey.routeShieldRepresentationKey] as? VisualInstruction.Component.ImageRepresentation
217217
navigationView.wayNameView.label.updateRoad(roadName: roadName, representation: representation)

0 commit comments

Comments
 (0)