Post

Replies

Boosts

Views

Activity

Reply to Use String Catalog and Localization with class and struct
I found out how. I was able to do it creating a dictionary of the words I need it and making them localized Here is how: import Foundation class LensStructFilter: Identifiable { var description: String init(description: String) { self.description = description } var localizedDescription: String { var result = description let terms: [String: LocalizedStringResource] = [ "Focal": "Focal", "Abertura Máxima": "Abertura Máxima", "Bocal": "Bocal", "Cobertura": "Cobertura", "Diâmetro Frontal": "Diâmetro Frontal", "Peso": "Peso", "Foco Mínimo": "Foco Mínimo" ] for (originalTerm, resource) in terms { let localizedTerm = String(localized: resource) result = result.replacingOccurrences(of: originalTerm, with: localizedTerm) } return result } } Then on the ContentView where you want to use the description just change description to localizedDescription. If there is another way please let me know. Thanks
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’25
Reply to Use String Catalog and Localization with class and struct
Thanks so much for the help. It kind of worked but the string catalog brought all the description as localizable. I just want these strings to be localizable Focal, Abertura Maxima, Bocal, Cobertura, Diametro frontal, Peso, Foco Minimo Is there a way to do that? For now the only thing I added was: class LensStructFilter: Identifiable { var description: LocalizedStringResource init(description: LocalizedStringResource) { self.description = description } } See screen attached. :
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’25