all repos — caroster @ 380b5581ffd8c7e099895b76a085bab341e6901a

[Octree] Group carpool to your event https://caroster.io

feat: 🚸  Rename router default locale for user faced use
Simon Mulquin simon@octree.ch
Thu, 19 Jan 2023 10:17:02 +0000
commit

380b5581ffd8c7e099895b76a085bab341e6901a

parent

c4ee8c801635c3fcdb28d1bec4b97d691b098144

M frontend/.env.examplefrontend/.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/hooks/useShare.tsfrontend/hooks/useShare.ts

@@ -2,6 +2,8 @@ import {useTranslation} from 'react-i18next';

import {Enum_Userspermissionsuser_Lang as SupportedLocales} from '../generated/graphql'; import useToastStore from '../stores/useToastStore'; +const DEFAULT_LOCALE = process.env.DEFAULT_LOCALE || 'share'; + const navigatorHasShareCapability = typeof navigator !== 'undefined' && !!navigator.share; const navigatorHasClipboardCapability =

@@ -20,7 +22,7 @@ const splittedUrl = url.split('/');

const localeParamIndex = splittedUrl.findIndex( member => SupportedLocales[member] ); - splittedUrl[localeParamIndex] = 'default'; + splittedUrl[localeParamIndex] = DEFAULT_LOCALE; const withDefaultLocaleURL = splittedUrl.join('/'); // If navigator share capability if (navigatorHasShareCapability) {
M frontend/middleware.tsfrontend/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.jsfrontend/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.jsfrontend/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,