2020-11-08 00:22:04 +01:00
/************************************************************************************/
2024-05-17 01:07:37 +02:00
import loadScripts from "./loadScripts.js" ;
2020-11-08 23:12:52 +01:00
import statParserFR from "./modules/import-stat-2.js" ;
2020-11-08 00:22:04 +01:00
2020-06-29 08:12:31 +02:00
/************************************************************************************/
2022-09-12 20:42:19 +02:00
var compmod = "wfrp4e-core" ;
2023-01-15 10:10:26 +01:00
const vo _conditions = {
"ablaze" : "Ablaze" ,
"bleeding" : "Bleeding" ,
"blinded" : "Blinded" ,
"broken" : "Broken" ,
"deafened" : "Deafened" ,
"entangled" : "Entangled" ,
"fatigued" : "Fatigued" ,
"poisoned" : "Poisoned" ,
"prone" : "Prone" ,
"stunned" : "Stunned" ,
"surprised" : "Surprised" ,
"unconscious" : "Unconscious" ,
"grappling" : "Grappling" ,
"fear" : "Fear" ,
"defeated" : "Defeated"
2020-11-13 14:52:23 +01:00
}
2020-06-03 18:30:03 +02:00
2024-05-12 17:39:03 +02:00
const _ _SELECT _BONUS _PREFIX _D = {
2024-05-12 20:50:22 +02:00
"initiative" : 1 ,
"intelligence" : 1 ,
"endurance" : 1 ,
2024-05-12 17:39:03 +02:00
"agilite" : 1 ,
"agilité" : 1
}
2023-01-15 10:10:26 +01:00
2024-05-12 20:50:22 +02:00
/************************************************************************************/
export class WFRP4FrTranslation {
static parseSpellContent ( spell ) {
if ( spell . system . range ? . value ) {
spell . system . range . value = this . processSpellContent ( spell . system . range . value )
}
if ( spell . system . damage ? . value ) {
spell . system . damage . value = this . processSpellContent ( spell . system . damage . value )
}
if ( spell . system . duration ? . value ) {
spell . system . duration . value = this . processSpellContent ( spell . system . duration ? . value )
}
if ( spell . system . range ? . value ) {
spell . system . range . value = this . processSpellContent ( spell . system . range ? . value )
}
if ( spell . system . target ? . value ) {
spell . system . target . value = this . processSpellContent ( spell . system . target ? . value )
}
}
static processSpellContent ( value ) {
//console.log("Spell duration/range/damage/target :", value);
if ( value == "" ) return "" ; // Hop !
if ( value == "Touch" ) return "Contact" ; // Hop !
if ( value == "You" ) return "Vous" ; // Hop !
if ( value == "Instant" ) return "Instantané" ; // Hop !
let translw = value ;
let re = /(.*)\s+[Bb]onus\s*(\w*)/i ;
let res = re . exec ( value ) ;
//console.log("RES1:", res);
let unit = "" ;
if ( res ) { // Test "<charac> Bonus <unit>" pattern
if ( res [ 1 ] ) { // We have char name, then convert it
translw = game . i18n . localize ( res [ 1 ] . trim ( ) ) ;
let bonusPrefix = ( translw . toLowerCase ( ) in _ _SELECT _BONUS _PREFIX _D ) ? "Bonus d'" : "Bonus de " ;
translw = bonusPrefix + translw
}
unit = res [ 2 ] ;
} else {
re = /(\d+) (\w+)/i ;
res = re . exec ( value ) ;
if ( res ) { // Test : "<number> <unit>" pattern
translw = res [ 1 ] ;
unit = res [ 2 ] ;
} else { // Test
re = /(\w+) (\w+)/i ;
res = re . exec ( value ) ;
if ( res ) { // Test : "<charac> <unit>" pattern
translw = game . i18n . localize ( res [ 1 ] . trim ( ) ) ;
unit = res [ 2 ] ;
}
}
}
if ( unit == "hour" ) unit = "heure" ;
if ( unit == "hours" ) unit = "heures" ;
if ( unit == "days" ) unit = "jours" ;
if ( unit == "yard" ) unit = "mètre" ;
if ( unit == "yards" ) unit = "mètres" ;
if ( unit == "Bonus" ) { // Another weird management
console . log ( "Translating bonus" , unit ) ;
translw = "Bonus de " + translw ;
} else {
translw += " " + unit ;
}
return translw ;
}
}
2020-04-26 18:38:43 +02:00
/************************************************************************************/
2020-03-25 20:37:09 +01:00
Hooks . once ( 'init' , ( ) => {
2020-04-26 18:38:43 +02:00
2020-07-03 11:38:38 +02:00
// Check various settings in the installation
2022-09-12 21:05:44 +02:00
game . modules . forEach ( ( module , id ) => {
2023-01-15 10:10:26 +01:00
if ( id == "wfrp4e-core" && module . active ) {
2020-11-05 21:53:12 +01:00
compmod = "wfrp4e-core" ;
}
2023-01-15 10:10:26 +01:00
} ) ;
game . wfrp4efr = {
compmod : compmod ,
vo _conditions : vo _conditions
}
game . wfrp4e . apps . StatBlockParser . parseStatBlock = async function ( statString , type = "npc" ) {
2024-05-12 17:39:03 +02:00
console . log ( "PARSER FR DONE" ) ;
2023-01-15 10:10:26 +01:00
return statParserFR ( statString , type ) ;
}
2024-05-17 01:07:37 +02:00
loadScripts ( ) ;
2023-01-15 10:10:26 +01:00
2020-11-13 14:52:23 +01:00
/*---------------------------------------------------------------------*/
2023-10-14 11:28:48 +02:00
/ * D E P R E C A T E D : g a m e . w f r p 4 e . e n t i t i e s . I t e m W f r p 4 e . p r o t o t y p e . c o m p u t e S p e l l D a m a g e = f u n c t i o n ( f o r m u l a , i s M a g i c M i s s i l e ) {
2021-07-25 10:05:59 +02:00
try {
2020-11-13 14:52:23 +01:00
2020-11-07 13:46:15 +01:00
formula = formula . toLowerCase ( ) ;
2020-11-13 14:52:23 +01:00
2020-11-07 13:46:15 +01:00
if ( isMagicMissile ) // If it's a magic missile, damage includes willpower bonus
{
2021-07-25 10:05:59 +02:00
formula += "+ " + this . actor . characteristics [ "wp" ] . bonus
2020-11-07 13:46:15 +01:00
}
2021-07-25 10:05:59 +02:00
2021-02-06 21:50:08 +01:00
// Specific case, to avoid wrong matching with "Force"
2023-01-15 10:10:26 +01:00
if ( formula . includes ( "toughness bonus" ) ) {
formula = formula . replace ( "toughness bonus" , this . actor . characteristics [ "t" ] . bonus ) ;
2021-02-06 21:50:08 +01:00
}
2021-07-25 10:05:59 +02:00
2020-11-07 13:46:15 +01:00
// Specific case, to avoid wrong matching with "Force"
2023-01-15 10:10:26 +01:00
if ( formula . includes ( "force mentale" ) ) {
2020-11-07 13:46:15 +01:00
// Determine if it's looking for the bonus or the value
if ( formula . includes ( 'bonus' ) ) {
2023-01-15 10:10:26 +01:00
formula = formula . replace ( "bonus de force mentale" , this . actor . characteristics [ "wp" ] . bonus ) ;
formula = formula . replace ( "force mentale bonus" , this . actor . characteristics [ "wp" ] . bonus ) ;
2020-11-07 13:46:15 +01:00
} else
2023-01-15 10:10:26 +01:00
formula = formula . replace ( "force mentale" , this . actor . characteristics [ "wp" ] . value ) ;
2020-11-07 13:46:15 +01:00
}
2021-07-25 10:05:59 +02:00
2020-11-07 13:46:15 +01:00
// Iterate through characteristics
2023-01-15 10:10:26 +01:00
for ( let ch in this . actor . characteristics ) {
2020-11-07 13:46:15 +01:00
// If formula includes characteristic name
2023-01-15 10:10:26 +01:00
while ( formula . includes ( this . actor . characteristics [ ch ] . label . toLowerCase ( ) ) ) {
2020-11-07 13:46:15 +01:00
// Determine if it's looking for the bonus or the value
if ( formula . includes ( 'bonus' ) ) {
2023-01-15 10:10:26 +01:00
formula = formula . replace ( "bonus de " + game . wfrp4e . config . characteristics [ ch ] . toLowerCase ( ) , this . actor . characteristics [ ch ] . bonus ) ;
formula = formula . replace ( game . wfrp4e . config . characteristics [ ch ] . toLowerCase ( ) + " bonus" , this . actor . characteristics [ ch ] . bonus ) ;
2020-11-07 13:46:15 +01:00
}
else
2023-01-15 10:10:26 +01:00
formula = formula . replace ( game . wfrp4e . config . characteristics [ ch ] . toLowerCase ( ) , this . actor . characteristics [ ch ] . value ) ;
2020-11-07 13:46:15 +01:00
}
}
2021-07-25 10:05:59 +02:00
return eval ( formula ) ;
}
catch ( e ) {
throw ui . notifications . error ( "Error: could not parse spell damage. See console for details" )
}
2023-10-14 11:28:48 +02:00
} * /
2020-11-13 14:52:23 +01:00
/*---------------------------------------------------------------------*/
2023-10-14 11:28:48 +02:00
/ * D E P R E C A T E D : g a m e . w f r p 4 e . e n t i t i e s . I t e m W f r p 4 e . p r o t o t y p e . c o m p u t e S p e l l P r a y e r F o r m u l a = f u n c t i o n ( t y p e , a o e = f a l s e , f o r m u l a O v e r r i d e ) {
2021-07-25 10:05:59 +02:00
let formula = formulaOverride || this [ type ] ? . value
if ( Number . isNumeric ( formula ) )
return formula
2020-11-07 13:46:15 +01:00
//console.log("Compute FR")
formula = formula . toLowerCase ( ) ;
// Do not process these special values
2023-01-15 10:10:26 +01:00
if ( formula != game . i18n . localize ( "You" ) . toLowerCase ( ) && formula != game . i18n . localize ( "Special" ) . toLowerCase ( ) && formula != game . i18n . localize ( "Instant" ) . toLowerCase ( ) ) {
2020-11-07 13:46:15 +01:00
// Specific case, to avoid wrong matching with "Force"
2023-01-15 10:10:26 +01:00
if ( formula . includes ( "force mentale" ) ) {
2020-11-07 13:46:15 +01:00
// Determine if it's looking for the bonus or the value
if ( formula . includes ( 'bonus' ) ) {
2023-01-15 10:10:26 +01:00
formula = formula . replace ( "bonus de force mentale" , this . actor . characteristics [ "wp" ] . bonus ) ;
formula = formula . replace ( "force mentale bonus" , this . actor . characteristics [ "wp" ] . bonus ) ;
2020-11-07 13:46:15 +01:00
}
else
2023-01-15 10:10:26 +01:00
formula = formula . replace ( "force mentale" , this . actor . characteristics [ "wp" ] . value ) ;
2020-11-07 13:46:15 +01:00
}
2023-01-15 10:10:26 +01:00
if ( formula . includes ( "yard" ) )
formula = formula . replace ( 'yard' , "mètre" ) ;
if ( formula . includes ( "yds" ) )
formula = formula . replace ( 'yds' , "m." ) ;
2020-11-07 13:46:15 +01:00
// Iterate through remaining characteristics
2023-01-15 10:10:26 +01:00
for ( let ch in this . actor . characteristics ) {
2020-11-07 13:46:15 +01:00
// If formula includes characteristic name
//console.log("Testing :", ch, WFRP4E.characteristics[ch].toLowerCase());
2023-01-15 10:10:26 +01:00
if ( formula . includes ( game . wfrp4e . config . characteristics [ ch ] . toLowerCase ( ) ) ) {
2020-11-07 13:46:15 +01:00
// Determine if it's looking for the bonus or the value
if ( formula . includes ( 'bonus' ) ) {
2023-01-15 10:10:26 +01:00
formula = formula . replace ( "bonus de " + game . wfrp4e . config . characteristics [ ch ] . toLowerCase ( ) , this . actor . characteristics [ ch ] . bonus ) ;
formula = formula . replace ( game . wfrp4e . config . characteristics [ ch ] . toLowerCase ( ) + " bonus" , this . actor . characteristics [ ch ] . bonus ) ;
2020-11-07 13:46:15 +01:00
}
else
2023-01-15 10:10:26 +01:00
formula = formula . replace ( game . wfrp4e . config . characteristics [ ch ] . toLowerCase ( ) , this . actor . characteristics [ ch ] . value ) ;
2020-11-07 13:46:15 +01:00
}
}
}
// If AoE - wrap with AoE ( )
if ( aoe )
formula = "AoE (" + formula . capitalize ( ) + ")" ;
2023-01-15 10:10:26 +01:00
2021-02-06 21:50:08 +01:00
//console.log("calculateSpellAttributes -> " + formula );
2020-11-07 13:46:15 +01:00
return formula . capitalize ( ) ;
2023-10-14 11:28:48 +02:00
} * /
2020-11-07 13:46:15 +01:00
2020-11-13 14:52:23 +01:00
/*---------------------------------------------------------------------*/
// Converters area
2023-01-15 10:10:26 +01:00
if ( typeof Babele !== 'undefined' ) {
Babele . get ( ) . register ( {
module : 'wh4-fr-translation' ,
lang : 'fr' ,
dir : 'compendium'
} )
2020-03-30 23:23:21 +02:00
Babele . get ( ) . registerConverters ( {
2021-06-29 09:57:36 +02:00
2020-03-31 09:03:19 +02:00
"career_skills" : ( skills _list ) => {
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "skill" )
//DEBUG: console.log( "Thru here ...", compendium, skills_list);
2023-01-15 10:10:26 +01:00
if ( skills _list ) {
2023-09-01 13:30:43 +02:00
let i ;
let len = skills _list . length ;
let re = /(.*)\((.*)\)/i ;
2020-05-05 09:21:03 +02:00
for ( i = 0 ; i < len ; i ++ ) {
2021-04-29 09:01:22 +02:00
skills _list [ i ] = skills _list [ i ] . trim ( ) ;
2023-09-24 22:47:50 +02:00
for ( let compData of validCompendiums ) {
2023-10-03 10:48:42 +02:00
let translItem = game . babele . translate ( compData . metadata . id , { name : skills _list [ i ] , type : "skill" } , true )
let transl = translItem ? . name || undefined
2023-09-24 22:47:50 +02:00
if ( ! transl ) transl = skills _list [ i ]
2023-10-03 11:43:31 +02:00
//console.log("List ...", skills_list[i], compData.metadata.id, translItem);
2023-09-24 22:47:50 +02:00
if ( transl == skills _list [ i ] ) {
let res = re . exec ( skills _list [ i ] ) ;
if ( res ) {
//console.log("Matched/split:", res[1], res[2]);
let subword = game . i18n . localize ( res [ 2 ] . trim ( ) ) ;
let s1 = res [ 1 ] . trim ( ) + " ()" ;
2023-10-03 10:48:42 +02:00
translItem = game . babele . translate ( compData . metadata . id , { name : s1 , type : "skill" } , true )
let translw = translItem ? . name || undefined
2023-10-03 11:43:31 +02:00
if ( translw && translw != s1 ) {
2023-09-24 22:47:50 +02:00
let res2 = re . exec ( translw ) ;
transl = res2 [ 1 ] + "(" + subword + ")" ;
} else {
s1 = res [ 1 ] . trim ( ) + " ( )" ;
2023-10-03 10:48:42 +02:00
translItem = game . babele . translate ( compData . metadata . id , { name : s1 , type : "skill" } , true )
translw = translItem ? . name || undefined
2023-09-24 22:47:50 +02:00
let res2 = re . exec ( translw ) ;
transl = res2 [ 1 ] + "(" + subword + ")" ;
}
2023-01-15 10:10:26 +01:00
}
2020-05-05 09:21:03 +02:00
}
2023-09-24 22:47:50 +02:00
skills _list [ i ] = transl ;
2023-10-03 10:48:42 +02:00
if ( translItem ? . system )
2023-09-24 22:47:50 +02:00
break ;
2020-03-30 23:23:21 +02:00
}
}
}
2023-01-15 10:10:26 +01:00
return skills _list ;
2020-03-30 23:23:21 +02:00
} ,
2023-01-15 10:10:26 +01:00
2022-10-21 18:24:39 +02:00
"resultConverter" : ( results , translated ) => {
2022-11-16 20:57:41 +01:00
//console.log("STUF PARSING", results, translated)
2022-10-21 18:24:39 +02:00
if ( translated ) {
for ( let data of results ) {
2023-01-15 10:10:26 +01:00
if ( translated [ ` ${ data . range [ 0 ] } - ${ data . range [ 1 ] } ` ] ) {
2022-10-21 18:24:39 +02:00
data . text = translated [ ` ${ data . range [ 0 ] } - ${ data . range [ 1 ] } ` ]
}
}
return results
}
2023-02-28 21:13:36 +01:00
// Auto patch
2023-09-16 15:27:37 +02:00
if ( results [ 0 ] . text . includes ( "wfrp4e-core.career-descriptions" ) ) {
2023-09-01 13:30:43 +02:00
if ( game . system . version . match ( "7." ) ) {
results [ 0 ] . text = "wfrp4e-core.journals"
} else {
2023-09-16 15:27:37 +02:00
results [ 0 ] . text = "wfrp4e-core.journal-entries"
2023-09-01 13:30:43 +02:00
}
2023-09-16 15:27:37 +02:00
}
2023-09-01 13:30:43 +02:00
if ( results [ 0 ] . text . includes ( "wfrp4e-core.journal" ) ) {
2022-10-21 18:24:39 +02:00
for ( let data of results ) {
let career = data . text . match ( /{(.*)}/ )
2022-11-16 20:57:41 +01:00
//console.log(">>>>>", career)
2022-10-21 18:24:39 +02:00
if ( career && career [ 1 ] ) {
let careerFR = Babele . instance . converters . career _careergroup ( career [ 1 ] )
data . text = data . text . replace ( career [ 1 ] , careerFR )
}
}
}
2023-01-15 10:10:26 +01:00
if ( results [ 0 ] . documentCollection ) {
2022-10-21 18:24:39 +02:00
return Babele . instance . converters . tableResults ( results )
}
return results
} ,
2020-11-10 15:01:06 +01:00
"npc_details" : ( details ) => {
//console.log("DETAILS: ", details);
let newDetails = duplicate ( details ) ;
2023-09-01 13:30:43 +02:00
if ( details . species ? . value )
2020-11-11 19:08:20 +01:00
newDetails . species . value = game . i18n . localize ( details . species . value ) ;
2023-09-01 13:30:43 +02:00
if ( details . gender ? . value )
2023-01-15 10:10:26 +01:00
newDetails . gender . value = game . i18n . localize ( details . gender . value ) ;
2023-09-01 13:30:43 +02:00
if ( details . class ? . value )
2023-01-15 10:10:26 +01:00
newDetails . class . value = game . i18n . localize ( details . class . value ) ;
2020-11-10 15:01:06 +01:00
return newDetails ;
} ,
2021-06-29 09:57:36 +02:00
2023-01-15 10:10:26 +01:00
"career_talents" : ( talents _list ) => {
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "talent" )
2023-09-01 13:30:43 +02:00
let i ;
2023-01-15 10:10:26 +01:00
if ( talents _list ) {
2023-09-01 13:30:43 +02:00
let len = talents _list . length ;
let re = /(.*)\((.*)\)/i ;
2020-05-05 09:21:03 +02:00
for ( i = 0 ; i < len ; i ++ ) {
2023-09-24 22:47:50 +02:00
for ( let compData of validCompendiums ) {
2024-02-08 12:54:56 +01:00
let translItem = game . babele . translate ( compData . metadata . id , { name : talents _list [ i ] } , true ) ;
2024-02-26 10:04:55 +01:00
//console.log("Search talent name:", compData.metadata.id, talents_list[i], translItem);
2023-10-03 10:48:42 +02:00
let transl = translItem ? . name || undefined
2023-09-24 22:47:50 +02:00
if ( ! transl ) transl = talents _list [ i ]
if ( transl == talents _list [ i ] ) {
let res = re . exec ( talents _list [ i ] ) ;
if ( res ) {
let subword = game . i18n . localize ( res [ 2 ] . trim ( ) ) ;
let s1 = res [ 1 ] . trim ( ) ; // No () in talents table
2024-02-08 12:54:56 +01:00
translItem = game . babele . translate ( compData . metadata . id , { name : s1 } , true )
2023-10-03 10:48:42 +02:00
let translw = translItem ? . name || undefined
2024-04-28 23:09:50 +02:00
console . log ( "Search talent name:" , compData . metadata . id , s1 , translw ) ;
2023-09-28 07:49:24 +02:00
if ( translw && translw != s1 ) {
2023-09-24 22:47:50 +02:00
transl = translw + " (" + subword + ")" ;
2024-05-12 20:50:22 +02:00
}
2023-01-15 10:10:26 +01:00
}
2020-05-05 09:21:03 +02:00
}
2023-09-24 22:47:50 +02:00
talents _list [ i ] = transl ;
2023-10-03 10:48:42 +02:00
if ( translItem ? . system )
2023-09-24 22:47:50 +02:00
break ;
2020-03-30 23:23:21 +02:00
}
}
}
2023-01-15 10:10:26 +01:00
return talents _list ;
2020-03-31 09:27:04 +02:00
} ,
2020-04-23 11:52:39 +02:00
"npc_characteristics" : ( chars ) => { // Auto-convert char names in the sheet
2023-09-01 13:30:43 +02:00
for ( let key in chars ) {
let char = chars [ key ] ;
2020-06-03 18:30:03 +02:00
//console.log("Was here !", key, char );
2023-09-01 13:30:43 +02:00
let abrev = char [ "abrev" ] ;
2020-06-06 13:27:59 +02:00
let toTransl = "CHAR." + abrev ;
2023-01-15 10:10:26 +01:00
if ( game . i18n . localize ( toTransl ) != toTransl ) { // Manages unknown language
char [ "label" ] = game . i18n . localize ( "CHAR." + abrev ) ;
char [ "abrev" ] = game . i18n . localize ( "CHARAbbrev." + abrev ) ;
2020-06-06 13:27:59 +02:00
}
2020-04-23 11:52:39 +02:00
}
return chars ;
} ,
2023-01-15 10:10:26 +01:00
"bestiary_traits" : ( beast _traits , translations ) => {
if ( ! beast _traits ) {
2022-10-02 19:17:50 +02:00
console . log ( "No beast traits found here ..." )
return beast _traits
}
2023-09-11 06:43:56 +02:00
//console.log("TRANS:", beast_traits)
2023-01-15 10:10:26 +01:00
for ( let trait _en of beast _traits ) {
2023-09-01 13:30:43 +02:00
let special = "" ;
let nbt = "" ;
let name _en = trait _en . name . trim ( ) ; // strip \r in some traits name
2022-10-03 12:14:34 +02:00
if ( ! trait _en . name || trait _en . name . length == 0 ) {
2022-10-02 19:17:50 +02:00
console . log ( "Wrong item name found!!!!" )
continue
2023-01-15 10:10:26 +01:00
}
2022-10-02 19:17:50 +02:00
//console.log(">>>>>>>> Parsing", trait_en.name)
2023-01-15 10:10:26 +01:00
if ( trait _en . type == "trait" ) {
2022-10-02 19:17:50 +02:00
//console.log("Trait translation", compmod, trait_en)
2023-01-15 10:10:26 +01:00
if ( name _en . includes ( "Tentacles" ) ) { // Process specific Tentacles case
2023-09-01 13:30:43 +02:00
let re = /(.d*)x Tentacles/i ;
let res = re . exec ( name _en ) ;
2023-01-15 10:10:26 +01:00
if ( res && res [ 1 ] )
2020-11-08 23:12:52 +01:00
nbt = res [ 1 ] + "x " ;
name _en = "Tentacles" ;
2023-01-15 10:10:26 +01:00
} else if ( name _en . includes ( "(" ) && name _en . includes ( ")" ) ) { // Then process specific traits name with (xxxx) inside
2023-09-01 13:30:43 +02:00
let re = /(.*) \((.*)\)/i ;
let res = re . exec ( name _en ) ;
2020-11-08 23:12:52 +01:00
name _en = res [ 1 ] ; // Get the root traits name
2023-01-15 10:10:26 +01:00
special = " (" + game . i18n . localize ( res [ 2 ] . trim ( ) ) + ")" ; // And the special keyword
2020-11-08 23:12:52 +01:00
}
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "trait" )
for ( let compData of validCompendiums ) {
let trait _fr = game . babele . translate ( compData . metadata . id , { name : name _en } , true )
if ( trait _fr ? . system ) {
trait _fr . name = trait _fr . name || trait _en . name
trait _en . name = nbt + trait _fr . name + special ;
trait _en . system . description . value = trait _fr . system . description . value ;
if ( trait _en . system ? . specification && isNaN ( trait _en . system . specification . value ) ) { // This is a string, so translate it
//console.log("Translating : ", trait_en.system.specification.value);
trait _en . system . specification . value = game . i18n . localize ( trait _en . system . specification . value . trim ( ) ) ;
}
break // Translation has been found, skip other compendiums
2023-09-16 15:27:37 +02:00
}
2023-01-15 10:10:26 +01:00
}
} else if ( trait _en . type == "skill" ) {
if ( name _en . includes ( "(" ) && name _en . includes ( ")" ) ) { // Then process specific skills name with (xxxx) inside
2023-09-01 13:30:43 +02:00
let re = /(.*) +\((.*)\)/i ;
let res = re . exec ( name _en ) ;
2020-11-08 23:12:52 +01:00
name _en = res [ 1 ] . trim ( ) ; // Get the root skill name
2023-01-15 10:10:26 +01:00
special = " (" + game . i18n . localize ( res [ 2 ] . trim ( ) ) + ")" ; // And the special keyword
2020-11-08 23:12:52 +01:00
}
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "skill" )
for ( let compData of validCompendiums ) {
let trait _fr = game . babele . translate ( compData . metadata . id , { name : name _en } , true )
if ( trait _fr ? . system ) {
//console.log(">>>>> Skill ?", name_en, special, trait_fr.name, trait_fr);
trait _fr . name = trait _fr . name || name _en
trait _en . name = trait _fr . name + special ;
2022-09-30 20:56:12 +02:00
trait _en . system . description . value = trait _fr . system . description . value ;
2023-09-24 22:47:50 +02:00
break ; // Translation has been found, skip other compendiums
2020-11-08 23:12:52 +01:00
}
}
2023-01-15 10:10:26 +01:00
} else if ( trait _en . type == "prayer" ) {
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "prayer" )
for ( let compData of validCompendiums ) {
let trait _fr = game . babele . translate ( compData . metadata . id , { name : name _en } , true )
if ( trait _fr ? . system ) {
//DEBUG : console.log(">>>>> Prayer ?", name_en, special, trait_fr.name );
2024-05-12 20:50:22 +02:00
WFRP4FrTranslation . parseSpellContent ( trait _en )
2023-09-24 22:47:50 +02:00
trait _fr . name = trait _fr . name || name _en
trait _en . name = trait _fr . name + special ;
if ( trait _fr . system ? . description ? . value ) {
trait _en . system . description . value = trait _fr . system . description . value ;
}
break ;
}
2023-09-16 15:27:37 +02:00
}
2023-01-15 10:10:26 +01:00
} else if ( trait _en . type == "spell" ) {
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "spell" )
for ( let compData of validCompendiums ) {
let trait _fr = game . babele . translate ( compData . metadata . id , { name : name _en } , true )
2024-05-12 20:50:22 +02:00
if ( trait _fr ? . system ) {
//DEBUG : console.log(">>>>> Spell ?", name_en, special, trait_fr);
WFRP4FrTranslation . parseSpellContent ( trait _en )
2023-09-24 22:47:50 +02:00
trait _fr . name = trait _fr . name || name _en
trait _en . name = trait _fr . name + special ;
if ( trait _fr . system ? . description ? . value ) {
trait _en . system . description . value = trait _fr . system . description . value ;
}
break ;
}
2020-11-08 23:12:52 +01:00
}
2023-09-16 15:27:37 +02:00
} else if ( trait _en . type == "talent" ) {
2023-01-15 10:10:26 +01:00
if ( name _en . includes ( "(" ) && name _en . includes ( ")" ) ) { // Then process specific skills name with (xxxx) inside
2023-09-01 13:30:43 +02:00
let re = /(.*) +\((.*)\)/i ;
let res = re . exec ( name _en ) ;
2020-11-08 23:12:52 +01:00
name _en = res [ 1 ] . trim ( ) ; // Get the root talent name, no parenthesis this time...
2023-01-15 10:10:26 +01:00
special = " (" + game . i18n . localize ( res [ 2 ] . trim ( ) ) + ")" ; // And the special keyword
2020-11-08 23:12:52 +01:00
}
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "talent" )
for ( let compData of validCompendiums ) {
let trait _fr = game . babele . translate ( compData . metadata . id , { name : name _en } , true )
if ( trait _fr ? . system ) {
trait _fr . name = trait _fr . name || name _en // Security since babele v10
//console.log(">>>>> Talent ?", trait_fr, name_en, special, trait_fr.name);
if ( trait _fr . name && ( trait _fr . name == "Sprinter" || trait _fr . name != name _en ) ) { // Talent translated!
trait _en . name = trait _fr . name . trim ( ) + special
if ( trait _fr . system ? . description ? . value ) { // Why ???
trait _en . system . description . value = trait _fr . system . description . value ;
}
}
break ;
2020-11-08 23:12:52 +01:00
}
}
2023-01-15 10:10:26 +01:00
} else if ( trait _en . type == "career" ) {
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "career" )
for ( let compData of validCompendiums ) {
let career _fr = game . babele . translate ( compData . metadata . id , { name : name _en } , true ) ;
if ( career _fr ? . system ) {
trait _en . name = career _fr . name || trait _en . name
// DEBG: console.log(">>>>> Career ?", career_fr.name );
trait _en . system = duplicate ( career _fr . system ) ;
break ;
}
2023-09-11 06:43:56 +02:00
}
2023-01-15 10:10:26 +01:00
} else if ( trait _en . type == "trapping" || trait _en . type == "weapon" || trait _en . type == "armour" || trait _en . type == "container" || trait _en . type == "money" ) {
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( [ "trapping" ] , [ "weapon" , "armour" , "container" , "money" ] )
for ( let compData of validCompendiums ) {
let trapping _fr = game . babele . translate ( compData . metadata . id , { name : name _en } , true ) ;
if ( trapping _fr ? . system ) {
//console.log(">>>>> Trapping ?", name_en, trapping_fr.name);
trait _en . name = trapping _fr . name || trait _en . name
if ( trapping _fr . system ? . description ? . value ) {
trait _en . system . description . value = trapping _fr . system . description . value
}
break ;
}
2020-11-08 23:12:52 +01:00
}
}
}
2022-10-02 19:17:50 +02:00
//console.log(">>>>>>>><OUTPUT", beast_traits)
return beast _traits
2020-04-21 21:47:05 +02:00
} ,
2020-03-31 09:27:04 +02:00
// To avoid duplicateing class for all careers
2023-01-15 10:10:26 +01:00
"generic_localization" : ( value ) => {
2022-10-03 12:14:34 +02:00
let ret = value
2023-01-15 10:10:26 +01:00
if ( value ) {
ret = game . i18n . localize ( value . trim ( ) ) ;
2022-10-03 12:14:34 +02:00
if ( ! ret ) ret = value
}
return ret
2023-01-15 10:10:26 +01:00
} ,
2020-04-01 00:41:20 +02:00
"trapping_qualities_flaws" : ( value ) => {
2023-01-15 10:10:26 +01:00
if ( value ) {
2021-07-08 13:46:30 +02:00
let newQF = [ ] ;
2022-09-16 09:55:58 +02:00
//console.log("ATOUTS", value, typeof(value));
let list = value
2023-01-15 10:10:26 +01:00
if ( typeof ( value ) == "string" ) {
2022-09-16 09:55:58 +02:00
let myList = value . split ( "," )
list = [ ]
for ( let l of myList ) {
2023-01-15 10:10:26 +01:00
list . push ( { name : l . trim ( ) } )
2022-09-16 09:55:58 +02:00
}
}
2023-01-15 10:10:26 +01:00
for ( let i = 0 ; i < list . length ; i ++ ) {
newQF [ i ] = duplicate ( list [ i ] )
if ( newQF [ i ] . name == "Trap Blade" ) {
2021-07-08 13:46:30 +02:00
newQF [ i ] . name = "TrapBlade" ; // Auto-patch, without space!
2020-06-19 00:26:15 +02:00
//console.log("PATCHED", trim);
2020-04-01 00:41:20 +02:00
}
2022-10-03 12:14:34 +02:00
let oldName = newQF [ i ] . name
2023-01-15 10:10:26 +01:00
newQF [ i ] . name = game . i18n . localize ( oldName )
2022-10-03 12:14:34 +02:00
if ( ! newQF [ i ] . name ) newQF [ i ] . name = oldName
2020-03-31 17:44:46 +02:00
}
2021-07-08 13:46:30 +02:00
return newQF ;
2020-03-31 17:44:46 +02:00
}
} ,
2020-03-31 09:27:04 +02:00
// Search back in careers the translated name of the groupe (as it is the name of the level career itself)
2023-01-15 10:10:26 +01:00
"career_careergroup" : ( value ) => {
2020-10-06 08:25:51 +02:00
// Manage exception - Dirty hack
2023-01-15 10:10:26 +01:00
if ( value == 'Slayer' ) {
2021-11-13 11:24:12 +01:00
return "Tueur" ;
2020-07-03 11:38:38 +02:00
}
2023-01-15 10:10:26 +01:00
if ( value == 'Druidic Priest' ) {
2020-10-06 08:25:51 +02:00
return "Druide" ;
}
2023-01-15 10:10:26 +01:00
//console.log("Carre groupe : ", value )
2020-07-03 11:38:38 +02:00
// Per default
2023-09-24 22:47:50 +02:00
let validCompendiums = game . wfrp4e . tags . getPacksWithTag ( "career" )
for ( let compData of validCompendiums ) {
let newName = game . babele . translate ( compData . metadata . id , { name : value } ) . name
2022-10-03 12:14:34 +02:00
if ( ! newName ) newName = value
return newName
}
2023-09-24 22:47:50 +02:00
ui . notifications . error ( "Impossible de trouver la carrière " + value + ". Elle n'est probablement pas traduite." , { permanent : true } )
2022-10-21 18:24:39 +02:00
return value
2020-04-10 15:11:26 +02:00
} ,
2022-10-21 18:24:39 +02:00
2020-06-21 22:28:51 +02:00
"mutations_modifier" : ( value ) => { // This is really UGLYYYY i know, but i started like this and discovered afterward that many strings were not easy to automate... Sorry :)
2020-06-14 21:22:07 +02:00
//console.log("Parsing mutation :", value);
2023-01-15 10:10:26 +01:00
value = value . toLowerCase ( ) ;
2020-06-21 22:28:51 +02:00
value = value . replace ( "gain a broken condition if you fail a test derived from " , "Gagnez un état Brisé si vous échouez à un test dérivé de " ) ;
2023-01-15 10:10:26 +01:00
value = value . replace ( "weapon skill" , "Capacité de Combat" ) ;
2020-06-13 23:09:11 +02:00
value = value . replace ( "ballistic skill" , "Capacité de Tir" ) ;
value = value . replace ( "strength" , "Force" ) ;
value = value . replace ( "toughness" , "Endurance" ) ;
value = value . replace ( "agility" , "Agilité" ) ;
value = value . replace ( "dexterity" , "Dextérité" ) ;
value = value . replace ( "willpower" , "Force Mentale" ) ;
value = value . replace ( "fellowship" , "Sociabilité" ) ;
value = value . replace ( "initiative" , "Initiative" ) ;
value = value . replace ( "intelligence" , "Intelligence" ) ;
2020-06-21 22:28:51 +02:00
value = value . replace ( "armor points to the head" , "PA à la Tête" ) ;
value = value . replace ( "subject to frenzy" , "Sujet à la Frénésie" ) ;
value = value . replace ( "you do not scar" , "Aucune cicatrice" ) ;
value = value . replace ( "movement" , "Mouvement" ) ;
value = value . replace ( "armor points to all locations" , "PA sur tout le corps" ) ;
value = value . replace ( "to any test when alone" , "à tout les tests lorsque seul" ) ;
value = value . replace ( "track" , "Pistage" ) ;
value = value . replace ( "to any test not hurting another" , "à tout les Tests n'aggressant pas autrui" ) ;
value = value . replace ( "on tests to hurt" , "pour les tests impliquant une agression" )
value = value . replace ( "to all language tests when speaking" , "à tout les Tests de Langue lorsque vous parlez" ) ;
value = value . replace ( "on perception tests involving sight" , "aux Tests de Perception impliquant la Vue" ) ;
value = value . replace ( "to all Sociabilité tests" , "à tout les Tests de Sociabilité" ) ;
2020-06-13 23:09:11 +02:00
return value ;
} ,
2021-02-06 21:50:08 +01:00
"talent_name" : ( name , translation ) => {
2022-10-03 12:14:34 +02:00
console . log ( "NAME !!!" , name , translation )
2021-02-06 21:50:08 +01:00
} ,
2023-01-15 10:10:26 +01:00
"effects" : ( effects , translations ) => {
if ( ! effects ) return ;
if ( ! translations ) return ;
for ( let i = 0 ; i < effects . length ; i ++ ) {
2021-02-06 21:50:08 +01:00
let effect = effects [ i ] ;
2021-05-06 21:51:06 +02:00
//console.log("EFFECT LABEL1:", effect );
2023-01-15 10:10:26 +01:00
effect . label = translations [ 'label' + i ] ;
2021-02-06 21:50:08 +01:00
}
return effects
} ,
2023-01-15 10:10:26 +01:00
"diseases_effects" : ( effects , translations ) => {
if ( ! effects ) return ;
for ( let i = 0 ; i < effects . length ; i ++ ) {
2021-02-06 21:50:08 +01:00
let effect = effects [ i ] ;
let label = effect . label ;
let gravity = "" ;
2023-01-15 10:10:26 +01:00
if ( label . includes ( "(" ) && label . includes ( ")" ) ) { // Then process specific skills name with (xxxx) inside
2023-09-01 13:30:43 +02:00
let re = /(.*) +\((.*)\)/i ;
let res = re . exec ( label ) ;
2021-02-06 21:50:08 +01:00
label = res [ 1 ] . trim ( ) ; // Get the gravity
2023-01-15 10:10:26 +01:00
gravity = " (" + game . i18n . localize ( res [ 2 ] . trim ( ) ) + ")" ; // And the special keyword
2021-02-06 21:50:08 +01:00
}
2023-01-15 10:10:26 +01:00
effect . label = game . i18n . localize ( label ) + gravity ;
2021-02-06 21:50:08 +01:00
}
} ,
2020-04-10 15:11:26 +02:00
// Auto-translate duration
"spells_duration_range_target_damage" : ( value ) => {
2024-05-12 20:50:22 +02:00
return WFRP4FrTranslation . processSpellContent ( value ) ;
2020-03-31 17:44:46 +02:00
}
2024-05-12 20:50:22 +02:00
} ) ;
2020-03-27 23:12:43 +01:00
}
2023-01-15 10:10:26 +01:00
} ) ;
2020-04-12 08:59:47 +02:00
2022-01-30 09:18:49 +01:00
/*---------------------------------------------------------------------*/
Hooks . once ( 'ready' , ( ) => {
2023-09-16 15:27:37 +02:00
2024-05-12 20:50:22 +02:00
import ( " https : //www.uberwald.me/fvtt_appcount/count-class-ready.js").then(moduleCounter => {
2024-02-26 10:04:55 +01:00
console . log ( "ClassCounter loaded" , moduleCounter )
2024-02-26 09:58:36 +01:00
moduleCounter . ClassCounter . registerUsageCount ( "wh4-fr-translation" )
2024-05-12 20:50:22 +02:00
} ) . catch ( err =>
2024-02-26 09:58:36 +01:00
console . log ( "No stats available, giving up." )
)
2023-05-25 14:55:31 +02:00
2022-01-30 09:18:49 +01:00
} ) ;