Changed around line 1
+ const newsContainer = document.querySelector('.news-container');
+ const loading = document.querySelector('.loading');
+ const langEnBtn = document.getElementById('lang-en');
+ const langCnBtn = document.getElementById('lang-cn');
+
+ let currentLanguage = 'en';
+
+ // Fetch news from multiple sources
+ async function fetchNews() {
+ try {
+ // Replace with actual API endpoints
+ const response = await fetch('/api/news');
+ const data = await response.json();
+ displayNews(data);
+ } catch (error) {
+ console.error('Error fetching news:', error);
+ loading.textContent = 'Failed to load news. Please try again later.';
+ }
+ }
+
+ function displayNews(newsItems) {
+ loading.style.display = 'none';
+ newsContainer.innerHTML = newsItems.slice(0, 20).map(item => `
+
${item.title}
+ Read more
+
+
+ `).join('');
+ }
+
+ function translateContent(language) {
+ // Implement translation logic here
+ // This would involve sending text to a translation API
+ // and updating the content accordingly
+ console.log(`Switching to ${language}`);
+ }
+
+ langEnBtn.addEventListener('click', () => {
+ if (currentLanguage !== 'en') {
+ currentLanguage = 'en';
+ langEnBtn.classList.add('active');
+ langCnBtn.classList.remove('active');
+ translateContent('en');
+ }
+ });
+
+ langCnBtn.addEventListener('click', () => {
+ if (currentLanguage !== 'cn') {
+ currentLanguage = 'cn';
+ langCnBtn.classList.add('active');
+ langEnBtn.classList.remove('active');
+ translateContent('cn');
+ }
+ });
+
+ // Initial load
+ fetchNews();