Types

JsxChildren

可用于翻译和渲染的 JSX 内容类型定义

概览

JsxChildren 表示用于翻译的 JSX 内容,包含文本、元素和变量。

type JsxChildren = JsxChild | JsxChild[];

结构

type JsxChild = string | JsxElement | Variable;
类型描述
string纯文本内容
JsxElement结构化元素
Variable动态占位符

JsxElement

type JsxElement = {
  t?: string;      // 标签名
  i?: number;      // id  
  d?: GTProp;      // GT 属性
  c?: JsxChildren; // 子内容
};

示例

基本用法

import { JsxChildren, Variable } from 'generaltranslation';

// 简单文本
const text: JsxChildren = "欢迎!";

// 带变量的文本
const greeting: JsxChildren = [
  "你好,",
  { k: 'userName' } as Variable,
  "!"
];

结构化元素

// Div 元素
const divElement: JsxChildren = {
  t: 'div',
  c: ['这里是内容']
};

// 带标题的链接
const linkElement: JsxChildren = {
  t: 'a',
  d: { ti: '访问主页' },
  c: ['点击这里']
};

相关类型

这份指南怎么样?

JsxChildren