Skip to content

Commit

Permalink
chore: Add test request
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Oct 3, 2024
1 parent 8e8c741 commit 2a8ba29
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
8 changes: 1 addition & 7 deletions apps/frontend/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import type { NextConfig } from 'next';
import VitNodeConfig from 'vitnode-frontend/next.config';

// @ts-ignore
const nextConfig: NextConfig = {
logging: {
fetches: {
fullUrl: process.env.NODE_ENV === 'development',
},
},
};
const nextConfig: NextConfig = {};

export default VitNodeConfig(nextConfig);
31 changes: 22 additions & 9 deletions apps/frontend/src/i18n/request.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { getRequestConfig } from 'next-intl/server';
import { i18nConfig } from 'vitnode-frontend/i18n';

export default getRequestConfig(async args => {
const config = await i18nConfig({
...args,
pathsToMessagesFromPlugins: async ({ plugin, locale }) => {
return import(`@/plugins/${plugin}/langs/${locale}.json`);
},
});
export default getRequestConfig(async ({ requestLocale }) => {
// This typically corresponds to the `[locale]` segment
let locale = await requestLocale;

// Ensure that a valid locale is used
if (!locale) {
locale = 'en';
}

return config;
const core = (await import(`@/plugins/core/langs/${locale}.json`)).default;
const admin = (await import(`@/plugins/admin/langs/${locale}.json`)).default;
const welcome = (await import(`@/plugins/welcome/langs/${locale}.json`))
.default;

return {
locale,
messages: {
...core,
...admin,
...welcome,
},
timeZone: 'UTC',
};
});
14 changes: 8 additions & 6 deletions packages/frontend/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { notFound } from 'next/navigation';
import { IntlConfig } from 'next-intl';

import { fetcher } from './graphql/fetcher';
Expand All @@ -20,9 +19,9 @@ export const i18nConfig = async ({
plugin: string;
}) => Promise<{ default: unknown }>;
requestLocale: Promise<string | undefined>;
}): Promise<Omit<IntlConfig, 'locale'>> => {
const locale = await requestLocale;
if (!locale) notFound();
}): Promise<IntlConfig> => {
let locale = await requestLocale;
let defaultLocale = 'en';

let plugins: string[] = [];
try {
Expand All @@ -35,8 +34,10 @@ export const i18nConfig = async ({
query: Core_Middleware__Show,
});

const defaultLanguage = languages.find(lang => lang.default);
defaultLocale = defaultLanguage?.code ?? 'en';
if (!languages.find(lang => lang.code === locale)) {
notFound();
locale = defaultLanguage?.code;
}

plugins = pluginsFromServer;
Expand All @@ -50,7 +51,7 @@ export const i18nConfig = async ({
try {
const message = await pathsToMessagesFromPlugins({
plugin,
locale,
locale: locale ?? defaultLocale,
});

return message.default;
Expand All @@ -61,6 +62,7 @@ export const i18nConfig = async ({
);

return {
locale: locale ?? defaultLocale,
messages: {
...messagesFormApps.reduce(
(acc, messages) => ({ ...acc, ...messages }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const UsersMembersAdminView = async ({
getTranslations('admin.members.users'),
]);

// console.log('data', data);

return (
<>
<HeaderContent desc={t('desc')} h1={t('title')}>
Expand Down

0 comments on commit 2a8ba29

Please sign in to comment.