-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d82e57c
commit fe6b249
Showing
8 changed files
with
180 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,17 @@ <h2 data-translation-key="file-upload-dialog-opened.h2"></h2> | |
</div> | ||
<div class="blur"></div> | ||
<div class="credits-overlay"> | ||
<div class="github-link"> | ||
<div class="github-link corner-link"> | ||
<a href="https://github.com/anotherpillow/xnb2cp" target="_blank"> | ||
<i class="fa-brands fa-github"></i> | ||
</a> | ||
</div> | ||
|
||
<div class="language-btn corner-link"> | ||
<button> | ||
<i class="fa-solid fa-globe"></i> | ||
</button> | ||
</div> | ||
|
||
<div class="background-credits"> | ||
<p data-translation-key="background-credits.p"></p> | ||
|
@@ -131,11 +137,16 @@ <h2 data-translation-key="files.h2"></h2> | |
</div> | ||
</div> | ||
|
||
<div id="language-popup" class="hidden"> | ||
<h2 data-translation-key="language.h2"></h2> | ||
<ul id="languages"></ul> | ||
</div> | ||
|
||
<!-- import https://unpkg.com/[email protected]/dist/FileSaver.js as FileSaver --> | ||
<script type="module" src="src/translations.js"></script> | ||
<script src="src/translations.js"></script> | ||
<script type="module" src="src/imports.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/jszip.js"></script> | ||
<script src="src/script.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/FileSaver.js"></script> | ||
<script src="src/script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
const supported_languages = { | ||
'en': { | ||
"flag": "🇬🇧" | ||
}, | ||
'de': { | ||
"flag": "🇩🇪" | ||
}, | ||
'pl': { | ||
"flag": "🇵🇱" | ||
}, | ||
'ru': { | ||
"flag": "🇷🇺" | ||
}, | ||
} | ||
|
||
const lang = navigator.language.split('-')[0] | ||
const translations = await new Promise(async (resolve, reject) => { | ||
const url1 = `/i18n/${lang}.json` | ||
const url2 = '/i18n/en.json'; | ||
|
||
try { | ||
const response1 = await fetch(url1); | ||
|
||
window.loadTranslations = async (_lang = lang) => { | ||
const translations = await new Promise(async (resolve, reject) => { | ||
const url1 = `/i18n/${_lang}.json` | ||
const url2 = '/i18n/en.json'; | ||
|
||
if (response1.ok) { | ||
// If the first URL exists, return its JSON content | ||
resolve(await response1.json()) | ||
return; | ||
if (lang in supported_languages) { | ||
const response1 = await fetch(url1); | ||
|
||
if (response1.ok) { | ||
// If the first URL exists, return its JSON content | ||
resolve(await response1.json()) | ||
return; | ||
} | ||
} else { | ||
const response2 = await fetch(url2); | ||
|
||
if (response2.ok) { | ||
resolve(await response2.json()) | ||
return; | ||
} | ||
} | ||
} catch (error) { | ||
// An error occurred while fetching the first URL | ||
console.error(error); | ||
} | ||
|
||
try { | ||
const response2 = await fetch(url2); | ||
|
||
reject(null) | ||
|
||
}) | ||
|
||
if (response2.ok) { | ||
resolve(await response2.json()) | ||
return; | ||
console.log(translations) | ||
document.querySelectorAll('[data-translation-key]').forEach(el => { | ||
const key = el.getAttribute('data-translation-key') | ||
const translation = translations[key] | ||
if (key.includes('placeholder-value')) { | ||
el.setAttribute('placeholder', translation) | ||
el.value = translation | ||
} else if (key.includes('value')) { | ||
el.value = translation | ||
} else { | ||
el.innerHTML = translation | ||
} | ||
} catch (error) { | ||
alert('Failed to load both local translations and English.') | ||
reject(null) | ||
} | ||
}) | ||
|
||
}) | ||
} | ||
|
||
console.log(translations) | ||
document.querySelectorAll('[data-translation-key]').forEach(el => { | ||
const key = el.getAttribute('data-translation-key') | ||
const translation = translations[key] | ||
if (key.includes('placeholder-value')) { | ||
el.setAttribute('placeholder', translation) | ||
el.value = translation | ||
} else if (key.includes('value')) { | ||
el.value = translation | ||
} else { | ||
el.innerHTML = translation | ||
} | ||
|
||
}) | ||
loadTranslations() |