Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1st i18n collaboration #3475

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const cspHeader = `
${process.env.NEXT_PUBLIC_CLOUD_ENABLED === "true" ? "upgrade-insecure-requests;" : ""}
`;

const withNextIntl = require('next-intl/plugin')();

/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
Expand Down Expand Up @@ -85,4 +87,4 @@ const sentryWebpackPluginOptions = {
};

// Export the module with conditional Sentry configuration
module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);
module.exports = withNextIntl(withSentryConfig(nextConfig, sentryWebpackPluginOptions));
14 changes: 14 additions & 0 deletions web/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {getRequestConfig} from 'next-intl/server';
import {notFound} from 'next/navigation';

// Can be imported from a shared config
const locales = ['en', 'es'];

export default getRequestConfig(async ({locale}) => {
// Validate that the incoming `locale` parameter is valid
if (!locales.includes(locale as any)) notFound();

return {
messages: (await import(`./messages/${locale}.json`)).default
};
});
12 changes: 12 additions & 0 deletions web/src/messages/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Index": {
"title": "Welcome to Onyx",
"description": "A powerful and modern platform"
},
"Common": {
"loading": "Loading...",
"error": "An error has occurred",
"save": "Save",
"cancel": "Cancel"
}
}
12 changes: 12 additions & 0 deletions web/src/messages/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Index": {
"title": "Bienvenido a Onyx",
"description": "Una plataforma potente y moderna"
},
"Common": {
"loading": "Cargando...",
"error": "Ha ocurrido un error",
"save": "Guardar",
"cancel": "Cancelar"
}
}
58 changes: 15 additions & 43 deletions web/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,18 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { SERVER_SIDE_ONLY__PAID_ENTERPRISE_FEATURES_ENABLED } from "./lib/constants";
import createMiddleware from 'next-intl/middleware';

export default createMiddleware({
// Lista de locales soportados
locales: ['en', 'es'],

// Locale por defecto
defaultLocale: 'es',

// Redirigir a la URL con locale
localePrefix: 'always'
});

// NOTE: have to have the "/:path*" here since NextJS doesn't allow any real JS to
// be run before the config is defined e.g. if we try and do a .map it will complain
export const config = {
matcher: [
"/admin/groups/:path*",
"/admin/performance/usage/:path*",
"/admin/performance/query-history/:path*",
"/admin/whitelabeling/:path*",
"/admin/performance/custom-analytics/:path*",
"/admin/standard-answer/:path*",

// Cloud only
"/admin/billing/:path*",
],
// Matcher configurado para manejar todos los paths excepto los que comienzan con
// /api/, /_next/, /_vercel/, /images/, /favicon.ico, /robots.txt
matcher: ['/((?!api|_next|_vercel|images|favicon.ico|robots.txt).*)']
};

// removes the "/:path*" from the end
const stripPath = (path: string) =>
path.replace(/(.*):\path\*$/, "$1").replace(/\/$/, "");

const strippedEEPaths = config.matcher.map(stripPath);

export async function middleware(request: NextRequest) {
if (SERVER_SIDE_ONLY__PAID_ENTERPRISE_FEATURES_ENABLED) {
const pathname = request.nextUrl.pathname;

// Check if the current path is in the eePaths list
if (strippedEEPaths.some((path) => pathname.startsWith(path))) {
// Add '/ee' to the beginning of the pathname
const newPathname = `/ee${pathname}`;

// Create a new URL with the modified pathname
const newUrl = new URL(newPathname, request.url);

// Rewrite to the new URL
return NextResponse.rewrite(newUrl);
}
}

// Continue with the response if no rewrite is needed
return NextResponse.next();
}