-
Notifications
You must be signed in to change notification settings - Fork 87
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 1 commit
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 |
---|---|---|
|
@@ -182,7 +182,10 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
|
||
includesExitRoundaboutManeuver = decoder.decodeBool(forKey: "includesExitRoundaboutManeuver") | ||
|
||
locale = Locale(identifier: decoder.decodeObject(of: NSString.self, forKey: "locale") as String? ?? "") | ||
guard let locale = decoder.decodeObject(of: NSLocale.self, forKey: "locale") as Locale? else { | ||
return nil | ||
} | ||
self.locale = locale | ||
} | ||
|
||
open static var supportsSecureCoding = true | ||
|
@@ -197,9 +200,7 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
coder.encode(routeShapeResolution.description, forKey: "routeShapeResolution") | ||
coder.encode(attributeOptions.description, forKey: "attributeOptions") | ||
coder.encode(includesExitRoundaboutManeuver, forKey: "includesExitRoundaboutManeuver") | ||
if let locale = locale, let languageCode = (locale as NSLocale?)?.object(forKey: .languageCode) as? String { | ||
coder.encode(languageCode, forKey: "locale") | ||
} | ||
coder.encode(locale, forKey: "locale") | ||
} | ||
|
||
// MARK: Specifying the Path of the Route | ||
|
@@ -315,6 +316,8 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
*/ | ||
open var locale: Locale? | ||
|
||
private let supportedLocales: [String] = ["de", "en", "es", "fr", "id", "nl", "ru", "sv", "vi", "zh-hans"] | ||
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. If the locale is Simplified Chinese, its locale identifier will be |
||
|
||
/** | ||
An array of URL parameters to include in the request URL. | ||
*/ | ||
|
@@ -332,7 +335,11 @@ open class RouteOptions: NSObject, NSSecureCoding { | |
} | ||
|
||
if let locale = locale, let languageCode = (locale as NSLocale?)?.object(forKey: .languageCode) as? String { | ||
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. The language code is only the two-letter ISO 369 code. It doesn’t ever include a region or script code; for that, you need the full locale identifier. Unfortunately, the Directions API currently lacks any sort of fallback mechanism. So this code will fail for Simplified Chinese ( Until the Directions API gains basic language fallback capability, we’ll need to hard-code a whitelist of locales that the Directions API supports. |
||
params.append(URLQueryItem(name: "language", value: languageCode)) | ||
if supportedLocales.contains(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. This will fail for a Locale with the identifier |
||
params.append(URLQueryItem(name: "language", value: languageCode)) | ||
} else { | ||
params.append(URLQueryItem(name: "language", value: "en")) | ||
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. Is it necessary to append any |
||
} | ||
} | ||
|
||
// Include headings and heading accuracies if any waypoint has a nonnegative heading. | ||
|
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.
It’d be nice to default to
Locale.autoupdatingCurrent
orBundle.main.preferredLocalizations.first
so the behavior is always what the user would expect, but that can happen as tail work, possibly at the same time that we set a default locale in MapboxGeocoder.swift.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.
Let's keep this optional for now.