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.

ruleslocale-detection.md

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

Prefer Cookie/Session Locale with DB Source of Truth

Use cookie or session for fast locale access, and fall back to DB when needed.

Why

  • Avoid DB lookups on every request
  • Keep a stable locale across server and client
  • Still honor user preferences stored in DB

Pattern

// app/middleware/i18next.ts
export const [i18nextMiddleware, getLocale] = createI18nextMiddleware({
  detection: {
    supportedLanguages: ["es", "en"],
    fallbackLanguage: "en",
    cookie: localeCookie,
    async findLocale(request) {
      let locale = await getLocaleFromSession(request);
      if (locale) return locale;

      let userLocale = await getLocaleFromDatabase(request);
      return userLocale ?? "en";
    },
  },
  i18next: { resources },
});

Optional: Pathname Locale

If you want /en/... routes, you can use findLocale to read the first path segment. This is optional and not recommended as the default storage.

findLocale(request) {
  let locale = new URL(request.url).pathname.split("/")[1];
  return locale;
}

Rules

  1. Read locale from cookie/session for speed
  2. Use DB as the source of truth when present
  3. Only use pathname locales if your routing strategy requires it

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