Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored file src/index/search.js to avoid nesting #12

Open
wants to merge 2 commits into
base: f24
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
const section = title[1] === 'development' ? 'advanced' : title[1];
const subsection = title[2] ? ` > [[admin/menu:${section}/${title[2]}]]` : '';
title = `[[admin/menu:section-${section}]]${subsection}`;

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