Skip to content

Instantly share code, notes, and snippets.

@meyusufdemirci
Last active April 28, 2022 10:52
Show Gist options
  • Save meyusufdemirci/96aff9ae381ba2af0cf4853a48d1d348 to your computer and use it in GitHub Desktop.
Save meyusufdemirci/96aff9ae381ba2af0cf4853a48d1d348 to your computer and use it in GitHub Desktop.
Realtime Localization Article
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