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

PropertyTypeDescription
kstringVariable key/name
i?numberInternal identifier
v?VariableTypeFormatting type

VariableType

type VariableType = 'v' | 'n' | 'd' | 'c';
ValueDescription
'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.'
];

How is this guide?

Variable