From d6ddad67cc9cb96ebab8d7e2b54473af478e2684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Wed, 13 Jan 2021 18:02:22 +0100 Subject: [PATCH] Implement localization (en only). --- src/lang/en.json | 15 ++++++++++++++- src/module/config.ts | 12 +++++++++++- src/module/ds4.ts | 1 + src/module/rolls/check-factory.ts | 23 +++++++++++++++-------- src/templates/roll/roll-options.hbs | 12 ++++++------ 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/lang/en.json b/src/lang/en.json index 4f79f7ef..4e90df36 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -115,5 +115,18 @@ "DS4.ProfileSpecialCharacteristics": "Special Characteristics", "DS4.WarningManageActiveEffectOnOwnedItem": "Managing Active Effects within an Owned Item is not currently supported and will be added in a subsequent update.", "DS4.ErrorDiceCritOverlap": "There's an overlap between Fumbles and Coups", - "DS4.ErrorExplodingRecursionLimitExceeded": "Maximum recursion depth for exploding dice roll exceeded" + "DS4.ErrorExplodingRecursionLimitExceeded": "Maximum recursion depth for exploding dice roll exceeded", + "DS4.RollDialogDefaultTitle": "Roll Options", + "DS4.RollDialogOkButton": "Ok", + "DS4.RollDialogCancelButton": "Cancel", + "DS4.HtmlTypeError": "Type Error: Expected {exType}, got {realType}", + "DS4.RollDialogTargetLabel": "Check Target Number", + "DS4.RollDialogModifierLabel": "Game Master Modifier", + "DS4.RollDialogCoupLabel": "Coup to", + "DS4.RollDialogFumbleLabel": "Fumble from", + "DS4.RollDialogVisibilityLabel": "Visibility", + "DS4.ChatVisibilityRoll": "All", + "DS4.ChatVisibilityGmRoll": "Self & GM", + "DS4.ChatVisibilityBlindRoll": "GM only", + "DS4.ChatVisibilitySelfRoll": "Self only" } diff --git a/src/module/config.ts b/src/module/config.ts index 03b2c9d5..7997e44b 100644 --- a/src/module/config.ts +++ b/src/module/config.ts @@ -175,7 +175,7 @@ export const DS4 = { }, /** - * Define the profile info types for hanndlebars of a character + * Define the profile info types for handlebars of a character */ profileDTypes: { gender: "String", @@ -188,4 +188,14 @@ export const DS4 = { eyeColor: "String", specialCharacteristics: "String", }, + + /** + * Define localization strings for Chat Visibility + */ + chatVisibilities: { + roll: "DS4.ChatVisibilityRoll", + gmroll: "DS4.ChatVisibilityGmRoll", + blindroll: "DS4.ChatVisibilityBlindRoll", + selfroll: "DS4.ChatVisibilitySelfRoll", + }, }; diff --git a/src/module/ds4.ts b/src/module/ds4.ts index 4da8a49c..a676b49b 100644 --- a/src/module/ds4.ts +++ b/src/module/ds4.ts @@ -85,6 +85,7 @@ Hooks.once("setup", function () { "progression", "language", "profile", + "chatVisibilities", ]; // Exclude some from sorting where the default order matters diff --git a/src/module/rolls/check-factory.ts b/src/module/rolls/check-factory.ts index 4be81ee7..90562dbf 100644 --- a/src/module/rolls/check-factory.ts +++ b/src/module/rolls/check-factory.ts @@ -1,5 +1,7 @@ // TODO: Rename to something sane. +import { DS4 } from "../config"; + /** * Provides default values for all arguments the `CheckFactory` expects. */ @@ -112,13 +114,15 @@ async function askGmModifier( ): Promise { // Render model interface and return value const usedTemplate = template ?? "systems/ds4/templates/roll/roll-options.hbs"; + const usedTitle = title ?? game.i18n.localize("DS4.RollDialogDefaultTitle"); const templateData = { cssClass: "roll-option", - title: title ?? "Roll Options", + title: usedTitle, checkTargetValue: targetValue, maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess, minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure, rollModes: rollModes, + config: DS4, }; const renderedHtml = await renderTemplate(usedTemplate, templateData); @@ -126,17 +130,22 @@ async function askGmModifier( const dialogPromise = new Promise((resolve) => { new Dialog( { - title: title ?? "Roll Options", + title: usedTitle, close: () => { // Don't do anything }, content: renderedHtml, buttons: { ok: { - label: "OK", + label: game.i18n.localize("DS4.RollDialogOkButton"), callback: (html: HTMLElement | JQuery) => { if (!("jquery" in html)) { - throw new Error("Internal Type Error"); + throw new Error( + game.i18n.format("DS4.HtmlTypeError", { + exType: "JQuery", + realType: "HTMLElement", + }), + ); } else { const innerForm = html[0].querySelector("form"); resolve(innerForm); @@ -144,7 +153,7 @@ async function askGmModifier( }, }, cancel: { - label: "Cancel", + label: game.i18n.localize("DS4.RollDialogCancelButton"), callback: () => { // Don't do anything }, @@ -160,7 +169,7 @@ async function askGmModifier( } function parseDialogFormData(formData: HTMLFormElement, targetValue: number): GmModifierData { - const parsedData = { + return { checkTargetValue: parseInt(formData["ctv"]?.value) ?? targetValue, gmModifier: parseInt(formData["gmmod"]?.value) ?? 0, maxCritSuccess: parseInt(formData["maxcoup"]?.value) ?? defaultCheckOptions.maxCritSuccess, @@ -168,8 +177,6 @@ function parseDialogFormData(formData: HTMLFormElement, targetValue: number): Gm useSlayingDice: false, rollMode: formData["visibility"]?.value ?? defaultCheckOptions.rollMode, }; - console.log("Data", parsedData); - return parsedData; } // TODO: Remove unnecessary data step by step diff --git a/src/templates/roll/roll-options.hbs b/src/templates/roll/roll-options.hbs index 9e2b320e..8c3e7dc3 100644 --- a/src/templates/roll/roll-options.hbs +++ b/src/templates/roll/roll-options.hbs @@ -1,16 +1,16 @@
- + - + - + - + - +