All files / app/features/translate TranslationProgress.tsx

86.53% Statements 45/52
50% Branches 22/44
92.3% Functions 12/13
88.88% Lines 40/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 3031x 1x 1x 1x 1x 1x 1x 1x 1x   1x 17x 8x                                                   1x 17x 8x                       1x 1x               1x 8x 4x         1x 8x 6x 2x 4x         8x                 2x 2x 2x   2x   2x                   2x                     2x 8x 6x                                                                         8x 8x 8x 8x   8x                                                                                                                                                                                                                                                                                                  
import TranslateIcon from "@mui/icons-material/Translate";
import { Box, Card, CardContent, Chip, Link, styled, Typography, useMediaQuery } from "@mui/material";
import { useTranslation } from "i18n";
import { getLocaleReadiness, LocaleReadiness } from "i18n/locales";
import { GLOBAL } from "i18n/namespaces";
import { useLocaleInfos } from "i18n/useLocaleInfos";
import React from "react";
import { translateJobURL } from "routes";
import { theme } from "theme";
 
const ProgressBar = styled(Box, {
  shouldForwardProp: (prop) => prop !== "percent" && prop !== "readiness",
})<{ percent: number; readiness: LocaleReadiness }>(({ theme, percent, readiness }) => ({
  width: "100%",
  height: 8,
  backgroundColor: theme.palette.grey[200],
  borderRadius: 4,
  overflow: "hidden",
  position: "relative",
  "&::after": {
    content: '""',
    position: "absolute",
    top: 0,
    left: 0,
    height: "100%",
    width: `${percent}%`,
    backgroundColor:
      readiness >= LocaleReadiness.AlmostDone
        ? theme.palette.success.main // Green
        : readiness === LocaleReadiness.Midway
          ? "#FFC107" // Yellow (Material Design amber/yellow)
          : readiness === LocaleReadiness.EarlyStage
            ? theme.palette.error.main // Red
            : theme.palette.grey[500], // Grey
    transition: "width 0.3s ease-in-out",
  },
}));
 
const LargeLanguageCard = styled(Card, {
  shouldForwardProp: (prop) => prop !== "readiness",
})<{ readiness: LocaleReadiness }>(({ theme, readiness }) => ({
  width: "100%",
  transition: "transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out",
  opacity: readiness === LocaleReadiness.JustStarted ? 0.35 : readiness === LocaleReadiness.EarlyStage ? 0.55 : 1,
  marginBottom: theme.spacing(2),
 
  "&:hover": {
    transform: "translateY(-1px)",
    boxShadow: theme.shadows[2],
  },
}));
 
const SmallLanguageCard = styled(Card, {
  shouldForwardProp: (prop) => prop !== "readiness",
})<{ readiness: LocaleReadiness }>(({ theme, readiness }) => ({
  width: "100%",
  transition: "transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out",
  opacity: readiness === LocaleReadiness.JustStarted ? 0.35 : readiness === LocaleReadiness.EarlyStage ? 0.55 : 1,
  marginBottom: theme.spacing(2),
}));
 
const getStatusColor = (readiness: LocaleReadiness): "success" | "info" | "warning" | "error" | "default" => {
  if (readiness >= LocaleReadiness.AlmostDone) return "success"; // Green
  Eif (readiness === LocaleReadiness.Midway) return "warning"; // Orange/Yellow
  if (readiness === LocaleReadiness.EarlyStage) return "error"; // Red
  return "default"; // Grey
};
 
const getStatusText = (readiness: LocaleReadiness, t: (key: string) => string) => {
  if (readiness === LocaleReadiness.Complete) return t("global:language_preference.translation_progress.complete");
  if (readiness === LocaleReadiness.AlmostDone)
    return t("global:language_preference.translation_progress.almost_there");
  Eif (readiness === LocaleReadiness.Midway) return t("global:language_preference.translation_progress.midway");
  if (readiness === LocaleReadiness.EarlyStage) return t("global:language_preference.translation_progress.early_stage");
  return t("global:language_preference.translation_progress.just_started");
};
 
const StyledCardContent = styled(CardContent)(({ theme }) => ({
  padding: theme.spacing(1.5),
  display: "flex",
  alignItems: "center",
  "&:last-child": {
    paddingBottom: theme.spacing(1.5),
  },
}));
 
