-
Notifications
You must be signed in to change notification settings - Fork 0
feat(mora-i18n): PR 3 — narrow age picker + in-app language switch #128
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
Merged
youtalk
merged 6 commits into
main
from
feat/mora-i18n/03-age-narrow-and-language-switch
Apr 27, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3c1357e
core: add 4 MoraStrings fields for in-app language switch
youtalk 36b628e
ui: narrow age picker to 6/7/8 tiles
youtalk ef1aaea
ui: extract LanguagePicker for reuse in switch sheet
youtalk aac622c
ui: add LanguageSwitchSheet model + view
youtalk 8a8096a
ui: wire globe language-switch button into HomeView
youtalk 2213f41
Address PR review: tighten language-switch error handling and naming
youtalk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
Packages/MoraUI/Sources/MoraUI/LanguageAge/LanguagePicker.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // Packages/MoraUI/Sources/MoraUI/LanguageAge/LanguagePicker.swift | ||
| import MoraCore | ||
| import SwiftUI | ||
|
|
||
| /// Reusable language-selection row list. | ||
| /// | ||
| /// Renders the locale-neutral header and one tappable row per language. | ||
| /// Active vs. coming-soon status is driven by `LanguageAgeFlow` so the | ||
| /// activation list stays in one place. | ||
| public struct LanguagePicker: View { | ||
| @Binding public var selection: String | ||
|
|
||
| public init(selection: Binding<String>) { | ||
| _selection = selection | ||
| } | ||
|
|
||
| private struct Option: Identifiable { | ||
| let id: String | ||
| let label: String | ||
| let enabled: Bool | ||
| } | ||
|
|
||
| private static let allOptions: [(id: String, label: String)] = [ | ||
| (id: "ja", label: "にほんご"), | ||
| (id: "ko", label: "한국어"), | ||
| (id: "zh", label: "中文"), | ||
| (id: "en", label: "English"), | ||
| ] | ||
|
|
||
| private var options: [Option] { | ||
| let active = Set(LanguageAgeFlow.activeLanguageIdentifiers) | ||
| return Self.allOptions.map { entry in | ||
| Option(id: entry.id, label: entry.label, enabled: active.contains(entry.id)) | ||
| } | ||
| } | ||
|
|
||
| public var body: some View { | ||
| VStack(spacing: MoraTheme.Space.xl) { | ||
| Text("Language / 言語 / 语言 / 언어") | ||
| .font(MoraType.label()) | ||
| .foregroundStyle(MoraTheme.Ink.muted) | ||
| .padding(.top, MoraTheme.Space.xxl) | ||
|
|
||
| VStack(spacing: MoraTheme.Space.sm) { | ||
| ForEach(options) { option in | ||
| row(option) | ||
| } | ||
| } | ||
| .padding(.horizontal, MoraTheme.Space.xxl) | ||
| } | ||
| } | ||
|
|
||
| private func row(_ option: Option) -> some View { | ||
| let selected = option.id == selection | ||
| return Button { | ||
| guard option.enabled else { return } | ||
| selection = option.id | ||
| } label: { | ||
| HStack { | ||
| Text(option.label) | ||
| .font(MoraType.heading()) | ||
| .foregroundStyle( | ||
| option.enabled | ||
| ? MoraTheme.Ink.primary | ||
| : MoraTheme.Ink.muted | ||
| ) | ||
| if !option.enabled { | ||
| Spacer() | ||
| Text("Coming soon") | ||
| .font(MoraType.pill()) | ||
| .foregroundStyle(MoraTheme.Ink.muted) | ||
| } else if selected { | ||
| Spacer() | ||
| Image(systemName: "checkmark") | ||
| .foregroundStyle(MoraTheme.Accent.orange) | ||
| } else { | ||
| Spacer() | ||
| } | ||
| } | ||
| .padding(MoraTheme.Space.md) | ||
| .background( | ||
| selected | ||
| ? MoraTheme.Background.peach | ||
| : MoraTheme.Background.cream, | ||
| in: RoundedRectangle(cornerRadius: MoraTheme.Radius.tile) | ||
| ) | ||
| .overlay( | ||
| RoundedRectangle(cornerRadius: MoraTheme.Radius.tile) | ||
| .stroke( | ||
| selected ? MoraTheme.Accent.orange : .clear, | ||
| lineWidth: 3 | ||
| ) | ||
| ) | ||
| } | ||
| .buttonStyle(.plain) | ||
| .disabled(!option.enabled) | ||
| .accessibilityAddTraits(selected ? .isSelected : []) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
onCommitupdatesprofile.l1Identifierbut swallows persistence errors viatry? modelContext.save(). Ifsave()throws, the sheet still dismisses and the in-memory change may be lost on next launch. Handle the error (e.g., do/catch withassertionFailure/logging and revertprofile.l1Identifieror keep the sheet open) instead of ignoring it.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.
Good catch — fixed in 2213f41. Replaced
try? modelContext.save()with do/catch; on failure I revertprofile.l1Identifierto its previous value, log viaLogger(tech.reenable.Mora/HomeViewcategory), and leave the sheet open so the user sees the change didn't take. Sheet still dismisses on success.