import { join } from 'path' ; import { omit , zipObject } from 'lodash' ; import { directories } from './directories' ; import { get } from './get' ; const ignore = [ 'Recipes' , 'Achievements' , 'Variants' , 'Patterns' ] ; const uniqueValues = [ 'variantId' , 'id' , 'furnitureName' , 'internalIds' , 'sourceSheet' , 'version' , 'clothName' , 'clothGroup' , 'plural' , ] ; const translations = get ( join ( directories . sanitized , 'Translations.json' ) ) . filter ( ( translation ) => ! translation . plural || ! ignore . includes ( translation . sourceSheet ) ) ; param name param sheets return export function find ( name , sheets ? ) { const translation = translations . find ( ( translation ) => { if ( translation . uSen === null ) { return false ; } if ( translation . uSen . toString ( ) . toLowerCase ( ) !== name . toLowerCase ( ) ) { return false ; } const source = translation . sourceSheet ; if ( sheets && ( typeof sheets === 'string' ? source . includes ( sheets ) : sheets . includes ( source ) ) ) { return true ; } else if ( sheets ) return false ; return true ; } ) ; return translation ?? null ; } param item export function translate ( item ) { const id = item . npcId ?? item . craftedItemInternalId ?? item . clothGroupId ?? item . internalId ?? item . filename ; const options = translations . filter ( ( translation ) => ( translation . clothGroup ?? translation . id ) == id ) ; const identical = options . every ( ( translation ) => translation . uSen === options [ 0 ] . uSen ) ; let translation = options . find ( ( translation ) => { if ( ignore . every ( ( tab ) => translation . sourceSheet . includes ( tab ) ) ) { return ; } return identical ? true : translation . uSen . toString ( ) . toLowerCase ( ) === ( item . name ?? item . event ) ?. toLowerCase ( ) ; } ) ; if ( item . sourceSheet === 'Villagers' ) { translation = options . find ( ( translation ) => translation . sourceSheet === 'Villagers' ) ; item . catchphrases = options . find ( ( translation ) => translation . sourceSheet === 'Villager Catchphrases' ) ?? null ; } if ( item . variation ) { item . variantTranslations = options . find ( ( translation ) => translation . uSen === item . variation ) ?? null ; if ( ! item . variantTranslations ) { const translation = find ( String ( item . variation ) , 'Variants' ) ; item . variantTranslations = translation ? omit ( translation , uniqueValues ) : null ; } } if ( item . pattern ) { item . patternTranslations = options . find ( ( translation ) => translation . uSen === item . pattern ) ?? null ; if ( ! item . patternTranslations ) { const translation = find ( item . pattern ) ; item . patternTranslations = translation ? omit ( translation , uniqueValues ) : null ; } } if ( item . labelThemes ) { const array = item . labelThemes . map ( ( theme ) => find ( theme , [ 'Fashion Themes' ] ) ) ; item . themesTranslations = zipObject ( item . labelThemes , array ) ; } if ( item . hhaSeries ) { item . seriesTranslations = find ( item . hhaSeries , [ 'HHA Themes' ] ) ; } if ( item . sourceSheet === 'Reactions' ) { translation = find ( item . name , [ 'Reactions' ] ) ?? undefined ; } if ( ! translation ) { translation = translations . find ( ( translation ) => translation . uSen === ( item . name ?? item . event ) ) ; } if ( item . sourceSheet === 'Achievements' ) { translation = undefined ; } if ( item . sourceSheet === 'Artwork' ) { translation = options . find ( ( translation ) => translation . sourceSheet === 'Art' ) ; } item . translations = translation ?? null ; }