Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
philffm committed Nov 18, 2024
1 parent efa4c11 commit a506f64
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 23 deletions.
92 changes: 70 additions & 22 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,79 @@
async function loadContent(lang = 'en') {
try {
let translations;
if (lang === 'en') {
const response = await fetch('translations.json');
if (!response.ok) {
throw new Error('Failed to load default content');
}
translations = await response.json();
data = translations.content;
} else {
const response = await fetch(`lang/${lang}.json`);
if (!response.ok) {
throw new Error(`Failed to load language file: ${lang}`);
}
data = await response.json();

// Check if aisummary exists, if not, load from en.json
if (!data.aisummary) {
const enResponse = await fetch('lang/en.json');
if (!enResponse.ok) {
throw new Error('Failed to load English language file for aisummary');
}
const enData = await enResponse.json();
data.aisummary = enData.aisummary;
const languageMap = {
'en': 'en',
'en-US': 'en',
'en-GB': 'en',
'es': 'es',
'es-ES': 'es',
'es-MX': 'es',
'de': 'de',
'de-DE': 'de',
'fr': 'fr',
'fr-FR': 'fr',
'it': 'it',
'it-IT': 'it',
'pt': 'pt',
'pt-PT': 'pt',
'pt-BR': 'pt',
'nl': 'nl',
'nl-NL': 'nl',
'ru': 'ru',
'ru-RU': 'ru',
'ua': 'ua',
'uk-UA': 'ua',
'pl': 'pl',
'pl-PL': 'pl',
'sv': 'sv',
'sv-SE': 'sv',
'da': 'da',
'da-DK': 'da',
'ja': 'jp',
'ja-JP': 'jp',
'zh': 'cn',
'zh-CN': 'cn',
'zh-Hans-CN': 'cn',
'zh-TW': 'cn',
'ko': 'kr',
'ko-KR': 'kr',
'hi': 'hi',
'hi-IN': 'hi',
'mr': 'hi',
'mr-IN': 'hi',
'th': 'th',
'th-TH': 'th',
'id': 'ind-bahasa',
'id-ID': 'ind-bahasa',
'ar': 'ar',
'ar-SA': 'ar',
'tr': 'tr',
'tr-TR': 'tr',
'bg': 'bg',
'bg-BG': 'bg',
'ro': 'ro',
'ro-RO': 'ro'
};

// Use the mapped language code or default to English
const mappedLang = languageMap[lang] || 'en';

const response = await fetch(`lang/${mappedLang}.json`);
if (!response.ok) {
throw new Error(`Failed to load language file: ${mappedLang}`);
}
data = await response.json();

if (!data.aisummary) {
const enResponse = await fetch('lang/en.json');
if (!enResponse.ok) {
throw new Error('Failed to load English language file for aisummary');
}
const enData = await enResponse.json();
data.aisummary = enData.aisummary;
}

// Update the page content with the loaded data
document.getElementById('metaTitle').textContent = data.title;
document.getElementById('metaDescription').setAttribute('content', data.aboutText);

Expand Down
2 changes: 1 addition & 1 deletion translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
},
{
"code": "bg",
"name": "Ъългарски",
"name": "Ъливки",
"emoji": "🇧🇬"
},
{
Expand Down

0 comments on commit a506f64

Please sign in to comment.