Last active
April 28, 2022 10:52
-
-
Save meyusufdemirci/96aff9ae381ba2af0cf4853a48d1d348 to your computer and use it in GitHub Desktop.
Realtime Localization Article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocalizationManager: ObservableObject { | |
@Published var language: Language = .english | |
func localize(_ key: String) -> String { | |
guard | |
let bundlePath = Bundle.main.path(forResource: language.rawValue, | |
ofType: "lproj"), | |
let bundle = Bundle(path: bundlePath) | |
else { | |
return key | |
} | |
return NSLocalizedString(key, tableName: nil, bundle: bundle, comment: "") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment