Просмотр исходного кода

fix(i18n): keep network data out of browser translation (#675)

The document always declared lang="es" even with the UI in English, so
browsers kept offering to translate the page and the translator rewrote
data values (hostnames like crowed-pixeltab became crowded-pixeltab).
The document language now follows the active UI language, and hostnames
and IPs in the client and device lists are marked translate="no".

Closes #666

Co-authored-by: gnacho <hnacho@proton.me>
Nacho 2 месяцев назад
Родитель
Сommit
7289fbd89e

+ 1 - 1
app/src/components/DeviceRow.tsx

@@ -134,7 +134,7 @@ export function DeviceRow({ device, variant = 'compact', className, onClick }: D
       </div>
       </div>
       <div className="min-w-0 flex-1">
       <div className="min-w-0 flex-1">
         <div className="flex items-center gap-2">
         <div className="flex items-center gap-2">
-          <span className="truncate text-sm font-medium text-text-primary">{device.name}</span>
+          <span className="truncate text-sm font-medium text-text-primary" translate="no">{device.name}</span>
           {device.isNew && (
           {device.isNew && (
             <span className="rounded-full bg-accent-soft px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-accent">
             <span className="rounded-full bg-accent-soft px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-accent">
               {t('devices.new')}
               {t('devices.new')}

+ 2 - 2
app/src/components/routers/RouterClients.tsx

@@ -106,12 +106,12 @@ export function RouterClients({ router }: { router: Router }) {
                         <Icon className="h-4 w-4" strokeWidth={1.75} />
                         <Icon className="h-4 w-4" strokeWidth={1.75} />
                       </span>
                       </span>
                       <div>
                       <div>
-                        <div className="font-medium text-text-primary">{d.name}</div>
+                        <div className="font-medium text-text-primary" translate="no">{d.name}</div>
                         <div className="text-caption text-text-muted">{d.manufacturer}</div>
                         <div className="text-caption text-text-muted">{d.manufacturer}</div>
                       </div>
                       </div>
                     </div>
                     </div>
                   </td>
                   </td>
-                  <td className="py-3 pr-3 font-mono text-mono-sm text-text-secondary">{d.ip}</td>
+                  <td className="py-3 pr-3 font-mono text-mono-sm text-text-secondary" translate="no">{d.ip}</td>
                   <td className="py-3 pr-3 capitalize text-text-secondary">{t(`devices.types.${d.type}`)}</td>
                   <td className="py-3 pr-3 capitalize text-text-secondary">{t(`devices.types.${d.type}`)}</td>
                   <td className="py-3 pr-3">
                   <td className="py-3 pr-3">
                     <span className="rounded-full bg-elevated px-2 py-0.5 font-mono text-caption text-text-secondary">{d.band}</span>
                     <span className="rounded-full bg-elevated px-2 py-0.5 font-mono text-caption text-text-secondary">{d.band}</span>

+ 12 - 0
app/src/i18n.ts

@@ -43,6 +43,18 @@ i18n
     returnNull: false,
     returnNull: false,
   })
   })
 
 
+// #666: el lang del documento debe seguir al idioma activo. index.html declara
+// lang="es"; si un usuario con la UI en inglés no lo actualizamos, el navegador
+// cree que la página es española y ofrece traducirla — y el traductor destroza
+// los datos (hostnames "crowed" → "crowded"). Con el lang correcto, la UI
+// traducida no dispara la oferta de traducción.
+const applyDocLang = (lng?: string) => {
+  const l = (lng ?? i18n.language ?? 'es').slice(0, 2).toLowerCase()
+  document.documentElement.lang = l === 'en' ? 'en' : 'es'
+}
+applyDocLang()
+i18n.on('languageChanged', applyDocLang)
+
 export default i18n
 export default i18n
 
 
 /** Locale numérico según el idioma activo */
 /** Locale numérico según el idioma activo */

+ 3 - 3
app/src/pages/Devices.tsx

@@ -263,7 +263,7 @@ function StatsStrip({ allDevices }: { allDevices: ClientDevice[] }) {
           <div className="pointer-events-none absolute left-0 top-full z-20 mt-2 hidden w-52 rounded-xl border border-border-strong bg-elevated p-3 group-hover:block">
           <div className="pointer-events-none absolute left-0 top-full z-20 mt-2 hidden w-52 rounded-xl border border-border-strong bg-elevated p-3 group-hover:block">
             <div className="mb-1.5 text-label uppercase text-text-muted">{t('devices.stats.seenThisWeek')}</div>
             <div className="mb-1.5 text-label uppercase text-text-muted">{t('devices.stats.seenThisWeek')}</div>
             {newThisWeekDevices.map((d) => (
             {newThisWeekDevices.map((d) => (
-              <div key={d.id} className="truncate py-0.5 text-xs text-text-secondary">
+              <div key={d.id} className="truncate py-0.5 text-xs text-text-secondary" translate="no">
                 {d.name}
                 {d.name}
                 <span className="text-text-muted"> · {d.firstSeen}</span>
                 <span className="text-text-muted"> · {d.firstSeen}</span>
               </div>
               </div>
@@ -818,7 +818,7 @@ function ListRow({
           <DeviceTile device={device} />
           <DeviceTile device={device} />
           <div className="min-w-0">
           <div className="min-w-0">
             <div className="flex items-center gap-2">
             <div className="flex items-center gap-2">
-              <span className="truncate text-sm font-medium text-text-primary">{device.name}</span>
+              <span className="truncate text-sm font-medium text-text-primary" translate="no">{device.name}</span>
               <button
               <button
                 type="button"
                 type="button"
                 onClick={(e) => {
                 onClick={(e) => {
@@ -978,7 +978,7 @@ function GridCard({
           </div>
           </div>
         </div>
         </div>
         <div className="mt-3 flex items-center gap-2">
         <div className="mt-3 flex items-center gap-2">
-          <span className="truncate text-sm font-medium text-text-primary">{device.name}</span>
+          <span className="truncate text-sm font-medium text-text-primary" translate="no">{device.name}</span>
           {infra && <InfraBadge info={infra} />}
           {infra && <InfraBadge info={infra} />}
           <TypeBadge type={device.type} />
           <TypeBadge type={device.type} />
         </div>
         </div>