zhongrj
2025-11-24 276323dce9613867abb3f58a4cc2abbfb2fd0dea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import PropTypes from 'prop-types';
import { interpolate } from '../classes/gettext';
 
class Trans extends React.Component {
  static propTypes = {
      params: PropTypes.object
  }
 
  static defaultProps = {
    params: {}
  };
 
  render() {
      if (!this.props.children) return (<span/>);
 
      let content = "";
      if (typeof this.props.children === "string"){
        content = (<span dangerouslySetInnerHTML={{__html: interpolate(this.props.children, this.props.params)}}></span>);
      }else{
          content = [];
          let i = 0;
          this.props.children.forEach(c => {
            if (typeof c === "string"){
                content.push(<span key={i} dangerouslySetInnerHTML={{__html: interpolate(c, this.props.params)}}>
                            </span>);
            }else{
                content.push(<span key={i}>{c}</span>);
            }
            i++;
          });
      }
 
      return content;
  }
}
 
export default Trans;