ZenCopy 是您需要的最后一个复制(文本)管理器。使用 ZenCopy,您可以
ZenCopy 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod "ZenCopy"
要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install
请注意,复制可以包含参数。只需使用 $0、$1 等来设置您的参数。文本中的顺序无关紧要。
// 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")
在这个示例中,chat.poke 具有参数 $0 和 $1,它们的样式设置为“令牌”
ZenCopy.manager.config.addCopy("en", prefix: "chat") {
return [
...
"poke": ["@$0 ".style("token"), "pokes ", "@$1".style("token")] // note: this is chat.poke
]
}
我建议在项目中的 Copy.swift(您可以取任何名称)文件中存储所有字符串。我还建议使用复制的“前缀”来根据上下文区分键(例如,“全局”、“配置文件”、“聊天”等)
如果你们有任何疑问!请提交反馈、问题和拉取请求 :D
JP McGlone,[email protected]
ZenCopy可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。