Files
DeltaGreen/module/other/utility-functions.js
T
2023-07-29 10:31:59 -07:00

24 lines
828 B
JavaScript

// Attempt to localize a keyword, and gracefully fallback to something else if the key does not exist.
// This way people using incomplete translations will not as many crashes or bugs when playing against a newly updated system.
export function localizeWithFallback(key, fallback){
try{
let translatedValue = game.i18n.localize(key);
if(translatedValue != key){
return translatedValue;
}
else{
console.warn(`Untranslated localization key '${key}'.`);
// can't have single quotes in a handlebars string literal input, so sort of hack in an escape character for them.
fallback = fallback.replace("'", "'");
return fallback;
}
}
catch(ex){
console.warn(ex);
return fallback;
}
}