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

Adopt l10n for media-preview #165525

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions extensions/media-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
"watch-web": "npx webpack-cli --config extension-browser.webpack.config --mode none --watch --info-verbosity verbose"
},
"dependencies": {
"@vscode/extension-telemetry": "0.6.2",
"vscode-nls": "^5.2.0"
"@vscode/extension-telemetry": "0.6.2"
},
"repository": {
"type": "git",
Expand Down
7 changes: 2 additions & 5 deletions extensions/media-preview/src/audioPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { BinarySizeStatusBarEntry } from './binarySizeStatusBarEntry';
import { MediaPreview, reopenAsText } from './mediaPreview';
import { escapeAttribute, getNonce } from './util/dom';

const localize = nls.loadMessageBundle();

class AudioPreviewProvider implements vscode.CustomReadonlyEditorProvider {

public static readonly viewType = 'vscode.audioPreview';
Expand Down Expand Up @@ -82,8 +79,8 @@ class AudioPreview extends MediaPreview {
<body class="container loading">
<div class="loading-indicator"></div>
<div class="loading-error">
<p>${localize('preview.audioLoadError', "An error occurred while loading the audio file.")}</p>
<a href="#" class="open-file-link">${localize('preview.audioLoadErrorLink', "Open file using VS Code's standard text/binary editor?")}</a>
<p>${vscode.l10n.t("An error occurred while loading the audio file.")}</p>
<a href="#" class="open-file-link">${vscode.l10n.t("Open file using VS Code's standard text/binary editor?")}</a>
</div>
<script src="${escapeAttribute(this.extensionResource('media', 'audioPreview.js'))}" nonce="${nonce}"></script>
</body>
Expand Down
14 changes: 6 additions & 8 deletions extensions/media-preview/src/binarySizeStatusBarEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { PreviewStatusBarEntry } from './ownedStatusBarEntry';

const localize = nls.loadMessageBundle();

class BinarySize {
static readonly KB = 1024;
Expand All @@ -17,29 +15,29 @@ class BinarySize {

static formatSize(size: number): string {
if (size < BinarySize.KB) {
return localize('sizeB', "{0}B", size);
return vscode.l10n.t("{0}B", size);
}

if (size < BinarySize.MB) {
return localize('sizeKB', "{0}KB", (size / BinarySize.KB).toFixed(2));
return vscode.l10n.t("{0}KB", (size / BinarySize.KB).toFixed(2));
}

if (size < BinarySize.GB) {
return localize('sizeMB', "{0}MB", (size / BinarySize.MB).toFixed(2));
return vscode.l10n.t("{0}MB", (size / BinarySize.MB).toFixed(2));
}

if (size < BinarySize.TB) {
return localize('sizeGB', "{0}GB", (size / BinarySize.GB).toFixed(2));
return vscode.l10n.t("{0}GB", (size / BinarySize.GB).toFixed(2));
}

return localize('sizeTB', "{0}TB", (size / BinarySize.TB).toFixed(2));
return vscode.l10n.t("{0}TB", (size / BinarySize.TB).toFixed(2));
}
}

export class BinarySizeStatusBarEntry extends PreviewStatusBarEntry {

constructor() {
super('status.imagePreview.binarySize', localize('sizeStatusBar.name', "Image Binary Size"), vscode.StatusBarAlignment.Right, 100);
super('status.imagePreview.binarySize', vscode.l10n.t("Image Binary Size"), vscode.StatusBarAlignment.Right, 100);
}

public show(owner: unknown, size: number | undefined) {
Expand Down
6 changes: 2 additions & 4 deletions extensions/media-preview/src/imagePreview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { BinarySizeStatusBarEntry } from '../binarySizeStatusBarEntry';
import { MediaPreview, PreviewState, reopenAsText } from '../mediaPreview';
import { escapeAttribute, getNonce } from '../util/dom';
import { SizeStatusBarEntry } from './sizeStatusBarEntry';
import { Scale, ZoomStatusBarEntry } from './zoomStatusBarEntry';

const localize = nls.loadMessageBundle();

export class PreviewManager implements vscode.CustomReadonlyEditorProvider {

Expand Down Expand Up @@ -181,8 +179,8 @@ class ImagePreview extends MediaPreview {
<body class="container image scale-to-fit loading">
<div class="loading-indicator"></div>
<div class="image-load-error">
<p>${localize('preview.imageLoadError', "An error occurred while loading the image.")}</p>
<a href="#" class="open-file-link">${localize('preview.imageLoadErrorLink', "Open file using VS Code's standard text/binary editor?")}</a>
<p>${vscode.l10n.t("An error occurred while loading the image.")}</p>
<a href="#" class="open-file-link">${vscode.l10n.t("Open file using VS Code's standard text/binary editor?")}</a>
</div>
<script src="${escapeAttribute(this.extensionResource('media', 'imagePreview.js'))}" nonce="${nonce}"></script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { PreviewStatusBarEntry } from '../ownedStatusBarEntry';

const localize = nls.loadMessageBundle();

export class SizeStatusBarEntry extends PreviewStatusBarEntry {

constructor() {
super('status.imagePreview.size', localize('sizeStatusBar.name', "Image Size"), vscode.StatusBarAlignment.Right, 101 /* to the left of editor status (100) */);
super('status.imagePreview.size', vscode.l10n.t("Image Size"), vscode.StatusBarAlignment.Right, 101 /* to the left of editor status (100) */);
}

public show(owner: unknown, text: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { PreviewStatusBarEntry as OwnedStatusBarEntry } from '../ownedStatusBarEntry';

const localize = nls.loadMessageBundle();

const selectZoomLevelCommandId = '_imagePreview.selectZoomLevel';

Expand All @@ -19,7 +17,7 @@ export class ZoomStatusBarEntry extends OwnedStatusBarEntry {
public readonly onDidChangeScale = this._onDidChangeScale.event;

constructor() {
super('status.imagePreview.zoom', localize('zoomStatusBar.name', "Image Zoom"), vscode.StatusBarAlignment.Right, 102 /* to the left of editor size entry (101) */);
super('status.imagePreview.zoom', vscode.l10n.t("Image Zoom"), vscode.StatusBarAlignment.Right, 102 /* to the left of editor size entry (101) */);

this._register(vscode.commands.registerCommand(selectZoomLevelCommandId, async () => {
type MyPickItem = vscode.QuickPickItem & { scale: Scale };
Expand All @@ -31,7 +29,7 @@ export class ZoomStatusBarEntry extends OwnedStatusBarEntry {
}));

const pick = await vscode.window.showQuickPick(options, {
placeHolder: localize('zoomStatusBar.placeholder', "Select zoom level")
placeHolder: vscode.l10n.t("Select zoom level")
});
if (pick) {
this._onDidChangeScale.fire({ scale: pick.scale });
Expand All @@ -47,7 +45,7 @@ export class ZoomStatusBarEntry extends OwnedStatusBarEntry {

private zoomLabel(scale: Scale): string {
return scale === 'fit'
? localize('zoomStatusBar.wholeImageLabel', "Whole Image")
? vscode.l10n.t("Whole Image")
: `${Math.round(scale * 100)}%`;
}
}
6 changes: 2 additions & 4 deletions extensions/media-preview/src/videoPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { BinarySizeStatusBarEntry } from './binarySizeStatusBarEntry';
import { MediaPreview, reopenAsText } from './mediaPreview';
import { escapeAttribute, getNonce } from './util/dom';

const localize = nls.loadMessageBundle();

class VideoPreviewProvider implements vscode.CustomReadonlyEditorProvider {

Expand Down Expand Up @@ -82,8 +80,8 @@ class VideoPreview extends MediaPreview {
<body class="loading">
<div class="loading-indicator"></div>
<div class="loading-error">
<p>${localize('preview.videoLoadError', "An error occurred while loading the video file.")}</p>
<a href="#" class="open-file-link">${localize('preview.videoLoadErrorLink', "Open file using VS Code's standard text/binary editor?")}</a>
<p>${vscode.l10n.t("An error occurred while loading the video file.")}</p>
<a href="#" class="open-file-link">${vscode.l10n.t("Open file using VS Code's standard text/binary editor?")}</a>
</div>
<script src="${escapeAttribute(this.extensionResource('media', 'videoPreview.js'))}" nonce="${nonce}"></script>
</body>
Expand Down
5 changes: 0 additions & 5 deletions extensions/media-preview/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,3 @@
dependencies:
"@microsoft/1ds-core-js" "^3.2.3"
"@microsoft/1ds-post-js" "^3.2.3"

vscode-nls@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.2.0.tgz#3cb6893dd9bd695244d8a024bdf746eea665cc3f"
integrity sha512-RAaHx7B14ZU04EU31pT+rKz2/zSl7xMsfIZuo8pd+KZO6PXtQmpevpq3vxvWNcrGbdmhM/rr5Uw5Mz+NBfhVng==