oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2
3/// Every word Base shows, from `Resources/Localizable.xcstrings`. The keys
4/// are copy review's ids (copy-review/strings.json) and the web's approved
5/// copy (`ask.*`, from internal/web/templates/partials/chat.html and
6/// ask.js); scripts/check-strings.py holds the catalog to both. Nothing in
7/// the app hard-codes copy: a view shows `BaseText.text("…")`, or
8/// `Text(verbatim:)` for what the server or the person wrote.
9public enum BaseText {
10 /// The catalog's text for `key`.
11 public static func text(_ key: String) -> String {
12 Bundle.module.localizedString(forKey: key, value: nil, table: nil)
13 }
14
15 /// The catalog's text for `key` with each `{name}` filled in. Copy
16 /// review writes placeholders as `{email}`, `{team}`; the catalog keeps
17 /// them so, and the values are never looked up themselves.
18 public static func format(_ key: String, _ values: [String: String]) -> String {
19 var out = text(key)
20 for (name, value) in values { out = out.replacingOccurrences(of: "{\(name)}", with: value) }
21 return out
22 }
23
24 /// A plural entry (copy review's "Plural in the String Catalog"): the
25 /// catalog's forms select on `count`, written `%lld` there.
26 public static func plural(_ key: String, _ count: Int) -> String {
27 String.localizedStringWithFormat(text(key), count)
28 }
29}
30