Strings for the drop-down list of note icons in map notes are not present in the usual Foundry Virtual Tabletop translation file. However, they can be localized by overriding the list of icons in the software configuration with JavaScript.
This guide was written for Foundry VTT 0.7.9. This is an opinionated guide and instructs you to use certain formatting, file hierarchies, and the included JavaScript code contains logging statements. Finnish is used as an example language.
You will be building (and the JavaScript code assumes) the following file structure in your module directory (replace fi-FI
with your language tag):
your-module-directory ├── module.json : Module information │ ├─┬─lang │ └── fi-FI_icons.json : Core Foundry VTT translation │ └─┬─scripts └── fi-FI.js : Script to load at startup
The following placeholder values are used in the code below. You need to replace them with the correct values for your module:
Placeholder | Correct Value |
---|---|
<language tag> |
The language tag for the translation. IETF language tag recommended. |
<language name> |
The name of the language in English for debug log messages. |
<your module name> |
The name of your module's directory. |
Venea.net has an excellent resource for IETF language tags.
Default | Localized |
---|---|
![]() |
![]() |
Copy the following code into the console (open with the F12 key) and press Enter:
JSON.stringify(
Object.keys(CONFIG.JournalEntry.noteIcons)
.reduce((o, key) => ({ ...o, [key]: key }), {}),
null, 2);
Copy the printed JSON string into a new .json
file at <path to your module>/lang/<language tag>_icons.json
and translate the strings. The file should be formatted as such (only two keys shown as a sample):
{
"Anchor": "Ankkuri",
"Barrel": "Tynnyri",
}
<path to your module>/scripts/<language tag>.js
.) If you do have such a file, create one now.
Replace the 3 <placeholder> texts at the start with the correct values!
const lang_tag = "<language tag>";
const lang_name = "<language name>";
const module_path = "/modules/<your module name>/";
const LocalizeNoteIcons = function(note_icons_translation_path) {
"use strict";
fetch(note_icons_translation_path)
.then(response => {
if (response.ok) {
return response.json();
}
console.error(`${lang_tag} | Failed to load Note Icons ${lang_name} localization: [${response.status}] ${response.statusText}`);
return null;
})
.then(localized_names => {
let localized_note_icons = {};
for (let source_icon_name in CONFIG.JournalEntry.noteIcons) {
if (CONFIG.JournalEntry.noteIcons.hasOwnProperty(source_icon_name)) {
// Default to unlocalized icon name to ensure newly added unlocalized icons are not skipped.
let icon_name = source_icon_name;
if (localized_names.hasOwnProperty(source_icon_name)) {
icon_name = localized_names[source_icon_name];
} else {
console.warn(`${lang_tag} | Missing localization for icon name "${source_icon_name}".`);
}
localized_note_icons[icon_name] = CONFIG.JournalEntry.noteIcons[source_icon_name];
}
}
// Sort icons according to the localized names.
CONFIG.JournalEntry.noteIcons = Object.keys(localized_note_icons)
.sort()
.reduce((acc, key) => {
acc[key] = localized_note_icons[key];
return acc;
}, {});
console.log(`${lang_tag} | Loaded ${lang_name} localization: Note Icons`);
});
};
Hooks.once("ready", () => {
"use strict";
// Only localize if the user has selected this language.
if (lang_tag === game.settings.get("core", "language")) {
LocalizeNoteIcons(`${module_path}/lang/${lang_tag}_icons.json`);
}
});
ready
hook in your script, only copy the LocalizeNoteIcons
function and add a call to it in your ready
hook:LocalizeNoteIcons("<path to note icons translation JSON>");
.js
file in step 1, add the following code into your module.json at <path to your module>/module.json
.
Replace the <placeholder> text with the correct value!
"esmodules": [
"scripts/<language tag>.js"
],
¶ Console
fi-FI | Loaded map note icons Finnish localization.