Added homepage and moved old homepage to aboutme page
This commit is contained in:
183
public/test-language-persistence.html
Normal file
183
public/test-language-persistence.html
Normal file
@@ -0,0 +1,183 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Language Persistence Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.test-section {
|
||||
margin-bottom: 30px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.test-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
button {
|
||||
padding: 8px 16px;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
.language-status {
|
||||
margin-top: 15px;
|
||||
padding: 10px;
|
||||
background-color: #e9f7ef;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.navigation-links {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.navigation-links a {
|
||||
display: inline-block;
|
||||
margin-right: 15px;
|
||||
padding: 8px 16px;
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.navigation-links a:hover {
|
||||
background-color: #0b7dda;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Language Persistence Test</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Current Language Status</h2>
|
||||
<div class="language-status">
|
||||
<p><strong>URL Language:</strong> <span id="url-language">Checking...</span></p>
|
||||
<p><strong>LocalStorage Language:</strong> <span id="localstorage-language">Checking...</span></p>
|
||||
<p><strong>Cookie Language:</strong> <span id="cookie-language">Checking...</span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test Language Selection</h2>
|
||||
<p>Click on a language to test the language persistence:</p>
|
||||
<div class="test-buttons">
|
||||
<button onclick="changeLanguage('en')">English</button>
|
||||
<button onclick="changeLanguage('nl')">Dutch</button>
|
||||
<button onclick="changeLanguage('de')">German</button>
|
||||
<button onclick="changeLanguage('fr')">French</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Navigation Test</h2>
|
||||
<p>Use these links to test language persistence during navigation:</p>
|
||||
<div class="navigation-links">
|
||||
<a href="/" id="home-link">Home</a>
|
||||
<a href="/aboutme" id="aboutme-link">About Me</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Function to get language from URL
|
||||
function getLanguageFromURL() {
|
||||
const pathSegments = window.location.pathname.split('/').filter(Boolean);
|
||||
const supportedLanguages = ['en', 'nl', 'de', 'fr'];
|
||||
if (pathSegments.length > 0 && supportedLanguages.includes(pathSegments[0])) {
|
||||
return pathSegments[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Function to get language from localStorage
|
||||
function getStoredLanguage() {
|
||||
return localStorage.getItem('preferredLanguage');
|
||||
}
|
||||
|
||||
// Function to get language from cookie
|
||||
function getLanguageFromCookie() {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
if (cookie.startsWith('preferredLanguage=')) {
|
||||
return cookie.substring('preferredLanguage='.length);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Function to update the language status display
|
||||
function updateLanguageStatus() {
|
||||
document.getElementById('url-language').textContent = getLanguageFromURL() || 'Not set';
|
||||
document.getElementById('localstorage-language').textContent = getStoredLanguage() || 'Not set';
|
||||
document.getElementById('cookie-language').textContent = getLanguageFromCookie() || 'Not set';
|
||||
}
|
||||
|
||||
// Function to change language
|
||||
function changeLanguage(langCode) {
|
||||
// Store language in localStorage
|
||||
localStorage.setItem('preferredLanguage', langCode);
|
||||
|
||||
// Store language in cookie
|
||||
const expirationDate = new Date();
|
||||
expirationDate.setFullYear(expirationDate.getFullYear() + 1);
|
||||
document.cookie = `preferredLanguage=${langCode}; expires=${expirationDate.toUTCString()}; path=/; SameSite=Lax`;
|
||||
|
||||
// Update the language status display
|
||||
updateLanguageStatus();
|
||||
|
||||
// Update navigation links with the selected language
|
||||
updateNavigationLinks(langCode);
|
||||
|
||||
// Dispatch a custom event for language change
|
||||
const event = new CustomEvent('languageChanged', {
|
||||
detail: {
|
||||
langCode,
|
||||
previousLangCode: getLanguageFromURL() || 'en',
|
||||
willReload: false
|
||||
}
|
||||
});
|
||||
document.dispatchEvent(event);
|
||||
|
||||
// Show a success message
|
||||
alert(`Language changed to ${langCode}. Navigation links have been updated.`);
|
||||
}
|
||||
|
||||
// Function to update navigation links with the selected language
|
||||
function updateNavigationLinks(langCode) {
|
||||
const homeLink = document.getElementById('home-link');
|
||||
const aboutmeLink = document.getElementById('aboutme-link');
|
||||
|
||||
homeLink.href = `/${langCode}/`;
|
||||
aboutmeLink.href = `/${langCode}/aboutme`;
|
||||
}
|
||||
|
||||
// Initialize the page
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Update the language status display
|
||||
updateLanguageStatus();
|
||||
|
||||
// Update navigation links with the current language
|
||||
const currentLang = getStoredLanguage() || getLanguageFromCookie() || 'en';
|
||||
updateNavigationLinks(currentLang);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
177
public/test-language-switching.html
Normal file
177
public/test-language-switching.html
Normal file
@@ -0,0 +1,177 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Language Switching Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.test-section {
|
||||
margin-bottom: 30px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.test-button {
|
||||
display: inline-block;
|
||||
margin: 5px;
|
||||
padding: 8px 15px;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
.test-button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
.language-button {
|
||||
display: inline-block;
|
||||
margin: 5px;
|
||||
padding: 8px 15px;
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
.language-button:hover {
|
||||
background-color: #0b7dda;
|
||||
}
|
||||
.result {
|
||||
margin-top: 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
}
|
||||
code {
|
||||
background-color: #f1f1f1;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
font-family: monospace;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Language Switching Test</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Current URL Information</h2>
|
||||
<div class="result" id="url-info">Loading...</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Switch Language</h2>
|
||||
<p>Click on a language to switch:</p>
|
||||
<div>
|
||||
<a href="#" class="language-button" data-lang="en">English</a>
|
||||
<a href="#" class="language-button" data-lang="nl">Dutch</a>
|
||||
<a href="#" class="language-button" data-lang="de">German</a>
|
||||
<a href="#" class="language-button" data-lang="fr">French</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test Hash Navigation</h2>
|
||||
<p>Click on a section to navigate:</p>
|
||||
<div>
|
||||
<a href="#services" class="test-button">Services</a>
|
||||
<a href="#contact" class="test-button">Contact</a>
|
||||
<a href="#about" class="test-button">About</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>Test Page Navigation</h2>
|
||||
<p>Navigate to different pages:</p>
|
||||
<div>
|
||||
<a href="/" class="test-button">Home</a>
|
||||
<a href="/aboutme" class="test-button">About Me</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Display current URL information
|
||||
function updateUrlInfo() {
|
||||
const url = new URL(window.location.href);
|
||||
const pathSegments = url.pathname.split('/').filter(Boolean);
|
||||
const currentLang = pathSegments[0] || 'none';
|
||||
|
||||
const infoDiv = document.getElementById('url-info');
|
||||
infoDiv.innerHTML = `
|
||||
<p><strong>Full URL:</strong> ${url.href}</p>
|
||||
<p><strong>Path:</strong> ${url.pathname}</p>
|
||||
<p><strong>Hash:</strong> ${url.hash || 'none'}</p>
|
||||
<p><strong>Current Language:</strong> ${currentLang}</p>
|
||||
<p><strong>Path Segments:</strong> ${JSON.stringify(pathSegments)}</p>
|
||||
`;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
updateUrlInfo();
|
||||
|
||||
// Set up language buttons
|
||||
document.querySelectorAll('.language-button').forEach(button => {
|
||||
button.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
const lang = button.getAttribute('data-lang');
|
||||
if (!lang) return;
|
||||
|
||||
// Get current URL information
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const currentPath = currentUrl.pathname.replace(/\/$/, '');
|
||||
const currentHash = currentUrl.hash;
|
||||
const pathSegments = currentPath.split('/').filter(Boolean);
|
||||
|
||||
// Check if we're on a language-specific path
|
||||
const supportedLanguages = ['en', 'nl', 'de', 'fr'];
|
||||
const isLangPath = supportedLanguages.includes(pathSegments[0]);
|
||||
|
||||
// Extract the page path without language
|
||||
let pagePath = '';
|
||||
if (isLangPath && pathSegments.length > 1) {
|
||||
// If we're on a language-specific path, get everything after the language code
|
||||
pagePath = `/${pathSegments.slice(1).join('/')}`;
|
||||
} else if (!isLangPath && pathSegments.length > 0) {
|
||||
// If we're not on a language-specific path, use the current path
|
||||
pagePath = `/${pathSegments.join('/')}`;
|
||||
}
|
||||
|
||||
// Handle special case for root path
|
||||
const isRootPath = pathSegments.length === 0 || (isLangPath && pathSegments.length === 1);
|
||||
|
||||
// Construct the new URL
|
||||
let newUrl = isRootPath ? `/${lang}` : `/${lang}${pagePath}`;
|
||||
|
||||
// Append hash fragment if it exists
|
||||
if (currentHash) {
|
||||
newUrl += currentHash;
|
||||
}
|
||||
|
||||
// Navigate to the new URL
|
||||
window.location.href = newUrl;
|
||||
});
|
||||
});
|
||||
|
||||
// Update URL info when hash changes
|
||||
window.addEventListener('hashchange', updateUrlInfo);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user