fix: localize files context menu
This commit is contained in:
@@ -195,7 +195,7 @@ function loadFilesComponent(document) {
|
||||
return { component, clipboard: sandbox.navigator.clipboard };
|
||||
}
|
||||
|
||||
function makeApi() {
|
||||
function makeApi(options = {}) {
|
||||
const externalCalls = [];
|
||||
const contributionCalls = [];
|
||||
const created = [];
|
||||
@@ -317,6 +317,15 @@ function makeApi() {
|
||||
};
|
||||
},
|
||||
},
|
||||
i18n: {
|
||||
t: (key, params, fallback) => {
|
||||
let value = options.translations && options.translations[key] ? options.translations[key] : (fallback || key);
|
||||
Object.entries(params || {}).forEach(([name, replacement]) => {
|
||||
value = value.replace(`{${name}}`, String(replacement));
|
||||
});
|
||||
return value;
|
||||
},
|
||||
},
|
||||
showExternalFile() {
|
||||
externalVisible = true;
|
||||
},
|
||||
@@ -444,6 +453,31 @@ async function flush() {
|
||||
throw new Error(`external file row not rendered after file.changed: ${container.textContent}`);
|
||||
}
|
||||
|
||||
const russianDocument = makeDocument();
|
||||
const { component: russianComponent } = loadFilesComponent(russianDocument);
|
||||
const russianApi = makeApi({
|
||||
translations: {
|
||||
'ui.open': 'Открыть',
|
||||
'ui.openExternal': 'Открыть во внешнем приложении',
|
||||
'ui.showInFolder': 'Показать в папке',
|
||||
'ui.rename': 'Переименовать',
|
||||
'ui.duplicate': 'Создать копию',
|
||||
'ui.cut': 'Вырезать',
|
||||
'ui.copy': 'Копировать',
|
||||
'ui.trash': 'Переместить в корзину',
|
||||
},
|
||||
});
|
||||
const russianContainer = new FakeNode('div');
|
||||
russianComponent.mount(russianContainer, {}, russianApi);
|
||||
await flush();
|
||||
const russianList = walk(russianContainer, (node) => node.getAttribute && node.getAttribute('data-files-list') !== undefined);
|
||||
const russianRow = walk(russianContainer, (node) => node.getAttribute && node.getAttribute('data-file-path') === 'Docs/readme.md');
|
||||
russianList.dispatchEvent('contextmenu', { target: russianRow, clientX: 20, clientY: 20 });
|
||||
const russianMenuText = russianDocument.body.textContent;
|
||||
['Открыть во внешнем приложении', 'Показать в папке', 'Переименовать', 'Создать копию', 'Вырезать', 'Копировать', 'Переместить в корзину'].forEach((label) => {
|
||||
if (!russianMenuText.includes(label)) throw new Error(`context menu label was not localized: ${label}`);
|
||||
});
|
||||
|
||||
console.log('files frontend smoke passed');
|
||||
})().catch((err) => {
|
||||
console.error(err);
|
||||
|
||||
Reference in New Issue
Block a user