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

Suppress freeway names in post-maneuver instructions #412

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions MapboxNavigation/Resources/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Continue on %1$@ for %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = distance */
"CONTINUE" = "Continue for %@";

/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Continue on %1$@ for %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/ca.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Continua per %1$@ cap a %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Continua per %1$@ cap a %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Continúe en %1$@ por %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Continúe en %1$@ por %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Continuez sur %1$@ pendant %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Continuez sur %1$@ pendant %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/hu.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Continue on %1$@ for %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Continue on %1$@ for %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/lt.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Tęskite %1$@ %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Tęskite %1$@ %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "iki %@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/sv.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Fortsätt på %1$@ i %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Fortsätt på %1$@ i %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/vi.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "Chạy tiếp trên %1$@ cho %2$@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "Chạy tiếp trên %1$@ cho %2$@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
4 changes: 2 additions & 2 deletions MapboxNavigation/Resources/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Format for speech string; 1 = way name; 2 = distance */
"CONTINUE" = "继续沿%@行驶%@";
/* Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance */
"CONTINUE_ON_ROAD" = "继续沿%@行驶%@";

/* Format string for less than; 1 = duration remaining */
"LESS_THAN" = "<%@";
Expand Down
3 changes: 1 addition & 2 deletions MapboxNavigation/RouteManeuverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ class RouteManeuverViewController: UIViewController {
}

