File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# better-auth-localization
22
3+ ## 2.1.7
4+
5+ ### Patch Changes
6+
7+ - Fixed issue where translations were not applied on server side requests
8+ - Added support for Danish (Thanks @BjornFrancke )
9+
310## 2.1.6
411
512### Patch Changes
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ This repo auto-generates the translations index to avoid PR conflicts when multi
1611611 . Create a new file in ` src/translations/ ` , for example ` nl.ts ` .
1621622 . Export your translation object and a ` LOCALES ` map from that file:
163163 ``` ts
164- import { ErrorCodesType } from " ../types" ;
164+ import type { ErrorCodesType } from " ../types" ;
165165
166166 export const NL_NL = { /* ...all error codes... */ } satisfies ErrorCodesType ;
167167
Original file line number Diff line number Diff line change 11{
22 "name" : " better-auth-localization" ,
3- "version" : " 2.1.6 " ,
3+ "version" : " 2.1.7 " ,
44 "author" : " Marcel Losso" ,
55 "description" : " A custom plugin for better-auth that allows you to localize your error messages." ,
66 "main" : " dist/index.js" ,
Original file line number Diff line number Diff line change 1- import type { BetterAuthPlugin } from "better-auth" ;
1+ import type { BetterAuthPlugin , Status } from "better-auth" ;
22import { createAuthMiddleware } from "better-auth/plugins" ;
33import { defaultTranslations } from "./translations" ;
44import type {
55 AvailableLocales ,
6+ ErrorCodesType ,
67 LocalizationOptions ,
78 PartialErrorCodesType ,
89} from "./types" ;
@@ -76,7 +77,7 @@ export const localization = <
7677 ) ;
7778
7879 const resolveLocale = getLocale
79- ? async ( request : Request ) => {
80+ ? async ( request : Request | undefined ) => {
8081 try {
8182 const locale = ( await getLocale (
8283 request ,
@@ -111,13 +112,11 @@ export const localization = <
111112 handler : createAuthMiddleware ( async ( ctx ) => {
112113 const { request } = ctx ;
113114
114- if ( ! request ) return ;
115-
116115 const { returned } = ctx . context ;
117116
118117 if ( ! hasBody ( returned ) || ! isErrorBody ( returned . body ) ) return ;
119118
120- const { body } = returned ;
119+ const { body, statusCode } = returned as { body : { code : keyof ErrorCodesType ; message : string } ; statusCode : Status } ;
121120
122121 const locale = await resolveLocale ( request ) ;
123122
@@ -132,7 +131,9 @@ export const localization = <
132131 ) ;
133132
134133 if ( translatedMessage ) {
135- body . message = translatedMessage ;
134+ return ctx . error ( statusCode || "UNPROCESSABLE_ENTITY" , {
135+ message : translatedMessage ,
136+ } ) ;
136137 }
137138 } ) ,
138139 } ,
Original file line number Diff line number Diff line change 1- import { ErrorCodesType } from "../types" ;
1+ import type { ErrorCodesType } from "../types" ;
22
33export const AR_SA = {
44 // User related errors
Original file line number Diff line number Diff line change 1- import { ErrorCodesType } from "../types" ;
1+ import type { ErrorCodesType } from "../types" ;
22
33export const DA_DK = {
44 // User related errors
Original file line number Diff line number Diff line change 1- import { ErrorCodesType } from "../types" ;
1+ import type { ErrorCodesType } from "../types" ;
22
33export const DE_DE_INFORMAL = {
44 // User related errors
Original file line number Diff line number Diff line change 1- import { ErrorCodesType } from "../types" ;
1+ import type { ErrorCodesType } from "../types" ;
22
33export const EL_GR = {
44 // User related errors
Original file line number Diff line number Diff line change 1- import { ErrorCodesType } from "../types" ;
1+ import type { ErrorCodesType } from "../types" ;
22
33export const ES_ES = {
44 // User related errors
Original file line number Diff line number Diff line change 1- import { ErrorCodesType } from "../types" ;
1+ import type { ErrorCodesType } from "../types" ;
22
33export const FA_IR = {
44 // User related errors
You can’t perform that action at this time.
0 commit comments