From 9688136a7c989900e1d64371e6d2f502542742fc Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Tue, 31 Mar 2020 12:25:27 +0200 Subject: [PATCH] Auto-translate trappings --- babele-register.js | 29 +++++++++++++++++++++++++++++ compendium/wfrp4e.careers.json | 6 +++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/babele-register.js b/babele-register.js index cba5ded..0a87e77 100644 --- a/babele-register.js +++ b/babele-register.js @@ -69,6 +69,35 @@ Hooks.once('init', () => { } return talents_list; }, + "career_trappings": (trappings_list) => { + var compendium = game.packs.find(p => p.collection === 'wfrp4e.trappings'); + var i; + var len = trappings_list.length; + var re = /(.*)\((.*)\)/i; + for (i = 0; i < len; i++) { + var transl = compendium.i18nName( trappings_list[i] ); + if ( transl == trappings_list[i] ) { + var res = re.exec( trappings_list[i]); + if (res) { + //console.log("Matched/split:", res[1], res[2]); + var subword = game.i18n.localize(res[2].trim() ); + var s1 = res[1].trim() + " ()"; + var translw = compendium.i18nName( s1 ); + if (translw != transl) { + var res2 = re.exec(translw); + transl = res2[1] + "(" + subword + ")"; + } else { + s1 = res[1].trim() + " ( )"; + translw = compendium.i18nName( s1 ); + var res2 = re.exec(translw); + transl = res2[1] + "(" + subword + ")"; + } + } + } + trappings_list[i] = transl; + } + return trappings_list; + }, // To avoid duplicateing class for all careers "career_class": (value) => { return game.i18n.localize( value.trim() ); diff --git a/compendium/wfrp4e.careers.json b/compendium/wfrp4e.careers.json index c4a7e97..fde8a20 100644 --- a/compendium/wfrp4e.careers.json +++ b/compendium/wfrp4e.careers.json @@ -16,7 +16,11 @@ "careergroup": { "path": "data.careergroup.value", "converter": "career_careergroup" - } + }, + "trappings": { + "path": "data.trappings", + "converter": "career_trappings" + } }, "entries": [ {