首页 > 解决方案 > ReactJS:使用 react-jhipster 进行翻译

问题描述

我正在尝试使用 react-jhipster 来使用翻译

我创建了一个 js 文件:

翻译.js

export const english =
{
    "my_key": "delete"
}

在我要获得翻译的页面中:

import { Translate, TextFormat, getSortState, IPaginationBaseState, JhiPagination, JhiItemCount, translate } from 'react-jhipster';
import { english } from '../../../../i18n/eng/translation';

// In my render I'm going to use like this:

                        <span className="d-none d-md-inline">
                          <Translate contentKey={english.my_key} />
                        </span>

但它什么也没显示

翻译是:

import * as React from 'react';
export interface ITranslateProps {
    contentKey: string;
    children?: string | JSX.Element | Array<string | JSX.Element>;
    interpolate?: any;
    component?: string;
}
/**
 * Translates the given key using provided i18n values
 */
declare class Translate extends React.Component<ITranslateProps> {
    static defaultProps: {
        component: string;
    };
    shouldComponentUpdate(): boolean;
    render(): React.DOMElement<{
        dangerouslySetInnerHTML: {
            __html: any;
        };
    }, Element>;
}
export declare const translate: (contentKey: string, interpolate?: any, children?: string) => any;
export default Translate;

我该如何使用它?

谢谢

标签: javascriptreactjsinternationalizationjhipster

解决方案


推荐阅读