You can do it simply by using: String(localized: “YOUR_LOCALIZED_KEY”)
If your localized key is programmatically generated, you must store it in a variable that conforms to “LocalizationValue” like this:
let localizedKey = String.LocalizationValue(stringLiteral: yourLocalizedVar)
Then you can use String(localized: localizedKey) to get your localized text content.
Mahdi BM’s solution has a problem because Swift returns only the language code even if you use variants of a language like Spanish, Portuguese, and so many others. The language code for both examples will always return ES and PT, but the names of folders with the localized keys will be different: PT can be ‘pt-PT’ or ‘pt-BR’, Spanish can be ‘es’ or ‘es-419’ (Latin America) and these cases will cause your app to crash. Locale is also a terrible idea to get this reference because it’s composed by both current language and region, both can be from different places, example, if the user is from Japan but is in the US, the user’s locale will very likely be jp_US@japaneseCalendar.
SwiftUI by Example <-- Start leaning SwiftUI from this site
Animations in SwiftUI – Bring Your iOS App to Life with Ease!
Alamofire vs. URLSession: Elevating Network Operations in Swift Development
How do I use Alamofire to download images or files from a website?
How to load a remote image from a URL
Localize Your Apps to Support Multiple Languages — iOS Localization in SwiftUI
or
You can do it simply by using: String(localized: “YOUR_LOCALIZED_KEY”)
If your localized key is programmatically generated, you must store it in a variable that conforms to “LocalizationValue” like this:
let localizedKey = String.LocalizationValue(stringLiteral: yourLocalizedVar)
Then you can use String(localized: localizedKey) to get your localized text content.
Mahdi BM’s solution has a problem because Swift returns only the language code even if you use variants of a language like Spanish, Portuguese, and so many others. The language code for both examples will always return ES and PT, but the names of folders with the localized keys will be different: PT can be ‘pt-PT’ or ‘pt-BR’, Spanish can be ‘es’ or ‘es-419’ (Latin America) and these cases will cause your app to crash. Locale is also a terrible idea to get this reference because it’s composed by both current language and region, both can be from different places, example, if the user is from Japan but is in the US, the user’s locale will very likely be jp_US@japaneseCalendar.
Checking the Language of a Device in Swift
How to submit an iOS app to the App Store: Step-by-step guide
Image Caching in SwiftUI
Getting Started with Xcode Cloud
Swift Networking Essentials: Using URLSession and URLRequest in iOS Apps
REST API Calls in Swift: iOS Networking Architecture [in SwiftUI]
Reduce your iOS apps network traffic with ETags using URLSession or Moya
https://designcode.io/swiftui-handbook-visual-editor-in-xcode
https://www.hackingwithswift.com/quick-start/swiftui/how-to-enable-pull-to-refresh
https://www.hackingwithswift.com/forums/swift/hacking-arend-with-json-invalid-key-containing-a-space-no-snakes-or-camels/23905
https://www.kodeco.com/books/swift-cookbook/v1.0/chapters/3-handle-custom-keys-missing-values-while-decoding-in-swift
https://www.hackingwithswift.com/guide/ios-swiftui/5/2/key-points
https://www.swiftyplace.com/blog/chy7hvne#:~:text=The%20table%20allows%20the%20selection,available%20to%20customize%20its%20behavior.
https://www.tutorialspoint.com/swift/index.htm
https://www.youtube.com/watch?v=YIPXgtsXhPc&list=PL9TY7jc64Gd4OU7LqA7N_r3O4c79QbR8w&index=4
A Step-by-Step Guide to the Delegate Pattern in Swift