Translating text within your app
At a glance
| Item | Summary |
|---|---|
| Purpose | Display simple system translations and create custom translation experiences. |
| App architecture | A Swift sample with the source-visible chain TranslatingTextApp → ContentView → ViewModel → Translation APIs. |
| Main patterns | Model-View-ViewModel, Actor-isolated state |
| Project style | 12 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── TranslatingText/
├── TranslatingTextApp.swift
├── ViewModel/
│ ├── ViewModel.swift
│ └── AvailableLanguage.swift
├── Views/
│ ├── Availability/
│ │ ├── LanguageAvailability/
│ │ │ └── LanguageAvailabilityView.swift
│ │ └── PrepareTranslation/
│ │ └── PrepareTranslationView.swift
│ ├── CustomUI/
│ │ ├── Batch/
│ │ │ └── BatchOfStringsView.swift
│ │ ├── BatchAsSequence/
│ │ │ └── BatchAsSequenceView.swift
│ │ └── SingleString/
│ │ └── SingleStringView.swift
│ ├── RowView.swift
│ └── SystemUI/
│ ├── ReplaceTranslationView.swift
│ └── ViewTranslationView.swift
└── ContentView.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 4 project/configuration file(s) and 13 source declaration(s).
Overall architecture
flowchart LR
N1["TranslatingTextApp"]
N2["ContentView"]
N3["ViewModel"]
N4["Translation APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
TranslatingText/TranslatingTextApp.swift:10 — architecture anchor
@main
struct TranslatingTextApp: App {
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Translation.
Ownership and state
classDiagram
TranslatingTextApp *-- ViewModel : model
ViewModel *-- Bool : isTranslationSupported
ViewModel *-- Array : availableLanguages
LanguageAvailabilityView *-- Language : selectedFrom
Ownership evidence
TranslatingText/TranslatingTextApp.swift:12 — stored dependency or nearest verified ownership anchor
@State private var model = ViewModel()| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
TranslatingTextApp |
ViewModel (model) |
owns wrapper-managed state | Owning lexical scope |
ViewModel |
Bool (isTranslationSupported) |
owns value state | App/module collaborators |
ViewModel |
Array (availableLanguages) |
owns value state | App/module collaborators |
LanguageAvailabilityView |
Language (selectedFrom) |
owns wrapper-managed state | Owning lexical scope |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
TranslatingText/TranslatingTextApp.swift:11 — representative type boundary
struct TranslatingTextApp: App {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
TranslatingTextApp |
Application entry and top-level composition | App |
ViewModel |
UI-facing state and feature coordination | Concrete collaborators/imported frameworks |
LanguageAvailabilityView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
PrepareTranslationView |
User-interface presentation and input forwarding | View |
BatchOfStringsView |
User-interface presentation and input forwarding | View |
BatchAsSequenceView |
User-interface presentation and input forwarding | View |
SingleStringView |
User-interface presentation and input forwarding | View |
RowView |
User-interface presentation and input forwarding | View |
ReplaceTranslationView |
User-interface presentation and input forwarding | View |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
model (TranslatingText/TranslatingTextApp.swift:12) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
shortName (TranslatingText/ViewModel/AvailableLanguage.swift:25) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
selectedFrom (TranslatingText/Views/Availability/LanguageAvailability/LanguageAvailabilityView.swift:15) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
selectedTo (TranslatingText/Views/Availability/LanguageAvailability/LanguageAvailabilityView.swift:16) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
TranslatingText/TranslatingTextApp.swift:12 — representative boundary
@State private var model = ViewModel()Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | TranslatingTextApp |
The source’s App suffix makes this role explicit. |
| User-interface presentation and input forwarding | BatchAsSequenceView, BatchOfStringsView, ContentView, LanguageAvailabilityView |
The source’s View suffix makes this role explicit. |
| UI-facing state and feature coordination | ViewModel |
The source’s ViewModel suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | TranslatingText/ViewModel/ViewModel.swift:12 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| Actor-isolated state | TranslatingText/ViewModel/ViewModel.swift:31 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: TranslatingTextApp; View: BatchAsSequenceView, BatchOfStringsView, ContentView, LanguageAvailabilityView, PrepareTranslationView; ViewModel: ViewModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
reset,prepareSupportedLanguages,translate,translateAllAtOnce,translateSequence,checkLanguageSupport,performCheck,triggerTranslation. - Files:
TranslatingText/TranslatingTextApp.swift,TranslatingText/ViewModel/ViewModel.swift,TranslatingText/Views/Availability/LanguageAvailability/LanguageAvailabilityView.swift,TranslatingText/ContentView.swift,TranslatingText/Views/Availability/PrepareTranslation/PrepareTranslationView.swift,TranslatingText/Views/CustomUI/Batch/BatchOfStringsView.swift.
Architecture takeaways
TranslatingTextAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, Translation through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
TranslatingText/TranslatingTextApp.swift |
TranslatingTextApp |
TranslatingText/ViewModel/ViewModel.swift |
ViewModel |
TranslatingText/Views/Availability/LanguageAvailability/LanguageAvailabilityView.swift |
LanguageAvailabilityView, LanguagePair |
TranslatingText/ContentView.swift |
ContentView |
TranslatingText/Views/Availability/PrepareTranslation/PrepareTranslationView.swift |
PrepareTranslationView |
TranslatingText/Views/CustomUI/Batch/BatchOfStringsView.swift |
BatchOfStringsView |
TranslatingText/Views/CustomUI/BatchAsSequence/BatchAsSequenceView.swift |
BatchAsSequenceView |
TranslatingText/Views/CustomUI/SingleString/SingleStringView.swift |
SingleStringView |
TranslatingText/Views/RowView.swift |
RowView |
TranslatingText/Views/SystemUI/ReplaceTranslationView.swift |
ReplaceTranslationView |