Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add alt text to tool images #1337

Merged
merged 6 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/localization/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
"img": {
"height": "140",
"width": "250",
"src": "tools/kobotoolbox-screenshot.png"
"src": "tools/kobotoolbox-screenshot.png",
"alt": "A phone, a laptop, and a tablet, each displaying a data collection form. The tool’s logo is in the foreground."
},
"description": [
"Design and build forms quickly",
Expand All @@ -181,7 +182,8 @@
"img": {
"height": "140",
"width": "250",
"src": "tools/landscale-screenshot.png"
"src": "tools/landscale-screenshot.png",
"alt": "A dashboard containing charts and graphs about a landscape. The tool’s logo is in the foreground."
},
"description": [
"Assess landscape sustainability performance",
Expand All @@ -198,6 +200,7 @@
"height": "188",
"width": "250",
"src": "tools/story-maps.png",
"alt": "A satellite map of a bend in a river, overlayed by a window containing a picture and a block of text.",
"caption": "Rocky Hill’s Story Map"
},
"description": ["Create beautiful map-based stories"],
Expand Down
7 changes: 5 additions & 2 deletions src/localization/locales/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
"img": {
"height": "140",
"width": "250",
"src": "tools/kobotoolbox-screenshot.png"
"src": "tools/kobotoolbox-screenshot.png",
"alt": "Un teléfono, una computadora portátil y una tableta, cada uno de los cuales muestra un formulario de recopilación de datos. El logotipo de la herramienta está en primer plano."
},
"description": [
"Diseñe y cree formularios rápidamente",
Expand All @@ -181,7 +182,8 @@
"img": {
"height": "140",
"width": "250",
"src": "tools/landscale-screenshot.png"
"src": "tools/landscale-screenshot.png",
"alt": "Un panel que contiene cuadros y gráficos sobre un paisaje. El logotipo de la herramienta está en primer plano."
},
"description": [
"Evaluar el desempeño de la sostenibilidad del paisaje",
Expand All @@ -198,6 +200,7 @@
"height": "188",
"width": "250",
"src": "tools/story-maps.png",
"alt": "Un mapa satelital de un recodo de un río, superpuesto por una ventana que contiene una imagen y un bloque de texto.",
"caption": "Story Map de Rocky Hill"
},
"description": ["Crea hermosas historias basadas en mapas"],
Expand Down
92 changes: 41 additions & 51 deletions src/tool/components/ToolCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,43 @@ import theme from 'theme';
const ToolIconAndLink = ({ tool, title, external }) => {
const { t } = useTranslation();
const toolImage = require(`assets/${t(`tools.${tool}.img.src`)}`);
const toolUrl = t(`tools.${tool}.url`);
const toolText = t('tool.go_to', { tool: title });
const toolIcon = (
<Box
component="img"
src={toolImage}
alt={t(`tools.${tool}.img.alt`)}
width={t(`tools.${tool}.img.width`)}
height={t(`tools.${tool}.img.height`)}
sx={{
width: `${t(`tools.${tool}.img.width`)}px`,
height: `${t(`tools.${tool}.img.height`)}px`,
borderRadius: '4px',
border: '1px solid rgba(0, 0, 0, 0.12)',
}}
/>
);
const LinkComponent = external ? ExternalLink : Link;

return (
<React.Fragment>
<Box
component="img"
src={toolImage}
alt=""
width={t(`tools.${tool}.img.width`)}
height={t(`tools.${tool}.img.height`)}
sx={{
width: `${t(`tools.${tool}.img.width`)}px`,
height: `${t(`tools.${tool}.img.height`)}px`,
borderRadius: '4px',
border: '1px solid rgba(0, 0, 0, 0.12)',
}}
/>
<LinkComponent href={toolUrl}>{toolIcon}</LinkComponent>
<p>
{t('tool.go_to', { tool: title })}
{external && (
<LaunchIcon
sx={{
paddingLeft: 1,
height: '1.2rem',
width: '1.2rem',
verticalAlign: 'bottom',
}}
/>
)}
<LinkComponent href={toolUrl}>
{toolText}
{external && (
<LaunchIcon
sx={{
paddingLeft: 1,
height: '1.2rem',
width: '1.2rem',
verticalAlign: 'bottom',
color: theme.palette.link,
}}
/>
)}
</LinkComponent>
</p>
</React.Fragment>
);
Expand All @@ -85,7 +94,8 @@ const ToolCard = ({ tool }) => {
attributes['aria-label'] = pronunciation;
}

const isToolExternal = t(`tools.${tool}.external`) === 'true';
const external = t(`tools.${tool}.external`) === 'true';
const LinkComponent = external ? ExternalLink : Link;

return (
<React.Fragment>
Expand Down Expand Up @@ -125,9 +135,9 @@ const ToolCard = ({ tool }) => {

{learnMoreUrl && (
<Typography sx={{ mt: '1em' }}>
{isToolExternal ? (
<ExternalLink href={learnMoreUrl}>
{t('tool.learn_more', { tool: toolTitle })}
<LinkComponent href={learnMoreUrl}>
{t('tool.learn_more', { tool: toolTitle })}
{external && (
<LaunchIcon
sx={{
paddingLeft: 1,
Expand All @@ -136,34 +146,14 @@ const ToolCard = ({ tool }) => {
verticalAlign: '-0.2rem',
}}
/>
</ExternalLink>
) : (
<Link href={t('tool.learn_more')}>
{t('tool.learn_more', { tool: toolTitle })}
</Link>
)}
)}
</LinkComponent>
</Typography>
)}
</section>

<section>
{isToolExternal ? (
<ExternalLink href={t(`tools.${tool}.url`)}>
<ToolIconAndLink
tool={tool}
title={toolTitle}
external={isToolExternal}
/>
</ExternalLink>
) : (
<Link href={t(`tools.${tool}.url`)}>
<ToolIconAndLink
tool={tool}
title={toolTitle}
external={isToolExternal}
/>
</Link>
)}
<ToolIconAndLink tool={tool} title={toolTitle} external />
</section>
</Stack>
</Card>
Expand Down