Skip to content

Instantly share code, notes, and snippets.

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