Skip to content

Commit

Permalink
PF2e: integrate with system's languages manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mclemente committed Jan 16, 2024
1 parent 94af7f3 commit 2d8674c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/module/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ export default class PolyglotHooks {
}
}

static async closeHomebrewElements(homebrewElements, html) {
if (game.system.id === "pf2e") {
await game.polyglot.languageProvider.getLanguages();
await game.settings.set("polyglot", "Languages", game.polyglot.languageProvider.languages);
}
}

// Re-checks the user languages for the GM when activating another party on the Actors sidebar.
static renderActorDirectoryPF2e(actors, html, data) {
game.polyglot.updateUserLanguages(game.polyglot.chatElement);
Expand Down
52 changes: 35 additions & 17 deletions src/module/providers/pf2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,42 @@ export default class pf2eLanguageProvider extends LanguageProvider {
};
}

addLanguage(lang) {
if (!lang) return;
lang = lang.trim();
let key = lang.toLowerCase().replace(/[\s']/g, "_");
const homebrewLanguagesObj = game.settings.get("pf2e", "homebrew.languages");
const homebrewLanguagesKeys = homebrewLanguagesObj.map((a) => a.id);
const homebrewLanguagesValues = homebrewLanguagesObj.map((a) => a.value);
if (homebrewLanguagesValues.includes(lang)) {
const index = homebrewLanguagesValues.indexOf(lang);
key = homebrewLanguagesKeys[index];
}
async getLanguages() {
const languagesSetting = game.settings.get("polyglot", "Languages");
this.languages[key] = {
label: lang,
font: languagesSetting[key]?.font || this.languages[key]?.font || this.defaultFont,
rng: languagesSetting[key]?.rng ?? "default",
};
this.addToConfig(key, lang);
const langs = {};
const systemLanguages = foundry.utils.deepClone(CONFIG.PF2E.languages);
delete systemLanguages.common;
Object.keys(systemLanguages).forEach((key) => {
langs[key] = {
label: game.i18n.localize(`PF2E.Actor.Creature.Language.${key}`),
font: languagesSetting[key]?.font || this.languages[key]?.font || this.defaultFont,
rng: languagesSetting[key]?.rng ?? "default",
};
});
const customSystemLanguages = game.settings.get("pf2e", "homebrew.languages");
customSystemLanguages.forEach((l) => {
const key = l.id;
langs[key] = {
label: l.value,
font: languagesSetting[key]?.font || this.languages[key]?.font || this.defaultFont,
rng: languagesSetting[key]?.rng ?? "default",
};
});
this.languages = langs;
}

loadLanguages() {}

addLanguage() {}

removeLanguage() {}

getSystemDefaultLanguage() {
return game.settings.get("pf2e", "homebrew.languageRarities").commonLanguage;
}

getDefaultLanguage() {
this.defaultLanguage = this.getSystemDefaultLanguage();
}

filterUsers(ownedActors) {
Expand Down

0 comments on commit 2d8674c

Please sign in to comment.