Skip to content

Can I use .locStringKey referencing .strings files in a Swift package? #1

Answered by Jeehut
Jeehut asked this question in Help / FAQ
Discussion options

You must be logged in to vote

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 SwiftUI Text view taking a bundle parameter where developers need to pass Bundle.module or more generally the bundle of the package where the .strings files lie:

Text("MainScreen.Greeting", bundle: .module) // => "Hello, World!" in 🇺🇸English and "ハロー、ワールド" in 🇯🇵Japanese

Unfortunately, as far as I could find, Text seems to be the only view taking a bundle parameter. But most others views in SwiftUI have a label-based initializer, such as Button or TextField where you could always create a T…

Replies: 1 comment

Comment options

Jeehut
Jul 4, 2022
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by Jeehut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant