From 36025015ac4fba1e9c8cefd1da9d7d61b2df95b7 Mon Sep 17 00:00:00 2001 From: "Luca T." Date: Sun, 1 Sep 2024 19:47:41 +0200 Subject: [PATCH] added localization --- lang/en.json | 12 ++++++++++++ last-scene-view.js | 39 ++++++++++++++++++++++---------------- module.json | 14 +++++++++++--- templates/scene-config.hbs | 26 +++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 lang/en.json create mode 100644 templates/scene-config.hbs diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..44bca49 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,12 @@ +{ + "last-scene-view.options-name": "Last scene view.", + "last-scene-view.disabled": "Disbled.", + "last-scene-view.disabled-tooltip": "Disable for this scene.", + "last-scene-view.scene-config-note": "The checkbox will disable the module for the current scene. Click the clear button to remove every saved position for this scene.", + "last-scene-view.enable-gm": "Save last scene view for GM.", + "last-scene-view.enable-gm-note": "By default the last view will be saved for both players and GMs, you can disable it for GM and the scene will keep the configured Initial View Position in the scene configuration.", + "last-scene-view.timeout": "Timeout befor saving scene view", + "last-scene-view.timeout-note": "Number of seconds to wait before saving the new scene view position. Minimum 3 seconds", + "last-scene-view.position-restored": "Last scene view position restored!", + "last-scene-view.positions-deleted": "Every saved position for the scene \"{sceneName}\" has been eliminated!" +} \ No newline at end of file diff --git a/last-scene-view.js b/last-scene-view.js index d64e099..971e736 100644 --- a/last-scene-view.js +++ b/last-scene-view.js @@ -8,8 +8,8 @@ class LastSceneView { LastSceneView.listen(); game.settings.register(LastSceneView.mId, 'save_gm_view', { - name: 'Save last scene view for GM', - hint: 'By default the last view will be saved for both players and GMs, you can disable it for GM and the scene will keep the configured Initial View Position in the scene configuration.', + name: game.i18n.localize("last-scene-view.enable-gm"), + hint: game.i18n.localize("last-scene-view.enable-gm-note"), scope: 'world', requiresReload: true, default: true, @@ -18,8 +18,8 @@ class LastSceneView { }); game.settings.register(LastSceneView.mId, 'timeout', { - name: 'Timeout before saving scene view', - hint: 'Number of seconds to wait before saving the new scene view position. Minimum 3 seconds', + name: game.i18n.localize("last-scene-view.timeout"), + hint: game.i18n.localize("last-scene-view.timeout-note"), scope: 'world', requiresReload: true, default: 3, @@ -50,7 +50,7 @@ class LastSceneView { if (typeof game.scenes.current.flags?.lastSceneView?.lastPosition[game.userId] !== 'undefined') { // move the canvas and notify the user. canvas.pan(game.scenes.current.flags?.lastSceneView?.lastPosition[game.userId]); - ui.notifications.info('Last scene view position restored!'); + ui.notifications.info(game.i18n.localize("last-scene-view.position-restored")); } }) @@ -97,20 +97,27 @@ class LastSceneView { }); Hooks.on('renderSceneConfig', (s, h) => { - var disabled = s.document.flags?.lastSceneView?.disabled == true; - var scene_id = s.document._id; - let html = '
'; - html += '
'; - html += 'Disabled '; - html += ''; - html += '
'; - html += '

The checkbox will disable the module for the current scene. Click the clear button to remove every saved position for this scene.

'; - html += '
'; - $(html).insertBefore($('.form-group.initial-position', h)); + LastSceneView.addSceneConfig(s, h); }) } + static async addSceneConfig(s, h) { + var disabled = s.document.flags?.lastSceneView?.disabled == true; + var scene_id = s.document._id; + + const template_data = { + 'disabled': disabled, + 'scene_id': scene_id + } + + const template_file = "modules/last-scene-view/templates/scene-config.hbs"; + const rendered_html = await renderTemplate(template_file, template_data); + console.log(rendered_html); + + $(rendered_html).insertBefore($('.form-group.initial-position', h)); + } + static sceneSaved() { $('#navigation #scene-list .scene.view').addClass('saved'); } @@ -155,7 +162,7 @@ class LastSceneView { static async clearSavedPositions(scene_id) { game.scenes.get(scene_id).update({ [`flags.lastSceneView.lastPosition`]: 'undefined' }); - ui.notifications.warn('Every saved position for the scene "' + game.scenes.get(scene_id).name + '" has been eliminated!'); + ui.notifications.warn(game.i18n.format("last-scene-view.positions-deleted", { sceneName: game.scenes.get(scene_id).name })); } } diff --git a/module.json b/module.json index 67b20af..9ea7ab4 100644 --- a/module.json +++ b/module.json @@ -2,9 +2,9 @@ "id": "last-scene-view", "title": "Save last scene view", "description": "Restore scene position for each user to continue your last session exactly as you left it.", - "version": "1.1.0", - "download": "https://github.com/misthero/last-scene-view/releases/download/v1.1.0/last-scene-view.zip", - "manifest": "https://github.com/misthero/last-scene-view/releases/download/v1.1.0/module.json", + "version": "1.1.1", + "download": "https://github.com/misthero/last-scene-view/releases/download/v1.1.1/last-scene-view.zip", + "manifest": "https://github.com/misthero/last-scene-view/releases/download/v1.1.1/module.json", "url": "https://github.com/misthero/last-scene-view", "authors": [ { @@ -23,6 +23,14 @@ "styles": [ "css/last-scene-view.css" ], + "languages": [ + { + "lang": "en", + "name": "English", + "path": "lang/en.json", + "flags": {} + } + ], "relationships": {}, "socket": true } \ No newline at end of file diff --git a/templates/scene-config.hbs b/templates/scene-config.hbs new file mode 100644 index 0000000..b2955a7 --- /dev/null +++ b/templates/scene-config.hbs @@ -0,0 +1,26 @@ +
+ +
+ {{localize "last-scene-view.disabled"}} + + +
+

+ {{localize "last-scene-view.scene-config-note"}} +

+
\ No newline at end of file