Skip to content

Commit ebb6852

Browse files
authored
Update index.html
1 parent 8a5b45b commit ebb6852

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/public/index.html

+12-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
<title>Language Redirect</title>
77
<script>
88
function getCookie(name) {
9+
console.log('getCookie function run!!');
910
const value = `; ${document.cookie}`;
1011
const parts = value.split(`; ${name}=`);
1112
if (parts.length === 2) return parts.pop().split(';').shift();
1213
}
1314

1415
function setCookie(name, value, days) {
16+
console.log('setCookie function run!!');
1517
const date = new Date();
1618
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
1719
document.cookie = `${name}=${value};path=/;expires=${date.toUTCString()};SameSite=Lax`;
18-
19-
console.log(document.cookie)
2020
}
2121

2222
async function detectAndRedirect() {
@@ -33,7 +33,7 @@
3333
const response = await fetch('https://ipapi.co/json/');
3434
const data = await response.json();
3535
const country = data.country; // e.g., "IR" for Iran
36-
36+
3737
// Determine language based on location or browser language
3838
let lang = 'en'; // Default language
3939
if (country === "IR") {
@@ -44,14 +44,20 @@
4444
}
4545

4646
// Save the language in a cookie
47-
await setCookie('userLang', lang, 365); // Save for 1 year
48-
47+
setCookie('userLang', lang, 365); // Save for 1 year
48+
4949
// Redirect to the appropriate language
5050
window.location.href = `/docs/${lang}/guides/`;
5151
} catch (error) {
5252
console.error("Error detecting location or language:", error);
5353
// Default to English if there's an error
54-
window.location.href = `/docs/en/guides/`;
54+
if(Intl.DateTimeFormat().resolvedOptions().timeZone === 'Asia/Tehran'){
55+
await setCookie('userLang', 'fa', 365); // Save for 1 year
56+
window.location.href = `/docs/fa/guides/`;
57+
}else{
58+
await setCookie('userLang', 'en', 365); // Save for 1 year
59+
window.location.href = `/docs/en/guides/`;
60+
}
5561
}
5662
}
5763

0 commit comments

Comments
 (0)