struct Stelios::IO::Badge::Text
- Stelios::IO::Badge::Text
- Stelios::IO::Badge
- Struct
- Value
- Object
Overview
The most basic Badge
variant, for displaying raw text to the renderer that doesn't have any additional info attached to it.
Despite being a basic badge format, it isn't a simple one. Text
badges are used for translation keys in localization.
The #key
of a Text
badge may be a string, which means an unlocalized string, or a symbol, which means a locale lookup. The locale
lookup is left to the renderer. In either case, the resulting string may additionally contain localization placeholders.
These placeholders are replaced by the renderer with other Badge
s from the #args
array.
There are 3 kinds of placeholders available:
%%n
. This is a simple substitution, where the placeholder is replaced by the badge at the nth index in
the #args
array.
%!n{key val}
. Similar to the above, but applies variant information. The key and value pairs shouldn't contain spaces. To specify multiple
key-value pairs, separate them with |
, for example, %!1{key1 val1|key2 val2|key3 val3}
. See Badge#variant
for more about variants.
%?n{k string}
. Similar to the above, but specifically for pluralization. This means the renderer picks the correct plural variant according
to the placeholder key. Also similarly, multiple plural forms are separated with |
, however the strings here may contain spaces. k stands
for a single character specifying the kind of the branch. An English localization might use 1
for singular and +
for plural, but is
arbitrary, with only the limiting factor being that it must be a single character. Example: He was offering $?1{1 a single gold coin|+ %%1 gold coins}
Defined in:
engine/io.crConstructors
- .new(key : String | Symbol, args : Array(Badge) = [] of Badge, *, emphasis : String | Symbol | Nil = nil)
- .new(key : String | Symbol, *args : Badge | String, emphasis : String | Symbol | Nil = nil)
Instance Method Summary
Instance methods inherited from struct Stelios::IO::Badge
initialize
initialize,
variant : Hash(String, String | Nil)
variant
Constructor methods inherited from struct Stelios::IO::Badge
new
new
Instance methods inherited from class Object
to_sban(io : IO)to_sban(encoder : SBAN::Encoder)
to_sban : Bytes to_sban