Firebonk_iOS/Firebonk/i18n/Localizer.swift

31 lines
840 B
Swift
Raw Permalink Normal View History

2023-01-12 22:07:37 +00:00
//
// Localizer.swift
// Firebonk
//
// Created by Patrick Müller on 12.01.23.
//
import Foundation
private class Localizer {
static let sharedInstance = Localizer()
func localize(string: String, tableName: String, plural: Bool) -> String {
var localizedString: String
if plural{
localizedString = NSLocalizedString(string, tableName: tableName, value:"**\(self)**", comment: "plural")
}else{
localizedString = NSLocalizedString(string, tableName: tableName, value:"**\(self)**", comment: "")
}
return localizedString
}
}
extension String {
func localized(tableName: String = "Localizable", plural: Bool = false) -> String {
return Localizer.sharedInstance.localize(string: self, tableName: tableName, plural: plural)
}
}