Skip to content

Commit

Permalink
Use the localization technology in the website code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Jan 27, 2024
1 parent 449ce84 commit d10b3a1
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 134 deletions.
3 changes: 2 additions & 1 deletion source/website/dialogs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { AddDiv } from '../engine/viewer/domutils.js';
import { ButtonDialog, ListPopup } from './dialog.js';
import { Loc } from '../engine/core/localization.js';

export function ShowMessageDialog (title, message, subMessage)
{
let dialog = new ButtonDialog ();
let contentDiv = dialog.Init (title, [
{
name : 'OK',
name : Loc ('OK'),
onClick () {
dialog.Close ();
}
Expand Down
19 changes: 10 additions & 9 deletions source/website/exportdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ShowMessageDialog } from './dialogs.js';
import { DownloadArrayBufferAsFile } from './utils.js';
import { CookieGetStringVal, CookieSetStringVal } from './cookiehandler.js';
import { HandleEvent } from './eventhandler.js';
import { Loc } from '../engine/core/localization.js';

import * as fflate from 'fflate';

Expand Down Expand Up @@ -53,8 +54,8 @@ class ModelExporterUI
return AddSelectWithCookieSave (parameterValueDiv, cookieKey, values, defaultIndex);
}

this.visibleOnlySelect = AddSelectItem (parametersDiv, 'Scope', 'ov_last_scope', ['Entire Model', 'Visible Only'], 1);
this.rotationSelect = AddSelectItem (parametersDiv, 'Rotation', 'ov_last_rotation', ['No Rotation', '-90 Degrees', '90 Degrees'], 0);
this.visibleOnlySelect = AddSelectItem (parametersDiv, Loc ('Scope'), 'ov_last_scope', [Loc ('Entire Model'), Loc ('Visible Only')], 1);
this.rotationSelect = AddSelectItem (parametersDiv, Loc ('Rotation'), 'ov_last_rotation', [Loc ('No Rotation'), Loc ('-90 Degrees'), Loc ('90 Degrees')], 0);
}

ExportModel (model, callbacks)
Expand All @@ -77,15 +78,15 @@ class ModelExporterUI
let exporterModel = new ExporterModel (model, settings);
if (exporterModel.MeshInstanceCount () === 0) {
ShowMessageDialog (
'Export Failed',
'The model doesn\'t contain any meshes.',
Loc ('Export Failed'),
Loc ('The model doesn\'t contain any meshes.'),
null
);
return;
}

let progressDialog = new ProgressDialog ();
progressDialog.Init ('Exporting Model');
progressDialog.Init (Loc ('Exporting Model'));
progressDialog.Open ();

RunTaskAsync (() => {
Expand Down Expand Up @@ -142,24 +143,24 @@ class ExportDialog
Open (model, viewer)
{
let mainDialog = new ButtonDialog ();
let contentDiv = mainDialog.Init ('Export', [
let contentDiv = mainDialog.Init (Loc ('Export'), [
{
name : 'Close',
name : Loc ('Close'),
subClass : 'outline',
onClick () {
mainDialog.Close ();
}
},
{
name : 'Export',
name : Loc ('Export'),
onClick : () => {
mainDialog.Close ();
this.ExportFormat (model, viewer);
}
}
]);

let text = 'Select the format from the list below, and adjust the settings of the selected format.';
let text = Loc ('Select the format from the list below, and adjust the settings of the selected format.');
AddDiv (contentDiv, 'ov_dialog_section', text);

let formatRow = AddDiv (contentDiv, 'ov_dialog_row');
Expand Down
5 changes: 3 additions & 2 deletions source/website/measuretool.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BigEps, IsEqualEps, RadDeg } from '../engine/geometry/geometry.js';
import { AddDiv, ClearDomElement } from '../engine/viewer/domutils.js';
import { AddSvgIconElement, IsDarkTextNeededForColor } from './utils.js';
import { Loc } from '../engine/core/localization.js';

import * as THREE from 'three';
import { ColorComponentToFloat, RGBColor } from '../engine/model/color.js';
Expand Down Expand Up @@ -231,9 +232,9 @@ export class MeasureTool
this.panel.style.backgroundColor = 'transparent';
}
if (this.markers.length === 0) {
this.panel.innerHTML = 'Select a point.';
this.panel.innerHTML = Loc ('Select a point.');
} else if (this.markers.length === 1) {
this.panel.innerHTML = 'Select another point.';
this.panel.innerHTML = Loc ('Select another point.');
} else {
let calcResult = CalculateMarkerValues (this.markers[0], this.markers[1]);

Expand Down
7 changes: 4 additions & 3 deletions source/website/navigatorfilespanel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SetDomElementHeight, GetDomElementOuterHeight } from '../engine/viewer/domutils.js';
import { NavigatorPanel } from './navigatorpanel.js';
import { TreeViewButton, TreeViewButtonItem, TreeViewGroupItem, TreeViewSingleItem } from './treeview.js';
import { Loc } from '../engine/core/localization.js';

export class NavigatorFilesPanel extends NavigatorPanel
{
Expand All @@ -11,7 +12,7 @@ export class NavigatorFilesPanel extends NavigatorPanel

GetName ()
{
return 'Files';
return Loc ('Files');
}

GetIcon ()
Expand All @@ -38,7 +39,7 @@ export class NavigatorFilesPanel extends NavigatorPanel
const missingFiles = importResult.missingFiles;

if (missingFiles.length > 0) {
let missingFilesItem = new TreeViewGroupItem ('Missing Files', null);
let missingFilesItem = new TreeViewGroupItem (Loc ('Missing Files'), null);
missingFilesItem.ShowChildren (true);
this.treeView.AddChild (missingFilesItem);
for (let i = 0; i < missingFiles.length; i++) {
Expand All @@ -51,7 +52,7 @@ export class NavigatorFilesPanel extends NavigatorPanel
item.AppendButton (browseButton);
missingFilesItem.AddChild (item);
}
let filesItem = new TreeViewGroupItem ('Available Files', null);
let filesItem = new TreeViewGroupItem (Loc ('Available Files'), null);
filesItem.ShowChildren (true);
this.treeView.AddChild (filesItem);
for (let i = 0; i < usedFiles.length; i++) {
Expand Down
5 changes: 3 additions & 2 deletions source/website/navigatormaterialspanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CalculatePopupPositionToElementBottomRight, ShowListPopup } from './dia
import { MaterialItem } from './navigatoritems.js';
import { NavigatorPanel, NavigatorPopupButton } from './navigatorpanel.js';
import { GetMaterialName, GetMeshName } from './utils.js';
import { Loc, FLoc } from '../engine/core/localization.js';

class NavigatorMeshesPopupButton extends NavigatorPopupButton
{
Expand All @@ -19,7 +20,7 @@ class NavigatorMeshesPopupButton extends NavigatorPopupButton
return;
}

let meshesText = 'Meshes (' + this.meshInstanceArray.length + ')';
let meshesText = FLoc ('Meshes ({0})', this.meshInstanceArray.length);
this.buttonText.innerHTML = meshesText;
}

Expand Down Expand Up @@ -74,7 +75,7 @@ export class NavigatorMaterialsPanel extends NavigatorPanel

GetName ()
{
return 'Materials';
return Loc ('Materials');
}

GetIcon ()
Expand Down
17 changes: 9 additions & 8 deletions source/website/navigatormeshespanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CalculatePopupPositionToElementBottomRight, ShowListPopup } from './dia
import { MeshItem, NavigatorItemRecurse, NodeItem } from './navigatoritems.js';
import { NavigatorPanel, NavigatorPopupButton } from './navigatorpanel.js';
import { AddSvgIconElement, GetMaterialName, GetMeshName, GetNodeName, SetSvgIconImageElement } from './utils.js';
import { Loc, FLoc } from '../engine/core/localization.js';

const MeshesPanelMode =
{
Expand All @@ -27,7 +28,7 @@ class NavigatorMaterialsPopupButton extends NavigatorPopupButton
return;
}

let materialsText = 'Materials (' + this.materialInfoArray.length + ')';
let materialsText = FLoc ('Materials ({0})', this.materialInfoArray.length);
this.buttonText.innerHTML = materialsText;
}

Expand Down Expand Up @@ -86,7 +87,7 @@ export class NavigatorMeshesPanel extends NavigatorPanel

GetName ()
{
return 'Meshes';
return Loc ('Meshes');
}

GetIcon ()
Expand Down Expand Up @@ -228,38 +229,38 @@ export class NavigatorMeshesPanel extends NavigatorPanel

this.buttons = {
flatList : {
name : 'Flat list',
name : Loc ('Flat list'),
icon : 'flat_list',
div : null,
iconDiv : null
},
treeView : {
name : 'Tree view',
name : Loc ('Tree view'),
icon : 'tree_view',
div : null,
iconDiv : null
},
separator : null,
expandAll : {
name : 'Expand all',
name : Loc ('Expand all'),
icon : 'expand',
div : null,
iconDiv : null
},
collapseAll : {
name : 'Collapse all',
name : Loc ('Collapse all'),
icon : 'collapse',
div : null,
iconDiv : null
},
showHideMeshes : {
name : 'Show/hide meshes',
name : Loc ('Show/hide meshes'),
icon : 'visible',
div : null,
iconDiv : null
},
fitToWindow : {
name : 'Fit meshes to window',
name : Loc ('Fit meshes to window'),
icon : 'fit',
div : null,
iconDiv : null
Expand Down
9 changes: 5 additions & 4 deletions source/website/openurldialog.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { ReadLines } from '../engine/import/importerutils.js';
import { AddDiv, CreateDomElement } from '../engine/viewer/domutils.js';
import { ButtonDialog } from './dialog.js';
import { Loc } from '../engine/core/localization.js';

export function ShowOpenUrlDialog (onOk)
{
let dialog = new ButtonDialog ();
let urlsTextArea = CreateDomElement ('textarea', 'ov_dialog_textarea');
let contentDiv = dialog.Init ('Open from url', [
let contentDiv = dialog.Init (Loc ('Open from url'), [
{
name : 'Cancel',
name : Loc ('Cancel'),
subClass : 'outline',
onClick () {
dialog.Close ();
}
},
{
name : 'OK',
name : Loc ('OK'),
onClick () {
let urls = [];
ReadLines (urlsTextArea.value, (line) => {
Expand All @@ -26,7 +27,7 @@ export function ShowOpenUrlDialog (onOk)
}
}
]);
let text = 'Here you can load models based on their urls. You can add more lines if your model builds up from multiple files.';
let text = Loc ('Here you can load models based on their urls. You can add more lines if your model builds up from multiple files.');
AddDiv (contentDiv, 'ov_dialog_section', text);
contentDiv.appendChild (urlsTextArea);
dialog.Open ();
Expand Down
19 changes: 10 additions & 9 deletions source/website/sharingdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ShowMessageDialog } from './dialogs.js';
import { ButtonDialog } from './dialog.js';
import { CopyToClipboard } from './utils.js';
import { HandleEvent } from './eventhandler.js';
import { Loc } from '../engine/core/localization.js';

export function ShowSharingDialog (fileList, settings, viewer)
{
Expand All @@ -19,8 +20,8 @@ export function ShowSharingDialog (fileList, settings, viewer)

function AddCopyableTextInput (parentDiv, getText)
{
let copyText = 'Copy';
let copiedText = 'Copied';
let copyText = Loc ('Copy');
let copiedText = Loc ('Copied');
let container = AddDiv (parentDiv, 'ov_dialog_copyable_input');
let input = AddDomElement (container, 'input', null);
input.setAttribute ('type', 'text');
Expand All @@ -47,7 +48,7 @@ export function ShowSharingDialog (fileList, settings, viewer)
}

let section = AddDiv (parentDiv, 'ov_dialog_section');
AddDiv (section, 'ov_dialog_inner_title', 'Sharing Link');
AddDiv (section, 'ov_dialog_inner_title', Loc ('Sharing Link'));
let sharingLinkInput = AddCopyableTextInput (section, () => {
HandleEvent ('model_shared', 'sharing_link');
return GetSharingLink (modelFiles);
Expand Down Expand Up @@ -88,13 +89,13 @@ export function ShowSharingDialog (fileList, settings, viewer)
let useCurrentSettings = true;
let section = AddDiv (parentDiv, 'ov_dialog_section');
section.style.marginTop = '20px';
AddDiv (section, 'ov_dialog_inner_title', 'Embedding Code');
AddDiv (section, 'ov_dialog_inner_title', Loc ('Embedding Code'));
let optionsSection = AddDiv (section, 'ov_dialog_section');
let embeddingCodeInput = AddCopyableTextInput (section, () => {
HandleEvent ('model_shared', 'embedding_code');
return GetEmbeddingCode (modelFiles, useCurrentSettings, settings, viewer);
});
AddCheckboxLine (optionsSection, 'Use customized settings', 'embed_current_settings', (checked) => {
AddCheckboxLine (optionsSection, Loc ('Use customized settings', 'embed_current_settings'), (checked) => {
useCurrentSettings = checked;
embeddingCodeInput.value = GetEmbeddingCode (modelFiles, useCurrentSettings, settings, viewer);
});
Expand All @@ -104,8 +105,8 @@ export function ShowSharingDialog (fileList, settings, viewer)

if (!fileList.IsOnlyUrlSource ()) {
return ShowMessageDialog (
'Sharing Failed',
'Sharing works only if you load files by url. Please upload your model files to a web server, open them by url, and try embedding again.',
Loc ('Sharing Failed'),
Loc ('Sharing works only if you load files by url. Please upload your model files to a web server, open them by url, and try embedding again.'),
null
);
}
Expand All @@ -120,9 +121,9 @@ export function ShowSharingDialog (fileList, settings, viewer)
}

let dialog = new ButtonDialog ();
let contentDiv = dialog.Init ('Share', [
let contentDiv = dialog.Init (Loc ('Share'), [
{
name : 'Close',
name : Loc ('Close'),
onClick () {
dialog.Close ();
}
Expand Down
Loading

0 comments on commit d10b3a1

Please sign in to comment.