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
titleLabel.text = "App demo".localized(key: "navigationbar.title") |
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) { |
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 | |
enum LanguageCode: String { | |
case en | |
case zh | |
case ja | |
} | |
class InAppLocalizationManager { | |
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
titleLabel.text = NSLocalizedString("navigationbar.title", comment: "The navigation bar's title") |