Skip to content

Commit 8b8995e

Browse files
Hotfix: Fix locale fetching and static files issue (#13)
* feat: init base of feature * chore: remove loading only in fail in signin * feat: add i18n * feat: update roadmap docs * feat: update github templates * feat: add i18n in mobile * refactor: create navbar dashboard component and add languague selector in dashboard * chore: update future roadmap * chore: create issue finalized markdown template * fix: add vercel json to use public in static * fix: get locale in production with fetch * chore: remove vercel file * fix: moving locales to src * chore: move location to src
1 parent 0996014 commit 8b8995e

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/app/layout.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
41
import { cookies } from 'next/headers';
52

6-
import { Poppins } from 'next/font/google'
3+
import { Poppins } from 'next/font/google';
74

85
import Toast from '@/components/Toast';
96
import { DatadogProvider } from '@/contexts/DatadogContext';
107
import { I18nProvider } from '@/contexts/i18nContext';
118
import { ToastProvider } from '@/contexts/ToastContext';
9+
import enUSLocale from '@/locales/en-US.json';
10+
import ptBRLocale from '@/locales/pt-BR.json';
1211

1312
import "@/styles/globals.css";
1413

15-
1614
const poppins = Poppins({
1715
subsets: ['latin'],
18-
weight: ['100', '200', '300', '400', '500', '600', '700', '800', '900',]
19-
})
16+
weight: ['100', '200', '300', '400', '500', '600', '700', '800', '900']
17+
});
2018

2119
export async function generateStaticParams() {
2220
return [{ locale: 'en-US' }, { locale: 'pt-BR' }, { locale: 'es' }];
2321
}
2422

2523
const loadTranslations = (locale: string): Record<string, string> => {
26-
const filePath = path.join(process.cwd(), 'public', 'locales', `${locale}.json`);
27-
const file = fs.readFileSync(filePath, 'utf-8');
28-
return JSON.parse(file);
24+
const translationsMap: Record<string, Record<string, string>> = {
25+
'en-US': enUSLocale,
26+
'pt-BR': ptBRLocale,
27+
};
28+
29+
const translations = translationsMap[locale] || enUSLocale;
30+
return translations;
2931
};
3032

3133
type Props = {
3234
children: React.ReactNode;
33-
}
35+
};
36+
3437
export default async function RootLayout({ children }: Props) {
3538
const cookieStore = await cookies();
3639
const locale = cookieStore.get('locale')?.value || 'en-US';
37-
const translations = loadTranslations(locale);
40+
const translations = await loadTranslations(locale);
3841

3942
return (
4043
<html lang={locale}>
@@ -51,4 +54,4 @@ export default async function RootLayout({ children }: Props) {
5154
</body>
5255
</html>
5356
);
54-
}
57+
}

src/locales/en-US.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"default": "default"
3+
}

src/locales/pt-BR.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"default": "padrão"
3+
}

0 commit comments

Comments
 (0)