export default function TranslationProgress() {
  const isMobile = useMediaQuery(theme.breakpoints.down("md"));
  const { t } = useTranslation([GLOBAL]);
 
  const { data: localeInfos, isLoading, error } = useLocaleInfos();
 
  Iif (isLoading) {
    return (
      <Box sx={{ p: 2 }}>
        <Typography variant="h6" gutterBottom>
          {t("global:language_preference.translation_progress.loading")}
        </Typography>
      </Box>
    );
  }
 
  Iif (error) {
    return (
      <Box sx={{ p: 2 }}>
        <Typography variant="h6" color="error" gutterBottom>
          {t("global:language_preference.translation_progress.error_loading")}
        </Typography>
      </Box>
    );
  }
 
  // Show all locales with any progress, sorted by completion percentage
  const availableLocales = localeInfos
    .filter((locale) => locale.stringAvailabilityPercent > 0)
    .sort((a, b) => b.stringAvailabilityPercent - a.stringAvailabilityPercent);
 
  return (
    <Box sx={{ p: 2 }}>
      <Box sx={{ mb: 3, display: "flex", alignItems: "center", gap: 1 }}>
        <TranslateIcon sx={{ fontSize: 28, color: "primary.main" }} />
        <Typography
          variant="h1"
          sx={{
            fontWeight: "bold",
          }}
        >
          {t("global:language_preference.translation_progress.title")}
        </Typography>
      </Box>
      <Box sx={{ mb: 3 }}>
        <Typography sx={{ mb: 2 }}>{t("global:language_preference.translation_progress.description")}</Typography>
        <Link
          href={translateJobURL}
          target="_blank"
          rel="noreferrer noopener"
          underline="hover"
          sx={{ fontWeight: "bold" }}
        >
          {t("global:language_preference.translation_progress.help_translate")} →
        </Link>
      </Box>
      <Box sx={{ mb: 3, p: 2, bgcolor: "grey.50", borderRadius: 2 }}>
        <Typography
          sx={{
            color: "text.secondary",
          }}
        >
          {t("global:language_preference.translation_progress.info_text")}
        </Typography>
      </Box>
      {availableLocales.map((localeInfo) => {
        const languageCode = localeInfo.code;
        const nativeName = localeInfo.autonym;
        const percent = localeInfo.stringAvailabilityPercent;
        const readiness = getLocaleReadiness(percent);
 
        return (
          <React.Fragment key={localeInfo.code}>
            {isMobile && (
              <SmallLanguageCard readiness={readiness}>
                <StyledCardContent
                  sx={{
                    display: "flex",
                    flexDirection: "column",
                    alignItems: "flex-start",
                  }}
                >
                  <Box
                    sx={{
                      display: "flex",
                      gap: 2,
                      alignItems: "center",
                      justifyContent: "space-between",
                      width: "100%",
                    }}
                  >
                    <Box sx={{ display: "flex", gap: 2, alignItems: "center" }}>
                      <Typography
                        variant="subtitle2"
                        sx={{
                          fontWeight: "bold",
                        }}
                      >
                        {nativeName}
                      </Typography>
                    </Box>
                    <Chip
                      label={getStatusText(readiness, t)}
                      size="small"
                      color={getStatusColor(readiness)}
                      variant="outlined"
                      sx={{
                        ...(readiness === LocaleReadiness.Midway && {
                          borderColor: "#FFC107",
                          color: "#F57C00",
                        }),
                      }}
                    />
                  </Box>
                  <Box
                    sx={{
                      display: "flex",
                      justifyContent: "space-between",
                      marginTop: 2,
                      width: "100%",
                    }}
                  >
                    <Typography
                      variant="h5"
                      sx={{
                        color: readiness === LocaleReadiness.JustStarted ? "text.secondary" : "primary.main",
                        fontWeight: "bold",
                      }}
                    >
                      {percent.toFixed(1)}%
                    </Typography>
                    <Typography variant="caption" sx={{ color: "text.secondary" }}>
                      {languageCode.toUpperCase()}
                    </Typography>
                  </Box>
                  <Box sx={{ flex: 1, width: "100%" }}>
                    <ProgressBar percent={percent} readiness={readiness} />
                  </Box>
                </StyledCardContent>
              </SmallLanguageCard>
            )}
            {!isMobile && (
              <LargeLanguageCard readiness={readiness}>
                <StyledCardContent>
                  <Box
                    sx={{
                      display: "flex",
                      alignItems: "center",
                      gap: 2,
                      width: "100%",
                    }}
                  >
                    <Typography
                      variant="subtitle1"
                      noWrap
                      sx={{
                        fontWeight: "bold",
                      }}
                    >
                      {nativeName}
                    </Typography>
                    <Typography
                      variant="caption"
                      sx={{
                        color: "text.secondary",
                      }}
                    >
                      {languageCode.toUpperCase()}
                    </Typography>
 
                    <Box sx={{ flex: 1, minWidth: 0 }} />
 
                    <Box
                      sx={{
                        display: "flex",
                        alignItems: "center",
                        gap: 2,
                        minWidth: 180,
                      }}
                    >
                      <Typography
                        variant="h5"
                        sx={{
                          color: readiness === LocaleReadiness.JustStarted ? "text.secondary" : "primary.main",
                          fontWeight: "bold",
                        }}
                      >
                        {percent.toFixed(1)}%
                      </Typography>
                      <Chip
                        label={getStatusText(readiness, t)}
                        size="small"
                        color={getStatusColor(readiness)}
                        variant="outlined"
                        sx={{
                          ...(readiness === LocaleReadiness.Midway && {
                            borderColor: "#FFC107",
                            color: "#F57C00",
                          }),
                        }}
                      />
                    </Box>
 
                    <Box sx={{ flex: 1, maxWidth: 200 }}>
                      <ProgressBar percent={percent} readiness={readiness} />
                    </Box>
                  </Box>
                </StyledCardContent>
              </LargeLanguageCard>
            )}
          </React.Fragment>
        );
      })}
    </Box>
  );
}