commit d1bc04dd38093b6149c4e479e5ce5402ace47ac7
parent 7cecbb6b44e152db40370d756488843f6a518f72
Author: Michael Camilleri <[email protected]>
Date: Wed, 4 Nov 2026 07:56:02 +0900
Accept regional English spellings when casing activities inline
When a narrative joins activities, each activity's first word is
lowercased if it is an ordinary dictionary word. The check consulted
only the en_US dictionary so an activity such as 'Travelling on a train'
was not correctly lowercased.
This commit checks a word against every English dictionary that
UITextChecker provides, so 'travelling' and 'traveling' both count as
ordinary words. Place phrases use the same check and gain the same fix.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat
| M | Reportage/Services/Narrative/InlineCasing.swift | | | 15 | ++++++++++++--- |
| M | Tests/Unit/ReportSummaryTests.swift | | | 3 | +++ |
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/Reportage/Services/Narrative/InlineCasing.swift b/Reportage/Services/Narrative/InlineCasing.swift
@@ -36,10 +36,19 @@ enum InlineCasing {
return lower + text.dropFirst(first.count)
}
+ /// English dictionaries to check, so regional spellings such as
+ /// 'travelling' and 'traveling' both count as ordinary words.
+ private static let languages: [String] = {
+ let english = UITextChecker.availableLanguages.filter { $0.hasPrefix("en") }
+ return english.isEmpty ? ["en_US"] : english
+ }()
+
static func isDictionaryWord(_ word: String) -> Bool {
let range = NSRange(location: 0, length: (word as NSString).length)
- return checker.rangeOfMisspelledWord(
- in: word, range: range, startingAt: 0, wrap: false, language: "en_US"
- ).location == NSNotFound
+ return languages.contains { language in
+ checker.rangeOfMisspelledWord(
+ in: word, range: range, startingAt: 0, wrap: false, language: language
+ ).location == NSNotFound
+ }
}
}
diff --git a/Tests/Unit/ReportSummaryTests.swift b/Tests/Unit/ReportSummaryTests.swift
@@ -212,6 +212,9 @@ struct InlineCasingTests {
"Only ordinary first words are lowercased",
arguments: [
("Drinking coffee", "drinking coffee"),
+ ("Travelling on a train", "travelling on a train"),
+ ("Traveling on a train", "traveling on a train"),
+ ("Playing games", "playing games"),
("Watching Netflix", "watching Netflix"),
("Studying Japanese", "studying Japanese"),
("TV", "TV"),