Skip to main content

BYNK_LOCALE_SRC

Constant BYNK_LOCALE_SRC 

Source
pub const BYNK_LOCALE_SRC: &str = "commons bynk.locale {\n\tuses bynk.locale.types\n\tuses bynk.list\n\tuses bynk.string\n\n\t---\n\tRenders `msg`. Slice 1 has no bundle/lookup mechanism: the output is\n\talways `msg.code`, plus a deterministic (key-sorted) \"{k=v, k=v}\" suffix\n\twhen `params` is non-empty. `tag` is accepted and reserved for a later\n\tslice \u{2014} it is not yet consulted.\n\t---\n\tfn render(tag: LocaleTag, msg: Message) -> String {\n\t\tif msg.params.length() == 0 {\n\t\t\tmsg.code\n\t\t} else {\n\t\t\tlet init: List[String] = List.empty()\n\t\t\tlet parts = reverse(msg.params\n\t\t\t\t.keys()\n\t\t\t\t.sortBy((k) => k)\n\t\t\t\t.fold(init, (acc, k) => match msg.params.get(k) {\n\t\t\t\t\tSome(arg) => acc.prepend(k.concat(\"=\").concat(renderArg(arg))),\n\t\t\t\t\tNone => acc,\n\t\t\t\t}))\n\t\t\tmsg.code.concat(\" {\").concat(join(parts, \", \")).concat(\"}\")\n\t\t}\n\t}\n\n\tfn renderArg(arg: MessageArg) -> String {\n\t\tmatch arg {\n\t\t\tText(v) => v,\n\t\t\tWhole(v) => v.toString(),\n\t\t\tNum(v) => v.toString(),\n\t\t\tMoment(v) => v.toString(),\n\t\t}\n\t}\n\n\t---\n\tStarts a `Message` with no substitution values. Building `Message`/\n\t`MessageArg` through this constructor and the `withX` helpers below (rather\n\tthan a record/sum literal) is deliberate: a consuming context\'s own `uses\n\tbynk.locale.types` gets a per-context-rebranded view of the *types* (v0.4\n\t\u{a7}3.4), but a plain `fn` mixed in from a commons is a value import and is\n\tnever rebranded \u{2014} so building a `Message` exclusively through these\n\tfunctions keeps `MessageArg`/`Message` values flowing untyped end to end,\n\tsidestepping the rebrand entirely.\n\t---\n\tfn message(code: String) -> Message { Message { code: code, params: Map.empty() } }\n\n\tfn withText(msg: Message, key: String, value: String) -> Message {\n\t\tMessage { code: msg.code, params: msg.params.insert(key, Text(value)) }\n\t}\n\n\tfn withWhole(msg: Message, key: String, value: Int) -> Message {\n\t\tMessage { code: msg.code, params: msg.params.insert(key, Whole(value)) }\n\t}\n\n\tfn withNum(msg: Message, key: String, value: Float) -> Message {\n\t\tMessage { code: msg.code, params: msg.params.insert(key, Num(value)) }\n\t}\n\n\tfn withMoment(msg: Message, key: String, value: Instant) -> Message {\n\t\tMessage { code: msg.code, params: msg.params.insert(key, Moment(value)) }\n\t}\n}\n";
Expand description

bynk.locale — the bundle-free render/renderArg helpers and the message/withText/withWhole/withNum/withMoment builder API (slice 1: render formats code plus a deterministic sorted-by-key rendering of params; no lookup, no locale-dependent behaviour). uses bynk.locale.types for the types its own signatures name.