Can I use .locStringKey
referencing .strings
files in a Swift package?
#1
-
In my first stream where I tested the first beta of RemafoX I came across an issue (exactly here) where I noticed that What can I do? Is this a SwiftUI limitation or is it a bug in RemafoX? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
After reading this blog post from @MarcoEidinger, I learned that Apple does already provide a solution for Text("MainScreen.Greeting", bundle: .module) // => "Hello, World!" in 🇺🇸English and "ハロー、ワールド" in 🇯🇵Japanese Unfortunately, as far as I could find, Button {
print("Cancel requested")
} label: {
Text("Global.Action.Cancel", bundle: .module)
} You might want to add a extension Text {
public init(locStringKey: LocalizedStringKey) {
self.init(locStringKey, bundle: .module)
}
} If that's too inconvenient, you can always revert back to using |
Beta Was this translation helpful? Give feedback.
After reading this blog post from @MarcoEidinger, I learned that Apple does already provide a solution for
LocalizedStringKey
when the.strings
files lie in a Swift package: There's an initializer for the SwiftUIText
view taking abundle
parameter where developers need to passBundle.module
or more generally the bundle of the package where the.strings
files lie:Unfortunately, as far as I could find,
Text
seems to be the only view taking abundle
parameter. But most others views in SwiftUI have alabel
-based initializer, such as Button or TextField where you could always create aT…