Skip to content

Commit e899933

Browse files
committed
update extension page
1 parent 483b553 commit e899933

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

src/components/library-item/library-item.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
}
9393

9494
.library-item-name {
95-
width: 80%;
95+
width: 100%;
9696
margin: 0.25rem 0;
9797
text-align: center;
9898

@@ -106,6 +106,12 @@
106106
min-width: 0;
107107
}
108108

109+
.featured-text .library-item-name,
110+
.featured-extension-text .library-item-name {
111+
width: 100%;
112+
text-align: inherit;
113+
}
114+
109115
.featured-item {
110116
flex-basis: 280px;
111117
max-width: 280px;
@@ -335,8 +341,8 @@
335341
background: rgba(76, 151, 255, 0.9);
336342
}
337343

338-
.source-badge02engine {
339-
background: rgba(255, 140, 0, 0.92);
344+
.source-badgeEngine {
345+
background: #00BAAD;
340346
}
341347

342348
.source-badgeTw {

src/containers/extension-library.jsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
281314
const 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

Comments
 (0)