Local+Extension 2.swift 791 Bytes
Newer Older
domenicw's avatar
domenicw committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
//  Local+Extension.swift
//  Amiv
//
//  Created by Domenic Wüthrich on 12.10.18.
//  Copyright © 2018 Amiv an der ETH. All rights reserved.
//

import Foundation

public extension Locale {
    
    public enum AppLanguage: String {
        case german = "de"
        case english = "en"
    }
    
    public static func current() -> AppLanguage {
        if let language = Locale.preferredLanguages.first, language == AppLanguage.german.rawValue {
            return .german
        } else {
            return .english
        }
    }
    
    public static func getLocalizedString(english: String, german: String) -> String {
        switch Locale.current() {
        case .english:
            return english
        case .german:
            return german
        }
    }
    
}