-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "chore: work on getting locale onthe backend through headers"
This reverts commit 029fa38.
- Loading branch information
1 parent
029fa38
commit 65986b7
Showing
15 changed files
with
43 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import { TRPCError } from '@trpc/server'; | ||
import { getTranslations } from 'next-intl/server'; | ||
import { cookies } from 'next/headers'; | ||
|
||
import { routing } from '@/lib/locale'; | ||
|
||
function getLocaleFromRequest(request: Request) { | ||
const acceptLanguage = request.headers.get('accept-language'); | ||
if (!acceptLanguage) { | ||
return routing.defaultLocale; | ||
async function getLocaleFromCookie() { | ||
const cookieStore = await cookies(); | ||
const locale = cookieStore.get('locale')?.value ?? routing.defaultLocale; | ||
if (!routing.locales.includes(locale as 'en')) { | ||
const t = await getTranslations('error'); | ||
throw new TRPCError({ | ||
code: 'BAD_REQUEST', | ||
message: t('invalidLocale', { locale }), | ||
}); | ||
} | ||
const preferredLocale = | ||
acceptLanguage.split(',').at(0)?.split(';').at(0)?.toLowerCase().trim() ?? | ||
''; | ||
|
||
return routing.locales.includes( | ||
preferredLocale as (typeof routing.locales)[number], | ||
) | ||
? (preferredLocale as (typeof routing.locales)[number]) | ||
: routing.defaultLocale; | ||
return locale; | ||
} | ||
|
||
export { getLocaleFromRequest }; | ||
export { getLocaleFromCookie }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { TRPCError as BaseTRPCError } from '@trpc/server'; | ||
|
||
type TRPCError = BaseTRPCError & { | ||
toast?: 'success' | 'info' | 'warning' | 'error'; | ||
}; | ||
|
||
export type { TRPCError }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters