-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #781 from kiwicom/764-add-localizationbundle-envir…
…onment-for-localization-support Add localization support to Text component
- Loading branch information
Showing
9 changed files
with
292 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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
29 changes: 29 additions & 0 deletions
29
Sources/Orbit/Support/Environment Keys/LocalizationBundle.swift
This file contains 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,29 @@ | ||
import SwiftUI | ||
|
||
struct LocalizationBundleKey: EnvironmentKey { | ||
static let defaultValue: Bundle = .main | ||
} | ||
|
||
public extension EnvironmentValues { | ||
|
||
/// A bundle used for Orbit localization using `LocalizedStringKey` stored in a view’s environment. | ||
/// The `Bundle.main` is used by default. | ||
var localizationBundle: Bundle { | ||
get { self[LocalizationBundleKey.self] } | ||
set { self[LocalizationBundleKey.self] = newValue } | ||
} | ||
} | ||
|
||
public extension View { | ||
|
||
/// Set the default bundle used for Orbit localization of `LocalizedStringKey` based texts in this view. | ||
/// | ||
/// Only applies to texts where the bundle is not explicitly specified. | ||
/// | ||
/// - Parameters: | ||
/// - bundle: A bundle that will be used to localize Orbit texts within the view hierarchy. | ||
/// - Important: Does not affect texts specified using `LocalizedStringResource` where the bundle is embedded. | ||
func localizationBundle(_ bundle: Bundle) -> some View { | ||
environment(\.localizationBundle, bundle) | ||
} | ||
} |
Oops, something went wrong.