11---
2+ import { getCurrentLocale , getUiTranslator } from " @/src/i18n/utils" ;
23import type { ComponentProps } from " astro/types" ;
34import { Image } from " astro:assets" ;
45type Props = ComponentProps <typeof Image > & {
56 /** Defaults to 'photo' aspect ratio */
67 aspectRatio? : " photo" | " square" | " none" ;
78 caption? : string ;
89 containerClass? : string ;
10+ visibleAltTextClass? : string ;
911};
1012const { props } = Astro ;
13+
14+ const currentLocale = getCurrentLocale (Astro .url .pathname );
15+ const t = await getUiTranslator (currentLocale );
16+ const noAltText = t (" No alt text" );
1117---
1218
1319<div class ={ props .containerClass || " relative w-fit h-fit" } >
@@ -16,19 +22,28 @@ const { props } = Astro;
1622 <Image
1723 {... props }
1824 class =" "
19- class:list ={ (props .class ,
20- {
21- " object-cover" : props .aspectRatio !== " none" ,
22- " aspect-square" : props .aspectRatio === " square" ,
23- " aspect-photo" :
24- props .aspectRatio === " photo" || props .aspectRatio === undefined ,
25- })}
25+ class:list ={ [
26+ props .class ,
27+ {
28+ " object-cover" : props .aspectRatio !== " none" ,
29+ " aspect-square" : props .aspectRatio === " square" ,
30+ " aspect-photo" :
31+ props .aspectRatio === " photo" || props .aspectRatio === undefined ,
32+ },
33+ ]}
2634 />
2735 <p
2836 aria-hidden
29- class =" renderable-alt bg-bg-gray-40 line-clamp-3 absolute top-0 mt-sm mx-sm px-[7.5px] pb-[2.5px] rounded-xl text-body-caption text-ellipsis"
37+ class:list ={ [
38+ " renderable-alt" ,
39+ " text-body-caption" ,
40+ " bg-bg-gray-40 line-clamp-3 absolute top-0 mt-sm mx-sm px-[7.5px] pb-[2.5px] rounded-xl text-ellipsis" ,
41+ props .visibleAltTextClass ,
42+ ]}
3043 >
31- { props .alt }
44+ <!-- It shouldn't be possible to pass no alt text, but if its missing
45+ show a '?' so the component doesn't look broken -->
46+ { props .alt || noAltText }
3247 </p >
3348 { props .caption && <p class = " text-body-caption mt-xs" >{ props .caption } </p >}
3449</div >
0 commit comments