-
Notifications
You must be signed in to change notification settings - Fork 88
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 language/locale #176
Add language/locale #176
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,11 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
self.attributeOptions = attributeOptions | ||
|
||
includesExitRoundaboutManeuver = decoder.decodeBool(forKey: "includesExitRoundaboutManeuver") | ||
|
||
guard let locale = decoder.decodeObject(of: NSLocale.self, forKey: "locale") as Locale? else { | ||
return nil | ||
} | ||
self.locale = locale | ||
} | ||
|
||
open static var supportsSecureCoding = true | ||
|
@@ -195,6 +200,7 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
coder.encode(routeShapeResolution.description, forKey: "routeShapeResolution") | ||
coder.encode(attributeOptions.description, forKey: "attributeOptions") | ||
coder.encode(includesExitRoundaboutManeuver, forKey: "includesExitRoundaboutManeuver") | ||
coder.encode(locale, forKey: "locale") | ||
} | ||
|
||
// MARK: Specifying the Path of the Route | ||
|
@@ -303,6 +309,15 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
*/ | ||
open var includesExitRoundaboutManeuver = false | ||
|
||
/** | ||
If set, this `Locale` will be used to translate instructions. | ||
|
||
See supported languages [here](https://www.mapbox.com/api-documentation/#instructions-languages). | ||
*/ | ||
open var locale: Locale? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’d be nice to default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this optional for now. |
||
|
||
private let supportedLocales: [String] = ["de", "en", "es", "fr", "id", "nl", "ru", "sv", "vi", "zh"] | ||
|
||
/** | ||
An array of URL parameters to include in the request URL. | ||
*/ | ||
|
@@ -319,6 +334,13 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
params.append(URLQueryItem(name: "roundabout_exits", value: String(includesExitRoundaboutManeuver))) | ||
} | ||
|
||
if let locale = locale, var languageCode = (locale as NSLocale?)?.object(forKey: .languageCode) as? String, supportedLocales.contains(languageCode) { | ||
if languageCode == "zh" { | ||
languageCode = "zh-Hans" | ||
} | ||
params.append(URLQueryItem(name: "language", value: languageCode)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we implement fallback logic on the server side, we’ll want to pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
} | ||
|
||
// Include headings and heading accuracies if any waypoint has a nonnegative heading. | ||
if !waypoints.filter({ $0.heading >= 0 }).isEmpty { | ||
let headings = waypoints.map { $0.headingDescription }.joined(separator: ";") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.