Implement localization (en only).

This commit is contained in:
Oliver Rümpelein 2021-01-13 18:02:22 +01:00
parent 2d809c955b
commit d6ddad67cc
5 changed files with 47 additions and 16 deletions

View file

@ -115,5 +115,18 @@
"DS4.ProfileSpecialCharacteristics": "Special Characteristics", "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.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.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"
} }

View file

@ -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: { profileDTypes: {
gender: "String", gender: "String",
@ -188,4 +188,14 @@ export const DS4 = {
eyeColor: "String", eyeColor: "String",
specialCharacteristics: "String", specialCharacteristics: "String",
}, },
/**
* Define localization strings for Chat Visibility
*/
chatVisibilities: {
roll: "DS4.ChatVisibilityRoll",
gmroll: "DS4.ChatVisibilityGmRoll",
blindroll: "DS4.ChatVisibilityBlindRoll",
selfroll: "DS4.ChatVisibilitySelfRoll",
},
}; };

View file

@ -85,6 +85,7 @@ Hooks.once("setup", function () {
"progression", "progression",
"language", "language",
"profile", "profile",
"chatVisibilities",
]; ];
// Exclude some from sorting where the default order matters // Exclude some from sorting where the default order matters

View file

@ -1,5 +1,7 @@
// TODO: Rename to something sane. // TODO: Rename to something sane.
import { DS4 } from "../config";
/** /**
* Provides default values for all arguments the `CheckFactory` expects. * Provides default values for all arguments the `CheckFactory` expects.
*/ */
@ -112,13 +114,15 @@ async function askGmModifier(
): Promise<GmModifierData> { ): Promise<GmModifierData> {
// Render model interface and return value // Render model interface and return value
const usedTemplate = template ?? "systems/ds4/templates/roll/roll-options.hbs"; const usedTemplate = template ?? "systems/ds4/templates/roll/roll-options.hbs";
const usedTitle = title ?? game.i18n.localize("DS4.RollDialogDefaultTitle");
const templateData = { const templateData = {
cssClass: "roll-option", cssClass: "roll-option",
title: title ?? "Roll Options", title: usedTitle,
checkTargetValue: targetValue, checkTargetValue: targetValue,
maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess, maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess,
minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure, minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure,
rollModes: rollModes, rollModes: rollModes,
config: DS4,
}; };
const renderedHtml = await renderTemplate(usedTemplate, templateData); const renderedHtml = await renderTemplate(usedTemplate, templateData);
@ -126,17 +130,22 @@ async function askGmModifier(
const dialogPromise = new Promise<HTMLFormElement>((resolve) => { const dialogPromise = new Promise<HTMLFormElement>((resolve) => {
new Dialog( new Dialog(
{ {
title: title ?? "Roll Options", title: usedTitle,
close: () => { close: () => {
// Don't do anything // Don't do anything
}, },
content: renderedHtml, content: renderedHtml,
buttons: { buttons: {
ok: { ok: {
label: "OK", label: game.i18n.localize("DS4.RollDialogOkButton"),
callback: (html: HTMLElement | JQuery) => { callback: (html: HTMLElement | JQuery) => {
if (!("jquery" in html)) { if (!("jquery" in html)) {
throw new Error("Internal Type Error"); throw new Error(
game.i18n.format("DS4.HtmlTypeError", {
exType: "JQuery",
realType: "HTMLElement",
}),
);
} else { } else {
const innerForm = html[0].querySelector("form"); const innerForm = html[0].querySelector("form");
resolve(innerForm); resolve(innerForm);
@ -144,7 +153,7 @@ async function askGmModifier(
}, },
}, },
cancel: { cancel: {
label: "Cancel", label: game.i18n.localize("DS4.RollDialogCancelButton"),
callback: () => { callback: () => {
// Don't do anything // Don't do anything
}, },
@ -160,7 +169,7 @@ async function askGmModifier(
} }
function parseDialogFormData(formData: HTMLFormElement, targetValue: number): GmModifierData { function parseDialogFormData(formData: HTMLFormElement, targetValue: number): GmModifierData {
const parsedData = { return {
checkTargetValue: parseInt(formData["ctv"]?.value) ?? targetValue, checkTargetValue: parseInt(formData["ctv"]?.value) ?? targetValue,
gmModifier: parseInt(formData["gmmod"]?.value) ?? 0, gmModifier: parseInt(formData["gmmod"]?.value) ?? 0,
maxCritSuccess: parseInt(formData["maxcoup"]?.value) ?? defaultCheckOptions.maxCritSuccess, maxCritSuccess: parseInt(formData["maxcoup"]?.value) ?? defaultCheckOptions.maxCritSuccess,
@ -168,8 +177,6 @@ function parseDialogFormData(formData: HTMLFormElement, targetValue: number): Gm
useSlayingDice: false, useSlayingDice: false,
rollMode: formData["visibility"]?.value ?? defaultCheckOptions.rollMode, rollMode: formData["visibility"]?.value ?? defaultCheckOptions.rollMode,
}; };
console.log("Data", parsedData);
return parsedData;
} }
// TODO: Remove unnecessary data step by step // TODO: Remove unnecessary data step by step

View file

@ -1,16 +1,16 @@
<form class="{{cssClass}} grid"> <form class="{{cssClass}} grid">
<label for="ctv">Check Target Value</label> <label for="ctv">{{localize "DS4.RollDialogTargetLabel"}}</label>
<input id="ctv" data-type="Number" type="number" name="ctv" value="{{checkTargetValue}}" /> <input id="ctv" data-type="Number" type="number" name="ctv" value="{{checkTargetValue}}" />
<label for="gmmod">Game Master Modifier</label> <label for="gmmod">{{localize "DS4.RollDialogModifierLabel"}}</label>
<input id="gmmod" data-type="Number" type="number" name="gmmod" value="0" /> <input id="gmmod" data-type="Number" type="number" name="gmmod" value="0" />
<label for="maxcoup">Coup to</label> <label for="maxcoup">{{localize "DS4.RollDialogCoupLabel"}}</label>
<input id="maxcoup" data-type="Number" type="number" name="maxcoup" value="{{maxCritSuccess}}" /> <input id="maxcoup" data-type="Number" type="number" name="maxcoup" value="{{maxCritSuccess}}" />
<label for="minfumble">Fumble from</label> <label for="minfumble">{{localize "DS4.RollDialogFumbleLabel"}}</label>
<input id="minfumble" data-type="Number" type="number" name="minfumble" value="{{minCritFailure}}" /> <input id="minfumble" data-type="Number" type="number" name="minfumble" value="{{minCritFailure}}" />
<label for="visibility">Visibility</label> <label for="visibility">{{localize "DS4.RollDialogVisibilityLabel"}}</label>
<select id="visibility" data-type="String"> <select id="visibility" data-type="String">
{{#each rollModes as |rollMode|}} {{#each rollModes as |rollMode|}}
<option value="{{rollMode}}">{{rollMode}}</option> <option value="{{rollMode}}">{{lookup ../config.chatVisibilities rollMode}}</option>
{{/each}} {{/each}}
</select> </select>
</form> </form>