passforios/passKit/Extensions/String+Localization.swift

27 lines
702 B
Swift
Raw Permalink Normal View History

2020-09-20 13:46:54 +02:00
//
// String+Localization.swift
// passKit
//
// Created by Danny Moesch on 12.01.19.
// Copyright © 2019 Bob Sun. All rights reserved.
//
2019-01-14 20:55:19 +01:00
2020-11-07 12:06:28 +01:00
public extension String {
func localize() -> String {
// swiftlint:disable:next nslocalizedstring_key
NSLocalizedString(self, bundle: Bundle.main, value: "#\(self)#", comment: "")
2019-01-14 20:55:19 +01:00
}
2020-11-07 12:06:28 +01:00
func localize(_ firstValue: CVarArg) -> String {
String(format: localize(), firstValue)
2019-01-14 20:55:19 +01:00
}
2020-11-07 12:06:28 +01:00
func localize(_ firstValue: CVarArg, _ secondValue: CVarArg) -> String {
String(format: localize(), firstValue, secondValue)
2019-01-14 20:55:19 +01:00
}
2020-11-07 12:06:28 +01:00
func localize(_ error: Error) -> String {
localize(error.localizedDescription)
2019-01-14 20:55:19 +01:00
}
}