Skip to content

Instantly share code, notes, and snippets.

@Viveron
Created July 23, 2018 15:49
Show Gist options
  • Select an option

  • Save Viveron/8c77e490ecaf1c2fdc8a79dc1b7901e1 to your computer and use it in GitHub Desktop.

Select an option

Save Viveron/8c77e490ecaf1c2fdc8a79dc1b7901e1 to your computer and use it in GitHub Desktop.
Common type for aggregation all UI strings, that should be localized
import Foundation
typealias Localized = String
extension Localized {
func localize() -> String {
return NSLocalizedString(self, comment: "")
}
/// Localize plural string key
func localize<T>(_ count: T) -> String {
return String.localizedStringWithFormat(self.localize(), count as! CVarArg)
}
}
@Viveron

Viveron commented Jul 23, 2018

Copy link
Copy Markdown
Author

Example:

// Localized+Alert.swift
extension Localized {

    struct Alert {

        static var error: String = {
            return "general.alert.error".localize()
        }()
        // ...
    }
}

//...

let _ = Localized.Alert.error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment