-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathLocalizeString.swift
More file actions
85 lines (75 loc) · 2.75 KB
/
LocalizeString.swift
File metadata and controls
85 lines (75 loc) · 2.75 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// LocalizeString.swift
// Localize
//
// Copyright © 2019 @andresilvagomez.
//
import Foundation
/// String extension used to localize your keys matched
/// in your JSON File.
public extension String {
/// Localize a string using your JSON File
/// If the key is not found return the same key
/// that prevent replace untagged values
///
/// - returns: localized key or same text
var localized: String {
return Localize.localize(key: self)
}
/// Localize a string using your JSON File
/// If the key is not found return the same key
/// that prevent replace untagged values
///
/// - returns: localized key or same text
func localize() -> String {
return Localize.localize(key: self)
}
/// Localize a string using your JSON File
/// If the key is not found return the same key
/// that prevent replace untagged values
///
/// - returns: localized key or same text
func localize(tableName: String) -> String {
return Localize.localize(key: self, tableName: tableName)
}
/// Localize a string using your JSON File
/// that replace all % character in your string with replace value.
///
/// - parameter String: The replacement value
///
/// - returns: localized key or same text
func localize(value: String, tableName: String? = nil) -> String {
return Localize.localize(key: self, replace: value, tableName: tableName)
}
/// Localize a string using your JSON File
/// that replace each % character in your string with each replace value.
///
/// - parameter Strings: The replacement values
///
/// - returns: localized key or same text
func localize(values: String..., tableName: String? = nil) -> String {
return Localize.localize(key: self, values: values, tableName: tableName)
}
/// Localize string with dictionary values
/// get properties in your key with rule :property
/// if property not exist in this string, not is used.
///
/// - parameter [String:String]: The replacement dictionary
///
/// - returns: localized key or same text
func localize(
dictionary values: [String: String],
tableName: String? = nil) -> String {
return Localize.localize(key: self, dictionary: values, tableName: tableName)
}
/// Pluralize strings with numeric value
/// get localized and pluralized key acording with the rules
/// and value.
///
/// - parameter String: The value could you pluralize
///
/// - returns: Localized and Pluralized key according with the value.
func pluralize(value: Int, tableName: String? = nil) -> String {
return Pluralize.pluralize(key: self, value: value, tableName: tableName)
}
}