Skip to content

Commit

Permalink
Remove remaining uses of LocalizePF2e (foundryvtt#7508)
Browse files Browse the repository at this point in the history
  • Loading branch information
In3luki committed Apr 22, 2023
1 parent 1966f3b commit 813145e
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 121 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"migrate": "esno ./build/run-migration.ts",
"lint": "npm run lint:ts && npm run lint:json",
"lint:ts": "eslint ./src ./tests ./types --ext .ts",
"lint:json": "eslint ./static --ext .json --no-eslintrc --plugin json --rule 'json/*: error'",
"lint:json": "eslint ./static --ext .json --no-eslintrc --plugin json --rule \"json/*: error\"",
"lint:fix": "eslint ./src ./tests ./types --ext .ts --fix"
},
"author": "The PF2e System Developers",
Expand Down
3 changes: 1 addition & 2 deletions src/module/item/abc/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ABCFeatureEntryData } from "@item/abc/data.ts";
import { FeatCategory } from "@item/feat/types.ts";
import { FEAT_CATEGORIES } from "@item/feat/values.ts";
import { ItemSheetDataPF2e, ItemSheetPF2e } from "@item/sheet/index.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { htmlClosest, setHasElement } from "@util";

abstract class ABCSheetPF2e<TItem extends ABCItem> extends ItemSheetPF2e<TItem> {
Expand Down Expand Up @@ -59,7 +58,7 @@ abstract class ABCSheetPF2e<TItem extends ABCItem> extends ItemSheetPF2e<TItem>
const goodCategories = validCategories.map((c) => game.i18n.localize(CONFIG.PF2E.featCategories[c]));
if (goodCategories.length === 1) {
const badCategory = game.i18n.localize(CONFIG.PF2E.featCategories[feat.category]);
const warning = game.i18n.format(LocalizePF2e.translations.PF2E.Item.ABC.InvalidDrop, {
const warning = game.i18n.format("PF2E.Item.ABC.InvalidDrop", {
badType: badCategory,
goodType: goodCategories[0],
});
Expand Down
16 changes: 6 additions & 10 deletions src/module/item/armor/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AutomaticBonusProgression as ABP } from "@actor/character/automatic-bon
import { ItemSummaryData } from "@item/data/index.ts";
import { getResilientBonus, PhysicalItemHitPoints, PhysicalItemPF2e } from "@item/physical/index.ts";
import { MAGIC_TRADITIONS } from "@item/spell/values.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { addSign, ErrorPF2e, setHasElement, sluggify } from "@util";
import { ArmorCategory, ArmorGroup, ArmorSource, ArmorSystemData, BaseArmorType } from "./index.ts";

Expand Down Expand Up @@ -212,13 +211,12 @@ class ArmorPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Phy
htmlOptions: EnrichHTMLOptions = {}
): Promise<ItemSummaryData> {
const systemData = this.system;
const translations = LocalizePF2e.translations.PF2E;
const properties = [
this.isArmor ? CONFIG.PF2E.armorCategories[this.category] : CONFIG.PF2E.weaponCategories.martial,
`${addSign(this.acBonus)} ${translations.ArmorArmorLabel}`,
this.isArmor ? `${systemData.dex.value || 0} ${translations.ArmorDexLabel}` : null,
this.isArmor ? `${systemData.check.value || 0} ${translations.ArmorCheckLabel}` : null,
this.speedPenalty ? `${systemData.speed.value || 0} ${translations.ArmorSpeedLabel}` : null,
`${addSign(this.acBonus)} ${game.i18n.localize("PF2E.ArmorArmorLabel")}`,
this.isArmor ? `${systemData.dex.value || 0} ${game.i18n.localize("PF2E.ArmorDexLabel")}` : null,
this.isArmor ? `${systemData.check.value || 0} ${game.i18n.localize("PF2E.ArmorCheckLabel")}` : null,
this.speedPenalty ? `${systemData.speed.value || 0} ${game.i18n.localize("PF2E.ArmorSpeedLabel")}` : null,
];

return this.processChatData(htmlOptions, {
Expand All @@ -229,17 +227,15 @@ class ArmorPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Phy
}

override generateUnidentifiedName({ typeOnly = false }: { typeOnly?: boolean } = { typeOnly: false }): string {
const translations = LocalizePF2e.translations.PF2E;
const base = this.baseType ? translations.Item.Armor.Base[this.baseType] : null;
const base = this.baseType ? CONFIG.PF2E.baseArmorTypes[this.baseType] : null;
const group = this.group ? CONFIG.PF2E.armorGroups[this.group] : null;
const fallback = this.isShield ? "PF2E.ArmorTypeShield" : "ITEM.TypeArmor";

const itemType = game.i18n.localize(base ?? group ?? fallback);

if (typeOnly) return itemType;

const formatString = LocalizePF2e.translations.PF2E.identification.UnidentifiedItem;
return game.i18n.format(formatString, { item: itemType });
return game.i18n.format("PF2E.identification.UnidentifiedItem", { item: itemType });
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/module/item/armor/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PreparedMaterials,
} from "@item/physical/index.ts";
import { createSheetTags, SheetOptions } from "@module/sheet/helpers.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { ArmorCategory, ArmorGroup, ArmorPF2e, BaseArmorType } from "./index.ts";

class ArmorSheetPF2e extends PhysicalItemSheetPF2e<ArmorPF2e> {
Expand All @@ -32,7 +31,7 @@ class ArmorSheetPF2e extends PhysicalItemSheetPF2e<ArmorPF2e> {
armorPropertyRunes: CONFIG.PF2E.armorPropertyRunes,
categories: CONFIG.PF2E.armorCategories,
groups: CONFIG.PF2E.armorGroups,
baseTypes: LocalizePF2e.translations.PF2E.Item.Armor.Base,
baseTypes: CONFIG.PF2E.baseArmorTypes,
bulkTypes: CONFIG.PF2E.bulkTypes,
preciousMaterials: this.prepareMaterials(ARMOR_MATERIAL_VALUATION_DATA),
...propertyRuneSlots,
Expand Down
4 changes: 1 addition & 3 deletions src/module/item/armor/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { LocalizePF2e } from "@system/localize.ts";

type ArmorTrait = keyof ConfigPF2e["PF2E"]["armorTraits"];
type ArmorCategory = keyof ConfigPF2e["PF2E"]["armorCategories"];
type ArmorGroup = keyof ConfigPF2e["PF2E"]["armorGroups"];
type BaseArmorType = keyof typeof LocalizePF2e.translations.PF2E.Item.Armor.Base;
type BaseArmorType = keyof ConfigPF2e["PF2E"]["baseArmorTypes"];
type ResilientRuneType = "" | "resilient" | "greaterResilient" | "majorResilient";
type OtherArmorTag = "shoddy";

Expand Down
12 changes: 5 additions & 7 deletions src/module/item/equipment/document.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ActorPF2e } from "@actor";
import { ItemSummaryData } from "@item/data/index.ts";
import { PhysicalItemPF2e } from "@item/physical/index.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { objectHasKey, sluggify } from "@util";
import { EquipmentSource, EquipmentSystemData, EquipmentTrait } from "./data.ts";
import { OtherEquipmentTag } from "./types.ts";
Expand Down Expand Up @@ -38,21 +37,20 @@ class EquipmentPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends
}

override generateUnidentifiedName({ typeOnly = false }: { typeOnly?: boolean } = { typeOnly: false }): string {
const translations = LocalizePF2e.translations.PF2E.identification;
const identificationConfig = CONFIG.PF2E.identification;
const slotType = /book\b/.test(this.slug ?? "")
? "Book"
: /\bring\b/.test(this.slug ?? "")
? "Ring"
: this.system.usage.value?.replace(/^worn/, "").capitalize() ?? "";

const itemType = objectHasKey(translations.UnidentifiedType, slotType)
? translations.UnidentifiedType[slotType]
: translations.UnidentifiedType.Object;
const itemType = objectHasKey(identificationConfig.UnidentifiedType, slotType)
? game.i18n.localize(identificationConfig.UnidentifiedType[slotType])
: game.i18n.localize(identificationConfig.UnidentifiedType.Object);

if (typeOnly) return itemType;

const formatString = translations.UnidentifiedItem;
return game.i18n.format(formatString, { item: itemType });
return game.i18n.format(identificationConfig.UnidentifiedItem, { item: itemType });
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/module/item/physical/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { MystifiedTraits } from "@item/data/values.ts";
import { CoinsPF2e } from "@item/physical/helpers.ts";
import { Rarity, Size } from "@module/data.ts";
import { UserPF2e } from "@module/user/document.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { ErrorPF2e, isObject, sluggify, sortBy } from "@util";
import { getUnidentifiedPlaceholderImage } from "../identification.ts";
import { Bulk, stackDefinitions, weightToBulk } from "./bulk.ts";
Expand Down Expand Up @@ -419,11 +418,10 @@ abstract class PhysicalItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | n
(() => {
if (status === "identified") return this.description;

const formatString = LocalizePF2e.translations.PF2E.identification.UnidentifiedDescription;
const itemType = this.generateUnidentifiedName({ typeOnly: true });
const caseCorrect = (noun: string) =>
game.i18n.lang.toLowerCase() === "de" ? noun : noun.toLowerCase();
return game.i18n.format(formatString, { item: caseCorrect(itemType) });
return game.i18n.format("PF2E.identification.UnidentifiedDescription", { item: caseCorrect(itemType) });
})();

return {
Expand Down Expand Up @@ -470,8 +468,7 @@ abstract class PhysicalItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | n
const itemType = game.i18n.localize(`ITEM.Type${this.type.capitalize()}`);
if (typeOnly) return itemType;

const formatString = LocalizePF2e.translations.PF2E.identification.UnidentifiedItem;
return game.i18n.format(formatString, { item: itemType });
return game.i18n.format("PF2E.identification.UnidentifiedItem", { item: itemType });
}

/** Include mystification-related rendering instructions for views that will display this data. */
Expand All @@ -483,7 +480,7 @@ abstract class PhysicalItemPF2e<TParent extends ActorPF2e | null = ActorPF2e | n
if (trait.excluded) {
delete trait.description;
} else if (trait.mystified) {
const gmNote = LocalizePF2e.translations.PF2E.identification.TraitGMNote;
const gmNote = game.i18n.localize("PF2E.identification.TraitGMNote");
trait.description = trait.description
? `${gmNote}\n\n${game.i18n.localize(trait.description)}`
: gmNote;
Expand Down
9 changes: 5 additions & 4 deletions src/module/item/sheet/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
processTagifyInSubmitData,
} from "@module/sheet/helpers.ts";
import { InlineRollLinks } from "@scripts/ui/inline-roll-links.ts";
import { LocalizePF2e } from "@system/localize.ts";
import {
BasicConstructorOptions,
SELECTABLE_TAG_FIELDS,
Expand Down Expand Up @@ -147,10 +146,12 @@ export class ItemSheetPF2e<TItem extends ItemPF2e> extends ItemSheet<TItem> {
ruleEditing: !!this.editingRuleElement,
rules: {
labels: rules.map((ruleData: RuleElementSource) => {
const translations: Record<string, string> = LocalizePF2e.translations.PF2E.RuleElement;
const localization = CONFIG.PF2E.ruleElement;
const key = String(ruleData.key).replace(/^PF2E\.RuleElement\./, "");
const label = translations[key] ?? translations.Unrecognized;
const recognized = label !== translations.Unrecognized;
const label = game.i18n.localize(
localization[key as keyof typeof localization] ?? localization.Unrecognized
);
const recognized = label !== game.i18n.localize(localization.Unrecognized);
return { label, recognized };
}),
selection: {
Expand Down
12 changes: 4 additions & 8 deletions src/module/item/weapon/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { MAGIC_SCHOOLS, MAGIC_TRADITIONS } from "@item/spell/values.ts";
import { OneToThree } from "@module/data.ts";
import { UserPF2e } from "@module/user/index.ts";
import { DamageCategorization } from "@system/damage/helpers.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { ErrorPF2e, objectHasKey, setHasElement, sluggify } from "@util";
import type { WeaponDamage, WeaponFlags, WeaponMaterialData, WeaponSource, WeaponSystemData } from "./data.ts";
import type {
Expand Down Expand Up @@ -480,7 +479,6 @@ class WeaponPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ph

/** Generate a weapon name base on precious-material composition and runes */
generateMagicName(): string {
const translations = LocalizePF2e.translations.PF2E;
const baseWeapons = CONFIG.PF2E.baseWeaponTypes;

const storedName = this._source.name;
Expand All @@ -506,7 +504,7 @@ class WeaponPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ph
property3: runes.property[2] && game.i18n.localize(CONFIG.PF2E.weaponPropertyRunes[runes.property[2]]),
property4: runes.property[3] && game.i18n.localize(CONFIG.PF2E.weaponPropertyRunes[runes.property[3]]),
};
const formatStrings = translations.Item.Weapon.GeneratedName;
const formatStrings = CONFIG.PF2E.weaponGeneratedNames;
// Construct a localization key from the weapon material and runes
const formatString = (() => {
const potency = params.potency && "Potency";
Expand All @@ -524,7 +522,7 @@ class WeaponPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ph
const key = ([potency, striking, properties, material]
.filter((keyPart): keyPart is string => !!keyPart)
.join("") || null) as keyof typeof formatStrings | null;
return key && formatStrings[key];
return key && game.i18n.localize(formatStrings[key]);
})();

return formatString ? game.i18n.format(formatString, params) : this.name;
Expand All @@ -537,16 +535,14 @@ class WeaponPF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extends Ph
}

override generateUnidentifiedName({ typeOnly = false }: { typeOnly?: boolean } = { typeOnly: false }): string {
const translations = LocalizePF2e.translations.PF2E;
const base = this.baseType ? translations.Weapon.Base[this.baseType] : null;
const base = this.baseType ? CONFIG.PF2E.baseWeaponTypes[this.baseType] : null;
const group = this.group ? CONFIG.PF2E.weaponGroups[this.group] : null;
const fallback = "ITEM.TypeWeapon";
const itemType = game.i18n.localize(base ?? group ?? fallback);

if (typeOnly) return itemType;

const formatString = LocalizePF2e.translations.PF2E.identification.UnidentifiedItem;
return game.i18n.format(formatString, { item: itemType });
return game.i18n.format("PF2E.identification.UnidentifiedItem", { item: itemType });
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/module/item/weapon/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PreciousMaterialType } from "@item/physical/types.ts";
import { LocalizePF2e } from "@system/localize.ts";
import {
MELEE_WEAPON_GROUPS,
WEAPON_CATEGORIES,
Expand All @@ -14,7 +13,7 @@ type WeaponCategory = SetElement<typeof WEAPON_CATEGORIES>;
type MeleeWeaponGroup = SetElement<typeof MELEE_WEAPON_GROUPS>;

type WeaponGroup = SetElement<typeof WEAPON_GROUPS>;
type BaseWeaponType = keyof typeof LocalizePF2e.translations.PF2E.Weapon.Base;
type BaseWeaponType = keyof ConfigPF2e["PF2E"]["baseWeaponTypes"];

type WeaponTrait = keyof ConfigPF2e["PF2E"]["weaponTraits"];
type OtherWeaponTag = "crossbow" | "improvised" | "shoddy";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ActorSourcePF2e } from "@actor/data/index.ts";
import { ItemSourcePF2e } from "@item/data/index.ts";
import { HomebrewTag, HOMEBREW_TRAIT_KEYS } from "@system/settings/homebrew/index.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { sluggify } from "@util";
import { MigrationBase } from "../base.ts";

Expand Down Expand Up @@ -45,7 +44,7 @@ export class Migration674StableHomebrewTagIDs extends MigrationBase {
for (const tag of tags) {
tag.id = `hb_${sluggify(tag.value)}`;
const tagMap: Record<string, string> =
key === "baseWeapons" ? LocalizePF2e.translations.PF2E.Weapon.Base : CONFIG.PF2E[key];
key === "baseWeapons" ? CONFIG.PF2E.baseWeaponTypes : CONFIG.PF2E[key];
tagMap[tag.id] = tag.value;
delete tagMap[key];
}
Expand Down
5 changes: 2 additions & 3 deletions src/module/rules/rule-element/fast-healing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ActorType } from "@actor/data/index.ts";
import { ItemPF2e } from "@item";
import { ChatMessagePF2e } from "@module/chat-message/index.ts";
import { DamageRoll } from "@system/damage/roll.ts";
import { LocalizePF2e } from "@system/localize.ts";
import { localizeList, objectHasKey, tupleHasValue } from "@util";
import { RuleElementData, RuleElementOptions, RuleElementPF2e, RuleElementSource } from "./index.ts";

Expand Down Expand Up @@ -70,10 +69,10 @@ class FastHealingRuleElement extends RuleElementPF2e implements FastHealingData
}

const roll = (await new DamageRoll(`${value}`).evaluate({ async: true })).toJSON();
const { ReceivedMessage } = LocalizePF2e.translations.PF2E.Encounter.Broadcast.FastHealing[this.type];
const receivedMessage = game.i18n.localize(`PF2E.Encounter.Broadcast.FastHealing.${this.type}.ReceivedMessage`);
const details = this.details;
const postFlavor = details ? `<div data-visibility="owner">${details}</div>` : "";
const flavor = `<div>${ReceivedMessage}</div>${postFlavor}`;
const flavor = `<div>${receivedMessage}</div>${postFlavor}`;
const rollMode = this.actor.hasPlayerOwner ? "publicroll" : "gmroll";
const speaker = ChatMessagePF2e.getSpeaker({ actor: this.actor, token: this.token });
ChatMessagePF2e.create({ flavor, speaker, type: CONST.CHAT_MESSAGE_TYPES.ROLL, rolls: [roll] }, { rollMode });
Expand Down
19 changes: 8 additions & 11 deletions src/module/system/check/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
DegreeOfSuccess,
DegreeOfSuccessString,
} from "../degree-of-success.ts";
import { LocalizePF2e } from "../localize.ts";
import { TextEditorPF2e } from "../text-editor.ts";
import { CheckModifiersDialog } from "./dialog.ts";
import { CheckRoll, CheckRollDataPF2e } from "./roll.ts";
Expand Down Expand Up @@ -528,15 +527,15 @@ class CheckPF2e {
};
})();

const translations = LocalizePF2e.translations.PF2E.Check;
const { checkDCs } = CONFIG.PF2E;

// DC, circumstance adjustments, and the target's name
const dcData = ((): ResultFlavorTemplateData["dc"] => {
const dcType = game.i18n.localize(
dc.label?.trim() ||
(objectHasKey(translations.DC.Specific, dc.slug)
? translations.DC.Specific[dc.slug]
: translations.DC.Unspecific)
game.i18n.localize(
objectHasKey(checkDCs.Specific, dc.slug) ? checkDCs.Specific[dc.slug] : checkDCs.Unspecific
)
);

// Get any circumstance penalties or bonuses to the target's DC
Expand All @@ -552,9 +551,9 @@ class CheckPF2e {
const visible = targetActor?.hasPlayerOwner || dc.visible || game.settings.get("pf2e", "metagame_showDC");

if (typeof preadjustedDC !== "number" || circumstances.length === 0) {
const labelKey = targetData
? translations.DC.Label.WithTarget
: customLabel ?? translations.DC.Label.NoTarget;
const labelKey = game.i18n.localize(
targetData ? checkDCs.Label.WithTarget : customLabel ?? checkDCs.Label.NoTarget
);
const markup = game.i18n.format(labelKey, { dcType, dc: dc.value, target: targetData?.name ?? null });

return { markup, visible };
Expand All @@ -569,9 +568,7 @@ class CheckPF2e {

// If the adjustment direction is "no-change", the bonuses and penalties summed to zero
const translation =
adjustment.direction === "no-change"
? translations.DC.Label.NoChangeTarget
: translations.DC.Label.AdjustedTarget;
adjustment.direction === "no-change" ? checkDCs.Label.NoChangeTarget : checkDCs.Label.AdjustedTarget;

const markup = game.i18n.format(translation, {
target: targetData?.name ?? game.user.name,
Expand Down
Loading

0 comments on commit 813145e

Please sign in to comment.