TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2016 |
SPMSupports SPM | ✗ |
Maintained by JP McGlone.
ZenCopy is the last copy (text) manager you’ll ever need. With ZenCopy you can:
ZenCopy is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ZenCopy"
To run the example project, clone the repo, and run pod install
from the Example directory first.
You’ll notice that Copy can include args. Simply use $0, $1, … to set your args. Order within the text doesn’t matter.
// english chat copy. prefix is for establishing context (optional)
ZenCopy.manager.config.addCopy("en", prefix: "chat") {
return [
"dance": ["@$0 dances with themself"], // note: this is chat.dance
]
}
// spanish chat copy
ZenCopy.manager.config.addCopy("sp", prefix: "chat") {
return [
"dance": ["@$0 baila con sí mismos"], // note: this is chat.dance
]
}
NSAttributedString
myLabel.attributedText = ZenCopy.manager.attributedString(key: "global.fun", args: [sender, other])
ZenCopy.manager.config.setStyles {
return [
"action": Style(
color: .lightGrayColor()
),
"token": Style(
color: .blueColor(),
fontSize: 14
),
"hulk": Style (
color: .greenColor(),
fontSize: 40
)
]
}
let atUserRegex = "(@[A-Za-z0-9_]*)"
mutableAttributedString.regexFind(atUserRegex, addStyle: "token")
In this example, chat.poke has arguments $0 and $1 styled as “token”
ZenCopy.manager.config.addCopy("en", prefix: "chat") {
return [
...
"poke": ["@$0 ".style("token"), "pokes ", "@$1".style("token")] // note: this is chat.poke
]
}
I recommend storing all your strings in a Copy.swift (name it what you want) file within your project. I also recommend making use of the copy ‘prefixes’ to separate your keys by context (e.g. “global”, “profile”, “chat”, etc.)
Let me know if you have any questions! Please submit feedback, issues, and pull requests :D
JP McGlone, [email protected]
ZenCopy is available under the MIT license. See the LICENSE file for more info.