Skip to content

liblxn/lxn-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lxn-js

lxn-go is an lxn client library for the Javascript programming language.

Translating Text

To translate text, a catalog has to be loaded:

function readCatalog(buf: BufferSource): Translator

This function reads a binary catalog from buf, which could either be an ArrayBuffer or an ArrayBufferView, and returns its translator function. Once a translator function of type

type Translator = (key: string, ctx: Context) => string;

is obtained, it can be used to convert a key and a context into a message. The key specifies the message key within the catalog preceded by its section, i.e. section.message-key (or simply message-key if the message has no section). The context contains all the necessary variables to render this message correctly. For each variable in the catalog there has to be a value of the corresponding type.