OSDN Git Service

Localizableを導入
[kcd/KCD.git] / KCD / Localizable.swift
1 //
2 //  Localizable.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/10/01.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Foundation
10
11 protocol Localizable {
12     
13     var key: String { get }
14     var table: String? { get }
15     var comment: String { get }
16     
17     var string: String { get }
18 }
19
20 extension Localizable {
21     
22     var string: String {
23         
24         return NSLocalizedString(key, tableName: table, bundle: .main, comment: comment)
25     }
26 }
27
28 struct LocalizedString: Localizable {
29     
30     let key: String
31     let table: String? = nil
32     let comment: String
33     
34     
35     init(_ string: String, comment: String) {
36         self.key = string
37         self.comment = comment
38     }
39 }
40
41 struct LocalizedStringFromTable: Localizable {
42     
43     let key: String
44     let table: String?
45     let comment: String
46     
47     
48     init(_ string: String, tableName: String, comment: String) {
49         self.key = string
50         self.table = tableName
51         self.comment = comment
52     }
53 }