Skip to content

Commit

Permalink
chore: move remaining file to l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Jun 21, 2023
1 parent 191c26b commit 6fcd396
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/environment-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AndroidEmulator, EnvironmentInfo, IosDevice, IosSimulator, TitaniumSDK,
import { iOSProvisioningProfileMatchesAppId } from './utils';
import { GlobalState } from './constants';
import { InteractionError } from './commands';
import { l10n } from 'vscode';

export class Environment {

Expand All @@ -32,9 +33,9 @@ export class Environment {
proc.on('close', (code) => {
ExtensionContainer.context.globalState.update(GlobalState.RefreshEnvironment, false);
if (code) {
const error = new InteractionError('Failed to get environment information');
const error = new InteractionError(l10n.t('Failed to get environment information'));
error.interactionChoices.push({
title: 'View Error',
title: l10n.t('View Error'),
run() {
ExtensionContainer.outputChannel.append(output);
ExtensionContainer.outputChannel.show();
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function startup (): Promise<void> {
ExtensionContainer.setContext(GlobalState.EnvironmentIssues, true);
const choice = await vscode.window.showWarningMessage(title, ...actions.map(action => action.title));
if (!choice) {
vscode.window.showErrorMessage('Cannot continue startup until all issues are resolved');
vscode.window.showErrorMessage(vscode.l10n.t('Cannot continue startup until all issues are resolved'));
return;
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function startup (): Promise<void> {
}

progress.report({
message: 'Fetching environment information'
message: vscode.l10n.t('Fetching environment information')
});

try {
Expand All @@ -129,7 +129,7 @@ export async function startup (): Promise<void> {
handleInteractionError(error);
return;
}
vscode.window.showErrorMessage('Error fetching Titanium environment');
vscode.window.showErrorMessage(vscode.l10n.t('Error fetching Titanium environment'));
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import * as utils from './utils';

import { Range, window, workspace } from 'vscode';
import { Range, l10n, window, workspace } from 'vscode';
import { handleInteractionError, InteractionError } from './commands/common';
import { Platform, ProjectType } from './types/common';
import { parseXmlString } from './common/utils';
Expand Down Expand Up @@ -73,7 +73,7 @@ export class Project {
if (this.type === 'app') {
return String(this.tiapp.id);
}
throw new Error('Project is not a Titanium application');
throw new Error(l10n.t('Project is not a Titanium application'));
}

/**
Expand Down Expand Up @@ -151,25 +151,25 @@ export class Project {
}
let line: number;
let column: number;
let message = 'Errors found in tiapp.xml';
let message = l10n.t('Errors found in tiapp.xml');
const columnExp = /Column: (.*?)(?:\s|$)/g;
const lineExp = /Line: (.*?)(?:\s|$)/g;
const columnMatch = columnExp.exec(err.message);
const lineMatch = lineExp.exec(err.message);

if (lineMatch) {
line = parseInt(lineMatch[1], 10);
message = `${message} on line ${line + 1}`;
message = l10n.t('{0} on line {1}', message, line + 1);
}

if (columnMatch) {
column = parseInt(columnMatch[1], 10);
message = `${message} in column ${column + 1}`;
message = l10n.t('{0} on line {1}', message, column + 1);
}

const error = new InteractionError(message);
error.interactionChoices.push({
title: 'Open tiapp.xml',
title: l10n.t('Open tiapp.xml'),
run: async () => {
const file = path.join(this.filePath, 'tiapp.xml');
const document = await workspace.openTextDocument(file);
Expand Down
12 changes: 6 additions & 6 deletions src/related.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import * as utils from './utils';

import { Uri, window, TextEditor, TextDocument } from 'vscode';
import { Uri, window, TextEditor, TextDocument, l10n } from 'vscode';
import { ExtensionContainer } from './container';
import { Project } from './project';
import { handleInteractionError, InteractionError } from './commands';
Expand All @@ -23,19 +23,19 @@ const alloyDirectoryMap: { [key: string]: string } = {
*/
export async function getTargetPath (project: Project, type: string, currentFilePath = window.activeTextEditor?.document.fileName): Promise<string> {
if (!currentFilePath) {
throw new InteractionError('No active edtor');
throw new InteractionError(l10n.t('No active edtor'));
}

const alloyRootPath = path.join(project.filePath, 'app');

if (!currentFilePath.includes(alloyRootPath)) {
throw new InteractionError('File is not part of an Alloy project');
throw new InteractionError(l10n.t('File is not part of an Alloy project'));
}

const pathUnderAlloy = path.relative(alloyRootPath, currentFilePath);

if (!/^(controllers|styles|views|widgets)/.test(pathUnderAlloy)) {
throw new InteractionError('File is not a controller, style, view or widget');
throw new InteractionError(l10n.t('File is not a controller, style, view or widget'));
}

const pathSplitArr = pathUnderAlloy.split(path.sep);
Expand All @@ -62,7 +62,7 @@ export async function getTargetPath (project: Project, type: string, currentFile
}
}

throw new InteractionError('Unable to find related file');
throw new InteractionError(l10n.t('Unable to find related file'));
}

/**
Expand All @@ -74,7 +74,7 @@ export async function getTargetPath (project: Project, type: string, currentFile
*/
export async function openRelatedFile (type: string, project?: Project): Promise<TextEditor|undefined> {
if (!window.activeTextEditor) {
window.showErrorMessage('No active editor');
window.showErrorMessage(l10n.t('No active editor'));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn, SpawnOptions } from 'child_process';
import { Terminal as VSTerminal, window } from 'vscode';
import { l10n, Terminal as VSTerminal, window } from 'vscode';
import { CommandError, CommandResponse } from './common/utils';

export default class Terminal {
Expand Down Expand Up @@ -56,7 +56,7 @@ export default class Terminal {

proc.on('close', code => {
if (code) {
const error = new CommandError('Failed to run command', `${command} ${args.join(' ')}`, code, output);
const error = new CommandError(l10n.t('Failed to run command'), `${command} ${args.join(' ')}`, code, output);
return reject(error);
}
return resolve({ output });
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import findUp from 'find-up';
import walkSync from 'klaw-sync';

import { platform } from 'os';
import { tasks, Task, ShellExecution, TaskScope } from 'vscode';
import { tasks, Task, ShellExecution, TaskScope, l10n } from 'vscode';
import { CreateOptions, CreateModuleOptions, PrettyDevelopmentTarget, PrettyTarget, Target } from './types/cli';
import { IosCert, IosCertificateType, Platform, PlatformPretty } from './types/common';
import { ExtensionContainer } from './container';
Expand Down Expand Up @@ -314,7 +314,7 @@ export function getCorrectCertificateName (certificateName: string, sdkVersion:
const certificate = ExtensionContainer.environment.iOSCertificates(certificateType).find((cert: IosCert) => cert.fullname === certificateName);

if (!certificate) {
throw new Error(`Failed to lookup certificate ${certificateName}`);
throw new Error(l10n.t('Failed to lookup certificate {0}', certificateName));
}

const coerced = semver.coerce(sdkVersion);
Expand Down Expand Up @@ -405,7 +405,7 @@ export function getDeviceNameFromId (deviceID: string, platform: Platform, targe
}

if (!deviceName) {
throw new Error(`Unable to find a name for ${deviceID}`);
throw new Error(l10n.t('Unable to find a name for {0}', deviceID));
}

return deviceName;
Expand All @@ -424,7 +424,7 @@ export async function findProjectDirectory (filePath: string): Promise<string> {
try {
const tiappFile = await findUp('tiapp.xml', { cwd: filePath, type: 'file' });
if (!tiappFile) {
throw new Error(`Unable to find project dir for ${filePath}`);
throw new Error(l10n.t('Unable to find project dir for {0}', filePath));
}

return path.dirname(tiappFile);
Expand Down

0 comments on commit 6fcd396

Please sign in to comment.