12345678910111213141516171819202122232425262728293031323334 |
- import * as i18n from './LanguageData';
- import { _decorator, Component, Label } from 'cc';
- const { ccclass, property, executeInEditMode } = _decorator;
- @ccclass('LocalizedLabel')
- @executeInEditMode
- export class LocalizedLabel extends Component {
- label: Label | null = null;
- @property
- key: string = '';
- onLoad() {
- if (!i18n.ready) {
- i18n.init('zh');
- }
- this.fetchRender();
- }
- fetchRender () {
- let label = this.getComponent('cc.Label') as Label;
- if (label) {
- this.label = label;
- this.updateLabel();
- return;
- }
- }
- updateLabel () {
- this.label && (this.label.string = i18n.t(this.key));
- }
- }
|