All skills
sergiodxa avatar

/frontend-internationalization-best-practices

@6eae8fd

Internationalization best practices for React Router framework mode using remix-i18next. Use when setting up locales, middleware, resource routes, or language switching.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-internationalization-best-practices

This session only. Nothing lands on disk.

ruleslocales-resource-route.md

≈354 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Serve Locales from a Resource Route

Expose /api/locales/:lng/:ns to load translation resources with caching.

Pattern

// app/routes/api.locales.$lng.$ns.ts
import { data } from "react-router";
import { cacheHeader } from "pretty-cache-header";
import { z } from "zod";
import resources from "~/locales";
import type { Route } from "./+types/api.locales.$lng.$ns";

export async function loader({ params }: Route.LoaderArgs) {
  const lng = z
    .enum(Object.keys(resources) as Array<keyof typeof resources>)
    .safeParse(params.lng);

  if (lng.error) return data({ error: lng.error }, { status: 400 });

  const namespaces = resources[lng.data];

  const ns = z
    .enum(Object.keys(namespaces) as Array<keyof typeof namespaces>)
    .safeParse(params.ns);

  if (ns.error) return data({ error: ns.error }, { status: 400 });

  const headers = new Headers();
  if (process.env.NODE_ENV === "production") {
    headers.set(
      "Cache-Control",
      cacheHeader({
        maxAge: "5m",
        sMaxage: "1d",
        staleWhileRevalidate: "7d",
        staleIfError: "7d",
      }),
    );
  }

  return data(namespaces[ns.data], { headers });
}

Rules

  1. Validate lng and ns before returning data
  2. Cache locale resources in production
  3. Keep the route aligned with client loadPath

Source: SKILL.md on GitHub

1 warning8d5 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    The skill provides guidelines and patterns for implementing internationalization in React Router applications using remix-i18next. It demonstrates secure practices such as using Zod for input validation in resource routes to prevent directory traversal or arbitrary data access, and correctly configuring secure cookies for locale persistence. No security issues were identified.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

  • Runlayer7mo

    12/12 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 6eae8fd. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-internationalization-best-practices