@reintent/lib/text
Words in two languages.
Every example speaks Chinese and English: a label, a note, a summary a model wrote. A text is { zh, en }, or one string that holds both ('床头 · the bed's head', the way vocabularies label their possibilities); say gives the reader's half.
The reader's language comes from the page: ?lang= first, then the one stored, then the browser's; Chinese when none says.
Interfaces
LangSources
Defined in: packages/lib/src/text.ts
Where a page's language is said, in the order they are asked.
Properties
| Property | Type | Description |
|---|---|---|
navigator? | string | The browser's language (navigator.language). |
search? | string | The page's query (?lang=en). |
stored? | string | null | What the reader chose before (localStorage.locale). |
Type Aliases
Lang
type Lang = "zh" | "en";Defined in: packages/lib/src/text.ts
A reader's language.
Text
type Text = object;Defined in: packages/lib/src/text.ts
Words in both languages.
Properties
Functions
both()
function both(s): Text;Defined in: packages/lib/src/text.ts
The same words in both languages: what a text is when only one was written.
Parameters
| Parameter | Type |
|---|---|
s | string |
Returns
isText()
function isText(x): x is Text;Defined in: packages/lib/src/text.ts
Whether a value is a Text.
Parameters
| Parameter | Type |
|---|---|
x | unknown |
Returns
x is Text
langOf()
function langOf(from?): Lang;Defined in: packages/lib/src/text.ts
The reader's language: ?lang= in the page's query, then what they chose before, then the
browser's language. Chinese when none of them says (as on a server).
Parameters
| Parameter | Type |
|---|---|
from | LangSources |
Returns
Example
import { langOf } from '@reintent/lib/text';
console.log(langOf({ search: '?lang=en', navigator: 'zh-CN' })); // → 'en'
console.log(langOf({ stored: 'zh', navigator: 'en-US' })); // → 'zh'
console.log(langOf({ navigator: 'en-GB' })); // → 'en'
console.log(langOf({})); // → 'zh'say()
function say(t, lang): string;Defined in: packages/lib/src/text.ts
The reader's half of a text. A string with both ('zh · en') is split at its middle dot; a
string in one language is said as it is.
Parameters
Returns
string
Example
import { say } from '@reintent/lib/text';
console.log(say({ zh: '门慢一点', en: 'the door, slower' }, 'en')); // → 'the door, slower'
console.log(say("床头 · the bed's head", 'zh')); // → '床头'
console.log(say('衣柜', 'en')); // → '衣柜'Last updated on
Edit on GitHub