From 18807abceb7eb08b46adebe19dfcfb2a5766d972 Mon Sep 17 00:00:00 2001 From: YJSON Date: Wed, 15 Jul 2020 20:50:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20prototype=20getTitle=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20i18n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/bundle/prototype.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/editor-preset-vision/src/bundle/prototype.ts b/packages/editor-preset-vision/src/bundle/prototype.ts index 86a9a0c92..bda37a203 100644 --- a/packages/editor-preset-vision/src/bundle/prototype.ts +++ b/packages/editor-preset-vision/src/bundle/prototype.ts @@ -15,6 +15,7 @@ import { upgradePropConfig, upgradeConfigure, } from './upgrade-metadata'; +import { globalLocale } from '@ali/lowcode-editor-core'; import { designer } from '../editor'; import { uniqueId } from '@ali/lowcode-utils'; @@ -23,7 +24,7 @@ const GlobalPropsConfigure: Array<{ initials?: InitialItem[]; filters?: FilterItem[]; autoruns?: AutorunItem[]; - config: FieldConfig + config: FieldConfig; }> = []; const Overrides: { [componentName: string]: { @@ -53,7 +54,7 @@ function addGlobalPropsConfigure(config: OldGlobalPropConfig) { addAutorun: (item) => { autoruns.push(item); }, - }) + }), }); } function removeGlobalPropsConfigure(name: string) { @@ -82,7 +83,7 @@ function overridePropsConfigure(componentName: string, config: { [name: string]: override = upgradeConfigure(config, { addInitial, addFilter, addAutorun }); } else { override = {}; - Object.keys(config).forEach(key => { + Object.keys(config).forEach((key) => { override[key] = upgradePropConfig(config[key], { addInitial, addFilter, addAutorun }); }); } @@ -212,7 +213,7 @@ class Prototype { static addGlobalExtraActions = addGlobalExtraActions; static removeGlobalPropsConfigure = removeGlobalPropsConfigure; static overridePropsConfigure = overridePropsConfigure; - static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup: boolean = false) { + static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup = false) { return new Prototype(config, lookup); } @@ -220,7 +221,7 @@ class Prototype { readonly meta: ComponentMeta; readonly options: OldPrototypeConfig | ComponentMetadata; - constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup: boolean = false) { + constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup = false) { if (lookup) { this.meta = designer.getComponentMeta(input.componentName); this.options = this.meta.getMetadata(); @@ -257,7 +258,15 @@ class Prototype { return this.meta.getMetadata().experimental?.context?.[name]; } - getTitle() { + getTitle(currentLocale?: string) { + if (currentLocale && this.meta.title[currentLocale]) { + return this.meta.title[currentLocale]; + } + const locale = globalLocale.getLocale(); + if (this.meta.title && this.meta.title.type === 'i18n') { + return this.meta.title[locale] || this.meta.title; + } + return this.meta.title; }