I have a reactJs application and I want to add localization to it. I have never used i18next before but I am trying to get used to it. My problem is, I cannot detect user's browser's in use language. This is my code could you please help me with some code, I have searched all documents and answers for this topic but I could not find any solution.
This is my i18n.js file and I am importing this in files that I want to use
import i18next from 'i18next';
import languageDetector from 'i18next-browser-languagedetector';
i18next
.use(languageDetector)
.init({
debug: true,
fallbackLng: "en",
resources: {
en: {
translation: {
"table": {
"fortuneId": "FortuneId",
"name": "Name",
"age": "Age",
"date": "Date",
"relationship": "Relationship",
"note": "Note",
"topic": "Topic",
"question": "Question",
"gender": "Gender",
"rejected": "Rejected"
},
"auth": {
"signIn": "Sign In",
"signOut": "Sign Out",
"joinUs": "Join Us",
"goBack": "Go Back",
"email": "E-mail",
"username": "Username",
"password": "Password",
},
"admin": {
"employee": "Employees",
"moderator": "Moderator",
"admin": "Admin",
"refreshCounters": "Refresh Counters",
"refreshCounter": "Refresh Counter",
"setAsEmployee": "Set as Employee",
"setAsAdmin": "Set as Admin",
"setAsModerator": "Set as Moderator",
"email": "E-mail",
"password": "Password",
"answeredFortunes": "Answered Fortunes",
"controlledFortunes": "Controlled Fortunes",
},
"moderator": {
"approve": "Approve",
"reject": "Reject",
"topic": "Topic",
"name": "Name",
"age": "Age",
"date": "Date",
"relationship": "Relationship",
"gender": "Gender",
"answer": "Answer"
},
"answer": {
"fortuneId": "FortuneId",
"name": "Name",
"age": "Age",
"date": "Date",
"relationship": "Relationship",
"note": "Note",
"topic": "Topic",
"question": "Question",
"gender": "Gender",
"send": "Send",
"rejectionReason": "Rejection Reason",
"rejection": "Rejection",
"rejectedAnswer": "Rejected Answer",
"unassign": "Unassign"
},
"modal": {
"fortuneId": "FortuneId",
"name": "Name",
"age": "Age",
"date": "Date",
"relationship": "Relationship",
"note": "Note",
"topic": "Topic",
"question": "Question",
"gender": "Gender",
"assignToMe": "Assign to Me",
"cancel": "Cancel"
},
"profile": {
"name": "Name",
"age": "Age",
"email": "E-mail",
"answeredFortunes": "Answered Fortunes",
"controlledFortunes": "Controlled Fortunes",
"employeeTypeAdmin": "Admin",
"employeeTypeModerator": "Moderator",
"employeeTypeEmployee": "Employee",
},
"errors": {},
}
},
tr: {
translation: {
"table": {
"fortuneId": "FalId",
"name": "Ad",
"age": "Yaş",
"date": "Tarih",
"relationship": "İlişki Durumu",
"note": "Not",
"topic": "Konu",
"question": "Soru",
"gender": "Cinsiyet",
"rejected": "Reddedildi"
},
"auth": {
"signIn": "Giriş Yap",
"signOut": "Çıkış Yap",
"joinUs": "Bize Katıl",
"goBack": "Geri Dön",
"email": "E-mail",
"username": "Kullanıcı Adı",
"password": "Şifre",
},
"admin": {
"employee": "Yorumcu",
"moderator": "Moderatör",
"admin": "Admin",
"refreshCounters": "Sayaçları Sıfırla",
"refreshCounter": "Sayacı Sıfırla",
"setAsEmployee": "Yorumcu Yap",
"setAsAdmin": "Admin Yap",
"setAsModerator": "Moderatör Yap",
"email": "E-mail",
"password": "Şifre",
"answeredFortunes": "Gönderilen Fallar",
"controlledFortunes": "Kontrol Edilen Fallar",
},
"moderator": {
"approve": "Onayla",
"reject": "Reddet",
"topic": "Konu",
"name": "Ad",
"age": "Yaş",
"date": "Tarih",
"relationship": "İlişki Durumu",
"gender": "Cinsiyet",
"answer": "Fal Gönderi"
},
"answer": {
"fortuneId": "FalId",
"name": "Ad",
"age": "Yaş",
"date": "Tarih",
"relationship": "İlişki Durumu",
"note": "Not",
"topic": "Konu",
"question": "Soru",
"gender": "Cinsiyet",
"send": "Gönder",
"rejectionReason": "Reddedilme Nedeni",
"rejection": "Reddedilme",
"rejectedAnswer": "Reddedilen Gönder",
"unassign": "Fal'ı Bırak"
},
"modal": {
"fortuneId": "FalId",
"name": "Ad",
"age": "Yaş",
"date": "Tarih",
"relationship": "İlişki Durumu",
"note": "Not",
"topic": "Konu",
"question": "Soru",
"gender": "Yaş",
"assignToMe": "Bana Ata",
"cancel": "İptal"
},
"profile": {
"name": "Ad",
"age": "Yaş",
"email": "E-mail",
"answeredFortunes": "Gönderilen Fallar",
"controlledFortunes": "Kontrol Edilen Fallar",
"employeeTypeAdmin": "Admin",
"employeeTypeModerator": "Moderatör",
"employeeTypeEmployee": "Yorumcu",
},
"errors": {},
}
}
}
});
export default i18next;
In those files I use this like
import i18next from "../../Localization/i18n";
<div>
{i18next.t('table.question')}
</div>
This shows me "Question" in web page but if I change my google chrome browser to Turkish, it is still in english. I do not know what I am missing.
Thank you for your help