feat: 🚸 Rename router default locale for user faced use
Simon Mulquin simon@octree.ch
Thu, 19 Jan 2023 10:17:02 +0000
5 files changed,
13 insertions(+),
6 deletions(-)
M
frontend/.env.example
→
frontend/.env.example
@@ -4,3 +4,4 @@ NEXTAUTH_SECRET=gewrsdfhgfh
NEXTAUTH_URL=http://localhost:3000/api/nauth GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= +# DEFAULT_LOCALE=share
M
frontend/middleware.ts
→
frontend/middleware.ts
@@ -8,6 +8,7 @@ import {initializeApollo} from './lib/apolloClient';
import {getCookie} from './lib/cookies'; const PUBLIC_FILE = /\.(.*)$/; +const DEFAULT_LOCALE = process.env.DEFAULT_LOCALE || 'share'; export async function middleware(req: NextRequest) { if (@@ -19,7 +20,7 @@ ) {
return; } - if (req.nextUrl.locale === 'share') { + if (req.nextUrl.locale === DEFAULT_LOCALE) { const registeredUserLanguage = await getRegisteredUserLanguage(req); const NEXT_LOCALE = getCookie('NEXT_LOCALE', req.headers.get('cookie')); const browserPreferredSupportedLanguage =
M
frontend/next.config.js
→
frontend/next.config.js
@@ -1,5 +1,5 @@
const {i18n} = require('./react-i18next.config'); -const {NODE_ENV, STRAPI_URL = 'http://localhost:1337'} = process.env; +const {NODE_ENV, STRAPI_URL = 'http://localhost:1337', DEFAULT_LOCALE = 'share'} = process.env; const withPWA = require('next-pwa')({ dest: 'public',@@ -16,6 +16,7 @@ ignoreBuildErrors: true,
}, env: { STRAPI_URL: process.env.STRAPI_URL, + DEFAULT_LOCALE }, i18n,
M
frontend/react-i18next.config.js
→
frontend/react-i18next.config.js
@@ -1,8 +1,10 @@
+const {DEFAULT_LOCALE = 'share'} = process.env; + module.exports = { i18n: { - defaultLocale: 'share', - locales: ['share', 'en', 'fr'], - localeDetection: false + defaultLocale: DEFAULT_LOCALE, + locales: [DEFAULT_LOCALE, 'en', 'fr'], + localeDetection: false, }, trailingSlash: true,