UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: SwiftUI Localization of Strings inside an Array

Forums > SwiftUI

Hi everyone! I'm trying to localize my App and everything worked for now, expect the strings inside an array apparently get not localized. This is the array and the picker:

let days: [String] = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

ForEach (days,id: \.self) { day in
                            Text (day)
                                .font (.callout)
                                .fontWeight(.semibold)
                                .frame(maxWidth: .infinity)
                   }

I'm trying to locate it in Spanish and this is the part than doesn't work in the Localizable.strings (Spanish):

"Mon" =  "Lun";
"Tue" = "Mar";
"Wed" = "Mier";
"Thu" = "Jue";
"Fri" = "Vier";
"Sat" = "Sab";
"Sun" =  "Dom";

Any idea? Thanks!

2      

I use an extension on String

/**
     A NSLocalizedString for this String where a key has to be added to Localizable.strings file.
     */
    var localized: String {
        return NSLocalizedString(self, comment: "")
    }

    func localized(_ arguments: CVarArg...) -> String {
        return String(format: self.localized, arguments: arguments)
    }

you can use it with day.localized.

2      

Perfect, this has solved my problem. Thank you!

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.