func updateStreetNameForStep() {
let isMotorway = step?.intersections?.first?.outletRoadClasses?.contains(.motorway) ?? false
if isMotorway, let codes = step?.codes, let digitRange = codes.first?.rangeOfCharacter(from: .decimalDigits), !digitRange.isEmpty {
if let step = step, step.isNumberedMotorway, let codes = step.codes {
destinationLabel.unabridgedText = codes.joined(separator: NSLocalizedString("REF_DELIMITER", bundle: .mapboxNavigation, value: " / ", comment: "Delimiter between route numbers in a road concurrency"))
} else if let name = step?.names?.first {
destinationLabel.unabridgedText = name
Expand Down
44 changes: 44 additions & 0 deletions MapboxNavigation/RouteStepFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,47 @@ public class RouteStepFormatter: Formatter {
return false
}
}

extension RouteStep {
/**
Returns true if the route travels on a motorway primarily identified by a route number rather than a road name.
*/
var isNumberedMotorway: Bool {
guard intersections?.first?.outletRoadClasses?.contains(.motorway) == true else {
return false
}
guard let codes = codes, let digitRange = codes.first?.rangeOfCharacter(from: .decimalDigits) else {
return false
}
return !digitRange.isEmpty
}

/**
Returns a string describing the step’s road by its name, route number, or both, depending on the kind of road.

- parameter markedUpWithSSML: True to wrap the name and route number in SSML tags that cause them to be read as addresses.
- returns: A string describing the step’s road, or `nil` if the step lacks the information needed to describe the step.
*/
func roadDescription(markedUpWithSSML: Bool) -> String? {
let addressSSML = { (text: String?) -> String? in
guard let text = text else {
return nil
}
return markedUpWithSSML ? "<say-as interpret-as=\"address\">\(text.addingXMLEscapes)</say-as>" : text
}

let nameSSML = addressSSML(names?.first)
let codeSSML = addressSSML(codes?.first)

if let codeSSML = codeSSML, nameSSML == nil || isNumberedMotorway {
return codeSSML
} else if let nameSSML = nameSSML {
if let codeSSML = codeSSML {
return String.localizedStringWithFormat(NSLocalizedString("NAME_AND_REF", bundle: .mapboxNavigation, value: "%@ (%@)", comment: "Format for speech string; 1 = way name; 2 = way route number"), nameSSML, codeSSML)
} else {
return nameSSML
}
}
return nil
}
}
29 changes: 8 additions & 21 deletions MapboxNavigation/RouteVoiceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,17 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
if routeProgress.currentLegProgress.currentStep.maneuverType == .depart && alertLevel == .depart {
if userDistance < minimumDistanceForHighAlert {
text = String.localizedStringWithFormat(NSLocalizedString("LINKED_WITH_DISTANCE_UTTERANCE_FORMAT", bundle: .mapboxNavigation, value: "%@, then in %@, %@", comment: "Format for speech string; 1 = current instruction; 2 = formatted distance to the following linked instruction; 3 = that linked instruction"), currentInstruction!, escapeIfNecessary(maneuverVoiceDistanceFormatter.string(from: userDistance)), upComingInstruction)
} else if let roadDescription = step.roadDescription(markedUpWithSSML: markUpWithSSML) {
text = String.localizedStringWithFormat(NSLocalizedString("CONTINUE_ON_ROAD", bundle: .mapboxNavigation, value: "Continue on %@ for %@", comment: "Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance"), roadDescription, escapeIfNecessary(maneuverVoiceDistanceFormatter.string(from: userDistance)))
} else {
text = String.localizedStringWithFormat(NSLocalizedString("CONTINUE", bundle: .mapboxNavigation, value: "Continue on %@ for %@", comment: "Format for speech string; 1 = way name; 2 = distance"), localizeRoadDescription(step, markUpWithSSML: markUpWithSSML), escapeIfNecessary(maneuverVoiceDistanceFormatter.string(from: userDistance)))
text = String.localizedStringWithFormat(NSLocalizedString("CONTINUE", bundle: .mapboxNavigation, value: "Continue for %@", comment: "Format for speech string after completing a maneuver and starting a new step; 1 = distance"), escapeIfNecessary(maneuverVoiceDistanceFormatter.string(from: userDistance)))
}
} else if routeProgress.currentLegProgress.currentStep.distance > 2_000 && routeProgress.currentLegProgress.alertUserLevel == .low {
text = String.localizedStringWithFormat(NSLocalizedString("CONTINUE", bundle: .mapboxNavigation, value: "Continue on %@ for %@", comment: "Format for speech string; 1 = way name; 2 = distance"), localizeRoadDescription(step, markUpWithSSML: markUpWithSSML), escapeIfNecessary(maneuverVoiceDistanceFormatter.string(from: userDistance)))
if let roadDescription = step.roadDescription(markedUpWithSSML: markUpWithSSML) {
text = String.localizedStringWithFormat(NSLocalizedString("CONTINUE_ON_ROAD", bundle: .mapboxNavigation, value: "Continue on %@ for %@", comment: "Format for speech string after completing a maneuver and starting a new step; 1 = way name; 2 = distance"), roadDescription, escapeIfNecessary(maneuverVoiceDistanceFormatter.string(from: userDistance)))
} else {
text = String.localizedStringWithFormat(NSLocalizedString("CONTINUE", bundle: .mapboxNavigation, value: "Continue for %@", comment: "Format for speech string after completing a maneuver and starting a new step; 1 = distance"), escapeIfNecessary(maneuverVoiceDistanceFormatter.string(from: userDistance)))
}
} else if alertLevel == .high && stepDistance < minimumDistanceForHighAlert {
text = String.localizedStringWithFormat(NSLocalizedString("LINKED_UTTERANCE_FORMAT", bundle: .mapboxNavigation, value: "%@, then %@", comment: "Format for speech string; 1 = current instruction; 2 = the following linked instruction"), upComingInstruction, followOnInstruction)
} else if alertLevel != .high {
Expand All @@ -242,25 +248,6 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate, AVAudioP
return text
}

func localizeRoadDescription(_ step: RouteStep, markUpWithSSML: Bool) -> String {
var road = ""
let escapeIfNecessary = {(distance: String) -> String in
return markUpWithSSML ? distance.addingXMLEscapes : distance
}
if let name = step.names?.first {
if let code = step.codes?.first {
let markedUpName = markUpWithSSML ? "<say-as interpret-as=\"address\">\(name.addingXMLEscapes)</say-as>" : name
let markedUpCode = markUpWithSSML ? "<say-as interpret-as=\"address\">\(code.addingXMLEscapes)</say-as>" : code
road = String.localizedStringWithFormat(NSLocalizedString("NAME_AND_REF", bundle: .mapboxNavigation, value: "%@ (%@)", comment: "Format for speech string; 1 = way name; 2 = way route number"), markedUpName, markedUpCode)
} else {
road = escapeIfNecessary(name)
}
} else if let code = step.codes?.first {
road = escapeIfNecessary(code)
}
return road
}

func speak(_ text: String, error: String? = nil) {
// Note why it failed
if let error = error {
Expand Down