File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,18 +110,18 @@ describe.concurrent("i18nDescription", () => {
110110 expect ( result ) . toBe ( "Default description" ) ;
111111 } ) ;
112112
113- it ( "没有 description 字段时返回 undefined " , ( ) => {
113+ it ( "没有 description 字段时返回 空字串 " , ( ) => {
114114 i18n . language = "en-US" ;
115115
116116 const script = {
117117 metadata : { } as SCMetadata ,
118118 } ;
119119
120120 const result = i18nDescription ( script ) ;
121- expect ( result ) . toBeUndefined ( ) ;
121+ expect ( result ) . toBe ( "" ) ;
122122 } ) ;
123123
124- it ( "description 字段为空数组时返回 undefined " , ( ) => {
124+ it ( "description 字段为空数组时返回 空字串 " , ( ) => {
125125 i18n . language = "en-US" ;
126126
127127 const script = {
@@ -131,6 +131,6 @@ describe.concurrent("i18nDescription", () => {
131131 } ;
132132
133133 const result = i18nDescription ( script ) ;
134- expect ( result ) . toBeUndefined ( ) ;
134+ expect ( result ) . toBe ( "" ) ;
135135 } ) ;
136136} ) ;
Original file line number Diff line number Diff line change @@ -76,26 +76,28 @@ export function initLocales(systemConfig: SystemConfig) {
7676
7777export const i18nLang = ( ) : string => `${ i18n ?. language ?. toLowerCase ( ) } ` ;
7878
79- export function i18nName ( script : { name : string ; metadata : SCMetadata } ) {
79+ export function i18nName ( script : { name : string ; metadata : SCMetadata } ) : string {
80+ const metadata = script . metadata ;
8081 const lang = i18nLang ( ) ;
81- let m = script . metadata [ `name:${ lang } ` ] ;
82+ let m = metadata [ `name:${ lang } ` ] ;
8283 if ( ! m ) {
8384 // 尝试只用前缀匹配
8485 const langPrefix = lang . split ( "-" ) [ 0 ] ;
85- m = script . metadata [ `name:${ langPrefix } ` ] ;
86+ m = metadata [ `name:${ langPrefix } ` ] ;
8687 }
8788 return m ? m [ 0 ] : script . name ;
8889}
8990
90- export function i18nDescription ( script : { metadata : SCMetadata } ) {
91+ export function i18nDescription ( script : { metadata : SCMetadata } ) : string {
92+ const metadata = script . metadata ;
9193 const lang = i18nLang ( ) ;
92- let m = script . metadata [ `description:${ lang } ` ] ;
94+ let m = metadata [ `description:${ lang } ` ] ;
9395 if ( ! m ) {
9496 // 尝试只用前缀匹配
9597 const langPrefix = lang . split ( "-" ) [ 0 ] ;
96- m = script . metadata [ `description:${ langPrefix } ` ] ;
98+ m = metadata [ `description:${ langPrefix } ` ] ;
9799 }
98- return m ? m [ 0 ] : script . metadata . description ?. [ 0 ] ;
100+ return m ? m [ 0 ] : metadata . description ?. [ 0 ] || "" ;
99101}
100102
101103// 判断是否是中文用户
You can’t perform that action at this time.
0 commit comments