Skip to content
dxcufgb edited this page Oct 30, 2026 · 1 revision

API

For other modules.

game.modules.get("dxcufgbs-linguistic-chat").api is set in init, so it is there from setup on.

Function
knownLanguages(actor) Array of the language ids the actor knows: the same list the module uses to decide who understands a message. Universal languages (Common), the languages on the character sheet, the extra languages a GM added in Manage Languages, and the whole dialect family when Dialects are mutually understood is on. Without an actor, only the universal languages.
languages() Array of the available languages as {id, label}: the system's list plus the GM's changes from Manage Languages.

From another module

const MOD = "dxcufgbs-linguistic-chat";
const api = game.modules.get(MOD)?.active ? game.modules.get(MOD).api : null;

// Which languages does this character know?
const actor = game.user.character;
const known = api?.knownLanguages(actor) ?? [];         // e.g. ["common", "elvish", "dwarvish"]
const speaksElvish = known.includes("elvish");

// All languages with their display names:
for (const { id, label } of api?.languages() ?? []) console.log(id, label);

// After a GM saves the Manage Languages dialog (language definitions and character languages).
Hooks.on(`${MOD}.languagesChanged`, () => console.log("languages changed"));

// A chat message sent in a language carries these flags (plain messages have none):
Hooks.on("createChatMessage", message => {
  const language = message.getFlag(MOD, "language");    // language id, e.g. "elvish"
  if (!language) return;
  const label = message.getFlag(MOD, "label");          // display name, e.g. "Elvish"
  const gibberish = message.getFlag(MOD, "translated"); // the text listeners who don't know it see
  console.log(label, gibberish, message.content);       // content is the original text, HTML-escaped
});

Hook and flags

  • dxcufgbs-linguistic-chat.languagesChanged is called with Hooks.callAll and no arguments, and only on the client of the GM who saved.
  • The chat message flags are written by the module; read them, don't change them.
  • The actor flag languages is internal: it holds only the GM's extra languages, not the ones on the sheet, and may change. Use api.knownLanguages(actor) instead.

Clone this wiki locally