Skip to content

Commit 593ba17

Browse files
authored
Localization: wrap non-translatable SwiftUI Text literals + document the rule (prep for swiftui: true) (#25701)
* Localization: document the non-translatable SwiftUI text rule `xcstringstool` tags each extracted string with its compile gate (`visibility`); `sync` admits only unconditional strings into the catalog, so `#Preview` / `PreviewProvider` / `#if DEBUG` literals are excluded automatically — no `verbatim:` needed. Document this, and that `Text(verbatim:)` is for non-translatable literals in shipping code (glyphs, brands, pure interpolations). * Localization: wrap non-translatable SwiftUI Text literals (prep for swiftui: true) Once SwiftUI string extraction is enabled (`swiftui: true` on generate_strings_catalog), `xcstringstool extract --SwiftUI-Text` pulls every shipping `Text("literal")` into the String Catalog for translation — including non-translatable literals that would reach GlotPress as garbage. Wrap those in `Text(verbatim:)`, and fix a few numeric cases to format per the user's locale. No behavior change. - Glyphs/separators, brand names, pure string interpolations, HTTP status codes, and developer/debug-screen text -> `Text(verbatim:)`. - Bare numeric interpolations -> locale formatters: `Text(count, format: .number)`, `Text(Double(progress) / 100, format: .percent)`, and `.formatted()` inside a verbatim wrapper for decorated counts. A bare `Text("\(count)")` ships unlocalized digits (no grouping, no locale numerals). Left translatable on purpose: real UI strings, the `^[%@](inflect:)` string (LocalizedStringKey inflection), and `example.com` (site-address placeholder). Out of scope (separate changes): the unwired Realtime/Insights/Subscribers strings, the `Overriden`->`Overridden` codebase-wide misspelling, the two `"%@ characters"` strings (want proper plurals), and a `TODO:` placeholder in ActivityLogDetailView's share sheet.
1 parent 18dd66a commit 593ba17

39 files changed

Lines changed: 72 additions & 54 deletions

Modules/Sources/JetpackStats/Cards/ChartCard.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ struct ChartCardHeaderView: View {
348348
}
349349
}
350350
if viewModel.showComparison {
351-
Text("\(viewModel.trend.formattedChange) \(viewModel.trend.iconSign) \(viewModel.trend.formattedPercentage)")
351+
Text(verbatim: "\(viewModel.trend.formattedChange) \(viewModel.trend.iconSign) \(viewModel.trend.formattedPercentage)")
352352
.font(.caption.weight(.semibold))
353353
.foregroundColor(viewModel.trend.sentiment.foregroundColor)
354354
.contentTransition(.numericText())

Modules/Sources/JetpackStats/Charts/PieChartView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct PieChartView: View {
2222
.cornerRadius(5)
2323
.annotation(position: .overlay) {
2424
if shouldShowAnnotation(for: segment) {
25-
Text("\(segment.name.capitalized) \((segment.percentage / 100).formatted(.percent.precision(.fractionLength(1))))")
25+
Text(verbatim: "\(segment.name.capitalized) \((segment.percentage / 100).formatted(.percent.precision(.fractionLength(1))))")
2626
.font(.caption2)
2727
.fontWeight(.medium)
2828
.foregroundStyle(.white)

Modules/Sources/JetpackStats/Screens/PostStatsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ private struct PostLikesStripView: View {
578578

579579
// Show additional count if there are more users
580580
if likes.totalCount > maxVisibleAvatars {
581-
Text("+\((likes.totalCount - maxVisibleAvatars).formatted(.number.notation(.compactName)))")
581+
Text(verbatim: "+\((likes.totalCount - maxVisibleAvatars).formatted(.number.notation(.compactName)))")
582582
.font(.caption2.weight(.medium))
583583
.foregroundColor(.primary.opacity(0.8))
584584
.padding(.horizontal, 4)

Modules/Sources/JetpackStats/Views/StatsCardTitleView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct StatsCardTitleView: View {
2626
if showChevron {
2727
// Note: had to do that to fix the animation issuse with Menu
2828
// hiding the image.
29-
title + Text(" ") + Text(Image(systemName: "chevron.up.chevron.down"))
29+
title + Text(verbatim: " ") + Text(Image(systemName: "chevron.up.chevron.down"))
3030
.font(.caption2.weight(.semibold))
3131
.foregroundColor(.secondary)
3232
.baselineOffset(1)
@@ -59,7 +59,7 @@ struct InlineValuePickerTitle: View {
5959

6060
// Note: had to do that to fix the animation issuse with Menu
6161
// hiding the image.
62-
title + Text(" ") + Text(Image(systemName: "chevron.up.chevron.down"))
62+
title + Text(verbatim: " ") + Text(Image(systemName: "chevron.up.chevron.down"))
6363
.font(.caption2.weight(.semibold))
6464
.foregroundColor(.secondary)
6565
.baselineOffset(1)

Modules/Sources/JetpackStats/Views/TimezoneInfoView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct TimezoneInfoView: View {
3838
.font(.headline)
3939
.foregroundStyle(.primary)
4040

41-
Text("\(formattedTimeZone) (\(context.formatters.date.formattedTimeOffset))")
41+
Text(verbatim: "\(formattedTimeZone) (\(context.formatters.date.formattedTimeOffset))")
4242
.font(.footnote)
4343
.foregroundColor(.secondary)
4444

Modules/Sources/JetpackStats/Views/TopList/Rows/TopListVideoRowView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct TopListVideoRowView: View {
55

66
var body: some View {
77
VStack(alignment: .leading, spacing: 2) {
8-
(Text(Image(systemName: "play.circle")).font(.footnote) + Text(" ") + Text(item.title))
8+
(Text(Image(systemName: "play.circle")).font(.footnote) + Text(verbatim: " ") + Text(item.title))
99
.font(.callout)
1010
.foregroundColor(.primary)
1111
.lineLimit(1)

Modules/Sources/JetpackStats/Views/TopList/TopListItemView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct TopListItemView: View {
5151
var content: some View {
5252
HStack(alignment: .center, spacing: 0) {
5353
if let index {
54-
Text("\(index + 1)")
54+
Text(index + 1, format: .number)
5555
.font(.system(.subheadline, design: .rounded, weight: .medium))
5656
.frame(width: 22, alignment: .center)
5757
.lineLimit(1)

Modules/Sources/JetpackStats/Views/TopList/TopListMetricsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct TopListMetricsView: View {
2020
}
2121
if let trend {
2222
HStack(spacing: 3) {
23-
Text("\(trend.iconSign) \(trend.formattedPercentage)")
23+
Text(verbatim: "\(trend.iconSign) \(trend.formattedPercentage)")
2424
.font(.system(.caption2, design: .rounded, weight: .semibold)).tracking(-0.25)
2525
.foregroundColor(trend.sentiment.foregroundColor)
2626
.contentTransition(.numericText())

Modules/Sources/Support/UI/Bot Conversations/ConversationBotIntro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct ConversationBotIntro: View {
1717
.font(.title2)
1818
.fontWeight(.semibold)
1919

20-
Text("👋")
20+
Text(verbatim: "👋")
2121
.font(.title2)
2222
}
2323

Modules/Sources/Support/UI/Bot Conversations/ConversationView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public struct ConversationView: View {
284284

285285
switchToHumanSupport
286286

287-
Text("").padding(.bottom, 4)
287+
Text(verbatim: "").padding(.bottom, 4)
288288
.listRowInsets(.zero)
289289
.listRowBackground(Color.clear)
290290
.listRowSpacing(0)

0 commit comments

Comments
 (0)