Skip to content

Instantly share code, notes, and snippets.

@danielbas
danielbas / TypicalLocalization.swift
Created September 23, 2017 15:41
Typical way to localize a string
titleLabel.text = NSLocalizedString("navigationbar.title", comment: "The navigation bar's title")
@danielbas
danielbas / String+InAppLocalization.swift
Created September 23, 2017 16:00
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) {
@danielbas
danielbas / LocalizedStringExample.swift
Created September 23, 2017 16:19
The example usage of localized string using in app localization manager
titleLabel.text = "App demo".localized(key: "navigationbar.title")
@danielbas
danielbas / InAppLocalizationManager.swift
Last active September 24, 2017 03:49
In app localization manager
import Foundation
enum LanguageCode: String {
case en
case zh
case ja
}
class InAppLocalizationManager {