Created
September 23, 2017 16:00
-
-
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.
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
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