Nextbase Docs
Guides

Removing Internationalization

Learn how to remove internationalization from your Nextbase application

Many saas products require internalization. But many don't need it too. Ultimately it is your customer requirements that matter.

If you don't need internationalization, you can remove it by following these steps:

  1. Move all the children of the src/app/[locale] folder to the src/app/ folder.
  2. Remove the [locale] from the src/app/ folder.
  3. Remove the next-intl from the package.json file.
  4. Update your middleware to this pattern. Pay close attention to the
// your imports stay the same
 
/**
 * Public paths are paths that are accessible to everyone.
 * They don't require the user to be logged in.
 */
const publicPaths = [
  `/`,
  `/changelog`,
  //...  other public paths
];
 
/**
 * Dashboard routes are paths that are accessible to logged in users.
 * They require the user to be logged in.
 */
const dashboardRoutes = [
  `/dashboard(/.*)?`,
  // ... other dashboard routes
];
 
/**
 * Onboarding paths are paths that are accessible to users who are not onboarded.
 * They require the user to be logged in.
 * However, if the user is not onboard, the dashboard routes are not accessible.
 */
const onboardingPaths = [`/onboarding(/.*)?`];
 
/**
 * App admin paths are paths that are accessible to app admins.
 * They require the user to be logged in.
 */
const appAdminPaths = [`/app_admin(/.*)?`];
 
/**
 * All routes which require login including dashboard, onboarding and app admin.
 */
const protectedPaths = [
  ...dashboardRoutes,
  ...onboardingPaths,
  ...appAdminPaths,
];
 
type MiddlewareFunction = (request: NextRequest) => Promise<NextResponse>;
 
interface MiddlewareConfig {
  matcher: string | string[];
  middleware: MiddlewareFunction;
}
 
function withMaybeLocale(request: NextRequest, subPath: string) {
  const currentLocale = request.cookies.get('NEXT_LOCALE')?.value;
  if (currentLocale) {
    return urlJoin(currentLocale, subPath);
  }
  return subPath;
}
 
const middlewares: MiddlewareConfig[] = [
  // remove the first two middleware configs which are related to locale
  {
    // protected routes
    matcher: protectedPaths, // instead of protectedPathsWithLocale
    middleware: async (req) => {
      // ...
    },
  },
  {
    matcher: dashboardRoutes, // instead of dashboardRoutesWithLocale
    middleware: async (req) => {
      // ...
    },
  },
  {
    matcher: onboardingPaths, // instead of onboardingPathsWithLocale
    middleware: async (req) => {
      // ...
    },
  },
  {
    // match /app_admin and /app_admin/ and all subpaths
    matcher: appAdminPaths, // instead of appAdminPathsWithLocale
    middleware: async (req) => {
      // ...
    },
  },
];
 
// the rest of the middleware configs stay the same
  1. Remove src/i18n folder.
  2. Replace all import { Link } from "@/components/intl-link"; with import Link from "next/link";
  3. Remove all LocaleSwitcherSelect component and its usage
  4. Remove import createNextIntlPlugin from "next-intl/plugin" and its usage in next.config.mjs
  5. Remove unstable_setRequestLocale usage in all static pages and locale from 'params'.
  6. Remove useTranslations usage in all client components.
  7. Remove getMessages usage in root layout component and remove locale and messages props from AppProviders component. Finally remove NextIntlProvider from the AppProviders component.

On this page

No Headings