Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danielbas
Created September 23, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbas/1c56fc5f2870efa6155c4c6b6aafba09 to your computer and use it in GitHub Desktop.
Save danielbas/1c56fc5f2870efa6155c4c6b6aafba09 to your computer and use it in GitHub Desktop.
The String extension that uses a key to get the localized string of itself.
import Foundation
extension String {
/// Get the localized string using the key.
///
/// - Parameter key: The localization key.
/// - Returns: The localized string if there exists the value of the key. Otherwise, return the string itself.
func localized(key: String) -> String {
if let localizedString = InAppLocalizationManager.shared.localizedString(key) {
return localizedString
}
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment