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

Add spoken locale #235

Merged
merged 4 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions MapboxDirections/MBDirections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ open class Directions: NSObject {
route.accessToken = self.accessToken
route.apiEndpoint = self.apiEndpoint
route.routeIdentifier = json["uuid"] as? String
if let vLocale = json["voiceLocale"] as? String {
route.spokenLocale = Locale(identifier: vLocale)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about also copying this locale into each SpokenInstruction, so that the navigation SDK’s voice controller classes only need to work with individual SpokenInstruction objects?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that works

}
}
}
completionHandler(response.0, response.1, nil)
Expand Down
8 changes: 8 additions & 0 deletions MapboxDirections/MBRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ open class Route: NSObject, NSSecureCoding {
routeOptions = options

routeIdentifier = decoder.decodeObject(of: NSString.self, forKey: "routeIdentifier") as String?

spokenLocale = decoder.decodeObject(of: NSLocale.self, forKey: "spokenLocale") as Locale?
}

open static var supportsSecureCoding = true
Expand All @@ -86,6 +88,7 @@ open class Route: NSObject, NSSecureCoding {
coder.encode(expectedTravelTime, forKey: "expectedTravelTime")
coder.encode(routeOptions, forKey: "routeOptions")
coder.encode(routeIdentifier, forKey: "routeIdentifier")
coder.encode(spokenLocale, forKey: "spokenLocale")
}

// MARK: Getting the Route Geometry
Expand Down Expand Up @@ -194,6 +197,11 @@ open class Route: NSObject, NSSecureCoding {
Each route produced by a single call to `Directions.calculate(_:completionHandler:)` has the same route identifier.
*/
@objc open var routeIdentifier: String?

/**
The locale to use for spoken instructions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain that this locale is specifically meant for use with the Mapbox Voice API. Add a note about what nil means.

*/
@objc open var spokenLocale: Locale?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this property to speechLocale or voiceLocale to better emphasize that this locale gets plugged into MapboxSpeech or the Voice API.

}

// MARK: Support for Directions API v4
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions MapboxDirectionsTests/V5Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class V5Tests: XCTestCase {
XCTAssertEqual(route!.accessToken, BogusToken)
XCTAssertEqual(route!.apiEndpoint, URL(string: "https://api.mapbox.com"))
XCTAssertEqual(route!.routeIdentifier, "cj725hpi30yp2ztm2ehbcipmh")
XCTAssertEqual(route!.spokenLocale!.description, "en-US")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description is a free-form, human-readable string that may contain extra details beyond the identifier. Use identifier instead.



// confirming actual decoded values is important because the Directions API
Expand Down