Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outside of react component does not work ? #36

Open
xian107 opened this issue Jan 2, 2024 · 2 comments
Open

outside of react component does not work ? #36

xian107 opened this issue Jan 2, 2024 · 2 comments

Comments

@xian107
Copy link

xian107 commented Jan 2, 2024

// 'lng' how to get it
// Do not use cookies
http.js
const isServer = typeof window === 'undefined';
const http = axios.create({
baseURL: process.env.REACT_APP_API_PATH,
timeout: 60000,
});
http.interceptors.response.use( async (response) => {
if (error.response?.status === 4005) {
if(isServer){
const { useTranslation } = (await import('@/app/i18n/index'));
// 'lng' how to get it
const { t } = useTranslation(lng, 'h-page');
message.error(t('K9')); // please login again
}else{
const { useTranslation } = (await import('@/app/i18n/client'));
// 'lng' how to get it
const { t } = useTranslation(lng, 'h-page');
message.error(t('K9')); // please login again
}
}
})

order.tsx
import http from '@/app/http';
import React from 'react'
export default function Order() {
http.get('/api/order/list').then(res => {})
return (


)
}

@xian107
Copy link
Author

xian107 commented Jan 2, 2024

@adrai
Copy link
Member

adrai commented Jan 2, 2024

in general:
i18next/next-i18next#2079 (comment)
i18next/next-i18next#2171

on client side you can do this:

import i18next from 'i18next'
// ...
i18next.t('mykey')

but on server side you always need a way to get the language first...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants