Skip to content
Merged
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
54 changes: 45 additions & 9 deletions qt-core/src/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
IsWindows,
OSExeSuffix,
searchForExeInQtInfo,
telemetry
telemetry,
QtWorkspaceFeatures
} from 'qt-lib';
import { coreAPI, projectManager } from '@/extension';
import { EXTENSION_ID } from '@/constants';
Expand All @@ -37,9 +38,17 @@ export async function openInLinguistCommand() {
}
const project = projectManager.findProjectContainingFile(activeDocument);
if (!project) {
logger.error('No project found for the active document');
logger.error('The active document does not belong to a project');
return;
}
const workspaceFeatures = coreAPI?.getValue<QtWorkspaceFeatures>(
project.folder,
CoreKey.WORKSPACE_FEATURES
);
const venvBinPath = coreAPI?.getValue<string>(
project.folder,
CoreKey.VENV_BIN_PATH
);
const selectedKitPath = coreAPI?.getValue<string>(
project.folder,
CoreKey.SELECTED_KIT_PATH
Expand All @@ -49,16 +58,38 @@ export async function openInLinguistCommand() {
CoreKey.SELECTED_QT_PATHS
);
let linguistPath: string | undefined;
if (selectedKitPath) {
linguistPath = await locateLinguist(selectedKitPath);
} else if (selectedQtPaths) {
linguistPath = await locateLinguistFromQtPaths(selectedQtPaths);

if (workspaceFeatures?.projectTypes.pyside) {
if (venvBinPath) {
linguistPath = await locateLinguistFromVenvBinPaths(venvBinPath);
}
}

if (workspaceFeatures?.projectTypes.cmake) {
if (selectedKitPath) {
linguistPath = await locateLinguist(selectedKitPath);
} else if (selectedQtPaths) {
linguistPath = await locateLinguistFromQtPaths(selectedQtPaths);
}
}

if (!linguistPath) {
logger.error('Linguist executable not found');
void vscode.window.showErrorMessage(
'Cannot find Qt Linguist executable. Check that the Qt version in the kit includes Qt Linguist.'
);

const isCMake = !!workspaceFeatures?.projectTypes.cmake;
const isPySide = !!workspaceFeatures?.projectTypes.pyside;
const message = ['Cannot find the Qt Linguist executable'];

if (isCMake && !isPySide) {
message.push('Check that the Qt version in the kit includes Qt Linguist');
} else if (!isCMake && isPySide) {
message.push(
'Check that PySide6 is properly installed ' +
'in a valid virtual environment'
);
}

void vscode.window.showErrorMessage(message.join('. '));
return;
}
if (!(await exists(linguistPath))) {
Expand Down Expand Up @@ -118,6 +149,11 @@ async function locateLinguist(selectedKitPath: string) {
return '';
}

async function locateLinguistFromVenvBinPaths(venvBinPath: string) {
const candidate = path.join(venvBinPath, 'pyside6-linguist' + OSExeSuffix);
return (await exists(candidate)) ? candidate : undefined;
}

function openInLinguist(linguistPath: string, file: string) {
const child = child_process.spawn(linguistPath, [file], {
stdio: 'inherit',
Expand Down
Loading