Added a choices translation selector

Added the ability to select a translation of choices
This commit is contained in:
MxShift 2023-02-25 01:02:39 +06:00
parent d84fa0fd06
commit a4f6d03137
2 changed files with 37 additions and 13 deletions

View file

@ -35,30 +35,35 @@ var segmentGroups = bv.segmentGroups;
// Transation of choices // Transation of choices
var moments = JSON.parse(JSON.stringify(momentsBySegment)); var moments = JSON.parse(JSON.stringify(momentsBySegment));
var translated_choices = ru; var translated_choices = en;
for (var key in translated_choices) { function switch_choices() {
for (var i = 0; i < Object.keys(moments[key]).length; i++) { for (var key in translated_choices) {
if ("choices" in moments[key][i]) { for (var i = 0; i < Object.keys(moments[key]).length; i++) {
for (var k = 0; k < Object.keys(moments[key][i]["choices"]).length; k++) { if ("choices" in moments[key][i]) {
if ("id" in moments[key][i]["choices"][k]) { for (var k = 0; k < Object.keys(moments[key][i]["choices"]).length; k++) {
if (moments[key][i]["choices"][k]['id'] in translated_choices[key]) { if ("id" in moments[key][i]["choices"][k]) {
moments[key][i]["choices"][k]['text'] = translated_choices[key][moments[key][i]["choices"][k]["id"]]; if (moments[key][i]["choices"][k]['id'] in translated_choices[key]) {
moments[key][i]["choices"][k]['text'] = translated_choices[key][moments[key][i]["choices"][k]["id"]];
}
} }
} }
} }
} }
} }
return moments;
} }
momentsBySegment = moments; // momentsBySegment = moments;
// Get translations from bandersnatch.js // Get translations from bandersnatch.js

View file

@ -38,6 +38,7 @@
<meta name="keywords" content="Bandersnatch,Bandersnatch Interactive Player,Interactive Player,watch," /> <meta name="keywords" content="Bandersnatch,Bandersnatch Interactive Player,Interactive Player,watch," />
<script src="assets/bandersnatch.js"></script> <script src="assets/bandersnatch.js"></script>
<script src="assets/choices/ru.js"></script> <script src="assets/choices/ru.js"></script>
<script src="assets/choices/en.js"></script>
<script src="assets/SegmentMap.js"></script> <script src="assets/SegmentMap.js"></script>
<script src="assets/scripts.js"></script> <script src="assets/scripts.js"></script>
<script> <script>
@ -47,6 +48,7 @@
reset(); reset();
} }
</script> </script>
<link rel="stylesheet" type="text/css" href="assets/styles.css"> <link rel="stylesheet" type="text/css" href="assets/styles.css">
</head> </head>
@ -57,16 +59,23 @@
<div id="file-selector"> <div id="file-selector">
<div class="file-area"> <div class="file-area">
<div class="contact"> <div class="contact">
<div>
<span class="default">You can select translation of choices: </span>
<select id="choice-translation">
<option value="ru">Russian</option>
<option value="en" selected>English</option>
</select>
<br>
This player remembers your choices and watch history: <a
href="javascript:askReset()">Reset all</a>
</div>
<p> <p>
Authors: Authors:
<a href="https://github.com/joric/bandersnatch/">Original version</a> - <a <a href="https://github.com/joric/bandersnatch/">Original version</a> - <a
href="https://github.com/joric/">joric</a> | href="https://github.com/joric/">joric</a> |
Web page, subtitles - <a href="https://github.com/mehotkhan">Mehotkhan</a> | Web page, subtitles - <a href="https://github.com/mehotkhan">Mehotkhan</a> |
Many fixes, improvements, and everything else - <a Many fixes, improvements, and everything else - <a
href="https://github.com/CyberShadow">CyberShadow</a> href="https://github.com/CyberShadow">CyberShadow</a>
<br>
This player remembers your choices and watch history. <a
href="javascript:askReset()">Click here to reset and start from scratch.</a>
</p> </p>
</div> </div>
<input id="fileinput" type="file"> <input id="fileinput" type="file">
@ -163,4 +172,14 @@
</div> </div>
</body> </body>
<script>
var select = document.getElementById('choice-translation');
select.addEventListener('change',(e)=>{
translated_choices = window[select.value];
console.log(select.value);
// console.log(translated_choices);
momentsBySegment = switch_choices();
})
</script>
</html> </html>