如何让RichText实现i18n功能

const i18n = require(‘i18n’);
cc.Class({
extends: cc.RichText,

properties: {
    textKey: {
        default: 'TEXT_KEY',
        multiline: true,
        tooltip: 'Enter i18n key here',
        notify: function () {
            if (this._sgNode) {
                this._sgNode.setString(this.string);
                this._updateNodeSize();
            }
        }
    },
    string: {
        override: true,
        tooltip: 'Here shows the localized string of Text Key',
        get: function () {
            return i18n.t(this.textKey);
        },
        set: function (value) {
            this.textKey = value;
            //cc.warn('Please set label text key in Text Key property....'+value);
        }
    }
}

});

如上图,编辑后提示没有this._sgNode.setString(this.string);和this._updateNodeSize();方法
this._sgNode.setString(this.string);可以改成 this._sgNode.string = this.string;
但是RichText没有_updateNodeSize方法,求用什么方法可以刷新RichText

贴不能沉啊,求大神指点,查不到相关API

这个是 RichText 设置 string 以后做 _updateRichTextStatus 的操作,你执行一个 _updateRichTextStatus 看看是否可行

this.sgNode.setString(this.string);和this.updateNodeSize();方法 直接删掉吧,换成 this._updateRichTextStatus()

1赞

可以了,谢谢啊,另外请问一下_updateRichTextStatus 像这种api在哪可以查看呢?官方api里查不到

这个只能看源码,因为下划线的都是私有方法不提供给用户使用的

源码目前是不公开的对吧?

你听谁说的? git 上的传送门 https://github.com/cocos-creator/engine ,而且文档 http://www.cocos.com/docs/creator/advanced-topics/engine-customization.html 都写能自定义 engine,怎么可能会不公开呢?

好的,谢谢了,我看源码去