Types

JsxChildren

翻訳してレンダリングできる JSX コンテンツの型定義

概要

JsxChildren は、翻訳対象のテキスト、要素、variables を含む JSX コンテンツを表します。

type JsxChildren = JsxChild | JsxChild[];

構成

type JsxChild = string | JsxElement | Variable;
種類説明
stringプレーンテキストのコンテンツ
JsxElement構造化要素
Variable動的プレースホルダー

JSX 要素

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: ['こちらをクリック']
};

関連型

このガイドはいかがですか?