@@ -278,6 +278,39 @@ const getNameText = (intl, value) => {
278278 return '' ;
279279} ;
280280
281+ const getLocalizedGalleryText = ( fallbackValue , translations , locale ) => {
282+ if ( ! translations || typeof translations !== 'object' ) {
283+ return fallbackValue ;
284+ }
285+ const normalizedLocale = typeof locale === 'string' ? locale . replace ( / _ / g, '-' ) . toLowerCase ( ) : '' ;
286+ const languageCode = normalizedLocale . split ( '-' ) [ 0 ] ;
287+ const entries = Object . entries ( translations ) ;
288+ const exactMatch = entries . find ( ( [ key ] ) => key . replace ( / _ / g, '-' ) . toLowerCase ( ) === normalizedLocale ) ;
289+ if ( exactMatch && typeof exactMatch [ 1 ] === 'string' && exactMatch [ 1 ] ) {
290+ return exactMatch [ 1 ] ;
291+ }
292+ const languageMatch = entries . find ( ( [ key ] ) => key . replace ( / _ / g, '-' ) . toLowerCase ( ) . split ( '-' ) [ 0 ] === languageCode ) ;
293+ if ( languageMatch && typeof languageMatch [ 1 ] === 'string' && languageMatch [ 1 ] ) {
294+ return languageMatch [ 1 ] ;
295+ }
296+ return fallbackValue ;
297+ } ;
298+
299+ const translateGalleryItem = ( item , locale ) => {
300+ if ( ! item || typeof item !== 'object' ) {
301+ return item ;
302+ }
303+ return {
304+ ...item ,
305+ name : typeof item . name === 'string' ?
306+ getLocalizedGalleryText ( item . name , item . nameTranslations , locale ) :
307+ item . name ,
308+ description : typeof item . description === 'string' ?
309+ getLocalizedGalleryText ( item . description , item . descriptionTranslations , locale ) :
310+ item . description
311+ } ;
312+ } ;
313+
281314const fetchPenguinModLibrary = async ( ) => {
282315 try {
283316 const module = await import (
@@ -563,12 +596,17 @@ class ExtensionLibrary extends React.PureComponent {
563596 return this . props . intl . formatMessage ( sourceMessages [ sourceKey ] || messages . sourceOther ) ;
564597 }
565598 getLibraryItems ( ) {
566- const baseLibrary = extensionLibraryContent . map ( toLibraryItem ) ;
599+ const locale = this . props . intl ?. locale ;
600+ const baseLibrary = extensionLibraryContent
601+ . map ( toLibraryItem )
602+ . map ( item => translateGalleryItem ( item , locale ) ) ;
567603 if ( this . state . gallery ) {
568604 return [
569605 ...baseLibrary ,
570606 toLibraryItem ( galleryMore ) ,
571- ...this . state . gallery . map ( toLibraryItem )
607+ ...this . state . gallery
608+ . map ( toLibraryItem )
609+ . map ( item => translateGalleryItem ( item , locale ) )
572610 ] ;
573611 }
574612 if ( this . state . galleryError ) {
@@ -991,7 +1029,7 @@ class ExtensionLibrary extends React.PureComponent {
9911029
9921030 const sourceToneMap = {
9931031 [ SOURCE_KEYS . SCRATCH ] : 'Scratch' ,
994- [ SOURCE_KEYS . ENGINE ] : '02engine ' ,
1032+ [ SOURCE_KEYS . ENGINE ] : 'Engine ' ,
9951033 [ SOURCE_KEYS . TW ] : 'Tw' ,
9961034 [ SOURCE_KEYS . PM ] : 'Pm' ,
9971035 [ SOURCE_KEYS . MIST ] : 'Mist' ,
0 commit comments