Skip to content

Commit

Permalink
Changed the way translation arrays are loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
METROKOP228 committed Nov 2, 2024
1 parent b8c6f3e commit cbd9d81
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 53 deletions.
74 changes: 28 additions & 46 deletions js/arrays_config.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,46 @@
let javaVer = "1.21.3";
var jeVer = '1.21.3'
var jeVer2 = '1.21.3'

function getSelectValue() {
const selectedValue = document.getElementById('version-choice-java').value;
// Тепер змінна selectedValue містить вибране значення
fileFetch(`https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/java/${selectedValue}.txt`)
const translations_java = {};
var java_vers = Array.from(document.getElementById("version-choice-java").options).map(option => option.value);
for (let verJ of java_vers) {
fileFetch(`https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/java/${verJ}.txt`)
.then(data => {
translations_java = data;
translations_java[verJ] = data;
})
.catch(error => {
console.error('Error fetching file translations_java:', error);
});

const selectedValue2 = document.getElementById('version-choice-java2').value;
// Тепер змінна selectedValue містить вибране значення
fileFetch(`https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/java/${selectedValue2}.txt`)
.then(data => {
translations_java2 = data;
})
.catch(error => {
console.error('Error fetching file translations_java2:', error);
console.error(`Error fetching file translations_java[${verJ}]:`, error);
});
}
document.getElementById('version-choice-java').addEventListener('change', function() {
jeVer = document.getElementById('version-choice-java').value;
});
document.getElementById('version-choice-java2').addEventListener('change', function() {
jeVer2 = document.getElementById('version-choice-java2').value;
});

document.getElementById('version-choice-java').addEventListener('change', getSelectValue);
document.getElementById('version-choice-java2').addEventListener('change', getSelectValue);

let javaUrl = `https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/java/1.21.3.txt`;
let translations_java = [];
let translations_java2 = [];

getSelectValue();

let bedrockVer = "1.21.40";
var beVer = '1.21.40'
var beVer2 = '1.21.40'

function getSelectValueBedrock() {
fileFetch(`https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/bedrock/${document.getElementById('version-choice-bedrock').value}.txt`)
const translations_bedrock = {};
var bedrock_vers = Array.from(document.getElementById("version-choice-bedrock").options).map(option => option.value);
for (let verB of bedrock_vers) {
fileFetch(`https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/bedrock/${verB}.txt`)
.then(data => {
translations_bedrock = data;
translations_bedrock[verB] = data;
})
.catch(error => {
console.error('Error fetching file translations_bedrock:', error);
});

fileFetch(`https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/bedrock/${document.getElementById('version-choice-bedrock2').value}.txt`)
.then(data => {
translations_bedrock2 = data;
})
.catch(error => {
console.error('Error fetching file translations_bedrock2:', error);
console.error(`Error fetching file translations_java[${verB}]:`, error);
});
}
document.getElementById('version-choice-bedrock').addEventListener('change', function() {
beVer = document.getElementById('version-choice-bedrock').value;
});
document.getElementById('version-choice-bedrock2').addEventListener('change', function() {
beVer2 = document.getElementById('version-choice-bedrock2').value;
});

document.getElementById('version-choice-bedrock').addEventListener('change', getSelectValueBedrock);
document.getElementById('version-choice-bedrock2').addEventListener('change', getSelectValueBedrock);

let bedrockUrl = `https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/bedrock/1.21.40.txt`;
let translations_bedrock = [];
let translations_bedrock2 = [];

getSelectValueBedrock();

const earthUrl = 'https://raw.githubusercontent.com/METROKOP228/UkMCW-templates-translation/main/files/earth/newest.txt';
let translations_earth = [];
Expand Down
14 changes: 7 additions & 7 deletions js/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function translateJava(text) {
}
}
}
for (let j = 0; j < translations_java.length; j++) {
en_uk = translations_java[j].split("=");
for (let j = 0; j < translations_java[jeVer].length; j++) {
en_uk = translations_java[jeVer][j].split("=");
if (text[i].includes(en_uk[0]) && en_uk[1] !== undefined) {
text[i] = text[i].replace(en_uk[0], en_uk[1]);
}
Expand All @@ -70,8 +70,8 @@ function translateBedrock(text) {
let en_uk = [];
try {
for (let i = 0; i < text.length; i++) {
for (let j = 0; j < translations_bedrock.length; j++) {
en_uk = translations_bedrock[j].split("=");
for (let j = 0; j < translations_bedrock[beVer].length; j++) {
en_uk = translations_bedrock[beVer][j].split("=");
if (text[i].includes(en_uk[0]) && en_uk[1] !== undefined) {
text[i] = text[i].replace(en_uk[0], en_uk[1]);
}
Expand Down Expand Up @@ -160,7 +160,7 @@ function searchMatches() {
caseSensitive = document.getElementById("cs-search").checked;
console.log(`Global: ${isGlobal}, regex: ${useRegex}, case sensitive: ${caseSensitive}`);
if (isGlobal) {
searchInArrays(translations_java2, translations_bedrock2, translations_earth, translations_legends, translations_education);
searchInArrays(translations_java[jeVer2], translations_bedrock[beVer2], translations_earth, translations_legends, translations_education);
} else {
let radioButtonsEd = document.getElementsByName('editions2');
for (let i = 0; i < radioButtonsEd.length; i++) {
Expand All @@ -169,10 +169,10 @@ function searchMatches() {
console.log(id);
switch (id) {
case 'java2':
searchInArrays(translations_java2);
searchInArrays(translations_java[jeVer2]);
break;
case 'bedrock2':
searchInArrays(undefined, translations_bedrock2);
searchInArrays(undefined, translations_bedrock[beVer2]);
break;
case 'earth2':
searchInArrays(undefined, undefined, translations_earth);
Expand Down

0 comments on commit cbd9d81

Please sign in to comment.