Skip to content

Commit

Permalink
changed lines 100-107 to avoid nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
mrahmatu committed Aug 29, 2024
1 parent e3e539d commit 5dbe394
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/admin/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ async function buildNamespace(language, namespace) {
if (!translations || !Object.keys(translations).length) {
return await fallback(namespace);
}
// join all translations into one string separated by newlines
let str = Object.keys(translations).map(key => translations[key]).join('\n');
// Join all translations into one string separated by newlines
let str = Object.values(translations).join('\n');
str = sanitize(str);

let title = namespace;
title = title.match(/admin\/(.+?)\/(.+?)$/);
title = `[[admin/menu:section-${
title[1] === 'development' ? 'advanced' : title[1]
}]]${title[2] ? (` > [[admin/menu:${
title[1]}/${title[2]}]]`) : ''}`;
// Extract the section and subsection from the namespace
let title = namespace.match(/admin\/(.+?)\/(.+?)$/);

title = await translator.translate(title);
if (title) {
let section = title[1] === 'development' ? 'advanced' : title[1];

Check failure on line 107 in src/admin/search.js

View workflow job for this annotation

GitHub Actions / test

'section' is never reassigned. Use 'const' instead
let subsection = title[2] ? ` > [[admin/menu:${section}/${title[2]}]]` : '';

Check failure on line 108 in src/admin/search.js

View workflow job for this annotation

GitHub Actions / test

'subsection' is never reassigned. Use 'const' instead
title = `[[admin/menu:section-${section}]]${subsection}`;

// Translate the title
title = await translator.translate(title);
}
return {
namespace: namespace,
translations: `${str}\n${title}`,
Expand Down

0 comments on commit 5dbe394

Please sign in to comment.