I'm trying to localize my App in English and German and everything worked for now, expect the strings inside an array apparently get not localized.
I have this array, which holds the options for my Picker:
let sorting = ["Newest First", "Oldest First"]
This is my Picker, which works correctly function wise:
Picker("Sort by", selection: $sortingSelection) {
ForEach(sorting, id: \.self) {
Text($0)
.foregroundColor(.accentColor)
.font(.footnote)
}
}
.pickerStyle(MenuPickerStyle())
And this is the correleting Localizable.strings (German):
"Newest First" = "Neueres Zuerst";
"Oldest First" = "Älteres Zuerst";
So I tried just writing it as strings, which is the easiest way to use localization now.
I also tried using the it as a variable, but this doesn't work:
let localizedString1 = "Newest First"
let localizedString2 = "Oldest First"
let sorting = [localizedString1, localizedString2]
I also saw this post:
Swift: Localize an Array of strings
but like the comment on the answer says, is there a way to get some example code? Or is there a better method now?