Variable
Type definition for variables used in translation content
Overview
Variable represents a placeholder for dynamic content in translations.
type Variable = {
k: string;
i?: number;
v?: VariableType;
};Properties
| Property | Type | Description |
|---|---|---|
k | string | Variable key/name |
i? | number | Internal identifier |
v? | VariableType | Formatting type |
Variable Type
type VariableType = 'v' | 'n' | 'd' | 'c';| Value | Description |
|---|---|
'v' | Plain-text substitution |
'n' | Number formatting |
'd' | Date formatting |
'c' | Currency formatting |
Examples
Basic usage
import { Variable } from 'generaltranslation';
// Text variable
const nameVariable: Variable = {
k: 'userName'
};
// Number variable
const countVariable: Variable = {
k: 'itemCount',
v: 'n'
};
// Currency variable
const priceVariable: Variable = {
k: 'price',
v: 'c'
};In JSX content
const welcomeContent = [
'Welcome back, ',
{ k: 'userName' } as Variable,
'! You have ',
{ k: 'messageCount', v: 'n' } as Variable,
' messages.'
];Related Types
VariableType- Formatting type specifications
How is this guide?