29 | var textTranslation = {
30 | "nav-game": {
31 | en: `Game`,
32 |
33 | bg: `Игра`,
34 | },
35 |
36 | "nav-singleplayer": {
37 | en: `Single Player`,
38 | bg: `Самостоятелна игра`,
39 | },
40 |
41 | "nav-multiplayer": {
42 | en: `Multiplayer`,
43 |
44 | bg: `Игра с приятел`,
45 | },
46 |
47 | "nav-rules": {
48 | en: `Rules`,
49 |
50 | bg: `Правила`,
51 | },
52 |
53 | "nav-about": {
54 | en: `About`,
55 |
56 | bg: `Информация`,
57 | },
58 |
59 | "nav-about-team": {
60 | en: `About Team`,
61 |
62 | bg: `За отбора`,
63 | },
64 |
65 | "nav-about-project": {
66 | en: `About Project`,
67 |
68 | bg: `За проекта`,
69 | },
70 |
71 | "nav-documentation": {
72 | en: `Documentation`,
73 |
74 | bg: `Документация`,
75 | },
76 |
77 | "nav-language": {
78 | en: `Language`,
79 |
80 | bg: `Език`,
81 | },
82 |
83 | "btn-en": {
84 | en: `English`,
85 |
86 | bg: `Английски`,
87 | },
88 |
89 | "btn-bg": {
90 | en: `Bulgarian`,
91 |
92 | bg: `Български`,
93 | },
94 |
95 | "nav-contact": {
96 | en: `Contact`,
97 |
98 | bg: `Контакт`,
99 | },
100 |
101 | "welcome-text": {
102 | en: `Welcome to Bletchley Game`,
103 |
104 | bg: `Добре дошли в Bletchley Game`,
105 | },
106 |
107 | "team-text": {
108 | en: `By Team Crypto Zargan`,
109 |
110 | bg: `От отбор Крипто Зарган`,
111 | },
112 |
113 | "index-singleplayer": {
114 | en: `Single Player`,
115 |
116 | bg: `Самостоятелна игра`,
117 | },
118 |
119 | "index-multiplayer": {
120 | en: `Multiplayer`,
121 |
122 | bg: `Игра с приятел`,
123 | },
124 |
125 | "index-story": {
126 | en: `Some Magic`,
127 |
128 | bg: `Магия`,
129 | },
130 |
131 | contact: {
132 | en: `Contact Page`,
133 |
134 | bg: `Страница за контакт`,
135 | },
136 |
137 | aboutTeam: {
138 | en: `About Team Page`,
139 |
140 | bg: `Страница за отбора`,
141 | },
142 |
143 | aboutProject: {
144 | en: `About Project Page`,
145 |
146 | bg: `Страница за проекта`,
147 | },
148 |
149 | singleplayer: {
150 | en: `Single Player Mode`,
151 |
152 | bg: `Самостоятелна игра`,
153 | },
154 |
155 | play: {
156 | en: `Play`,
157 |
158 | bg: `Играй`,
159 | },
160 |
161 | "diff-easy": {
162 | en: `Easy`,
163 |
164 | bg: `Лесно`,
165 | },
166 |
167 | "diff-med": {
168 | en: `Medium`,
169 |
170 | bg: `Нормално`,
171 | },
172 |
173 | "diff-hard": {
174 | en: `Hard`,
175 |
176 | bg: `Трудно`,
177 | },
178 |
179 | level1: {
180 | en: `You completed level 1. Are you ready to continue?`,
181 |
182 | bg: `Ти мина първото ниво. Готов ли си да продължиш?`,
183 | },
184 |
185 | "next-level": {
186 | en: `Next Task`,
187 |
188 | bg: `Следваща мисия`,
189 | },
190 |
191 | ff: {
192 | en: `Surrender`,
193 |
194 | bg: `Предаване`,
195 | },
196 |
197 | home: {
198 | en: `Home`,
199 |
200 | bg: `Начална страница`,
201 | },
202 |
203 | "play-again": {
204 | en: `Play Again`,
205 |
206 | bg: `Играй отново`,
207 | },
208 |
209 | win: {
210 | en: `You win!`,
211 |
212 | bg: `Ти печелиш!`,
213 | },
214 |
215 | lose: {
216 | en: `You lose!`,
217 |
218 | bg: `Ти загуби!`,
219 | },
220 |
221 | "guessed-digi": {
222 | en: `Guessed Digits`,
223 |
224 | bg: `Познати числа`,
225 | },
226 |
227 | "guessed-pos": {
228 | en: `Guessed Positions`,
229 |
230 | bg: `Познати позиции`,
231 | },
232 |
233 | "guessed-num": {
234 | en: `Number`,
235 |
236 | bg: `Число`,
237 | },
238 |
239 | opening: {
240 | en: `Multiplayer Mode`,
241 |
242 | bg: `Игра с приятел`,
243 | },
244 |
245 | winner: {
246 | en: `British wins!`,
247 |
248 | bg: `Британеца печели!`,
249 | },
250 |
251 | create: {
252 | en: `Create Game`,
253 |
254 | bg: `Създай игра`,
255 | },
256 |
257 | join: {
258 | en: `Join Game`,
259 |
260 | bg: `Присъедини се в игра`,
261 | },
262 |
263 | "send-code": {
264 | en: `Send this code to your friend and play together`,
265 |
266 | bg: `Прати кода на твоя приятел и играйте заедно`,
267 | },
268 |
269 | username: {
270 | en: `Username:`,
271 |
272 | bg: `Потребителско име:`,
273 | },
274 |
275 | role: {
276 | en: `Role:`,
277 |
278 | bg: `Роля:`,
279 | },
280 |
281 | german: {
282 | en: `German`,
283 |
284 | bg: `Германец`,
285 | },
286 |
287 | british: {
288 | en: `British`,
289 |
290 | bg: `Британец`,
291 | },
292 |
293 | ID: {
294 | en: `Game ID:`,
295 |
296 | bg: `Идентификатор на играта:`,
297 | },
298 |
299 | "guess-code": {
300 | en: `Guess Code`,
301 |
302 | bg: `Познай кода`,
303 | },
304 |
305 | "create-code": {
306 | en: `Create code`,
307 |
308 | bg: `Създай кода`,
309 | },
310 |
311 | code: {
312 | en: `Code: `,
313 |
314 | bg: `Код: `,
315 | },
316 |
317 | table1: {
318 | en: `Guessed Digits`,
319 |
320 | bg: `Познати цифри`,
321 | },
322 |
323 | table2: {
324 | en: `Guessed Positions`,
325 |
326 | bg: `Познати позиции`,
327 | },
328 |
329 | table3: {
330 | en: `Number`,
331 |
332 | bg: `Число`,
333 | },
334 |
335 | "level1-win": {
336 | en: `Congratulations you completed level 1`,
337 |
338 | bg: `Поздравления ти завърши първо ниво`,
339 | },
340 |
341 | "wait-level2": {
342 | en: `Waiting for your friend to start level 2`,
343 |
344 | bg: `Изчакай приятеля си да стартира второ ниво`,
345 | },
346 |
347 | "wait-create-code": {
348 | en: `Waiting for your friend to create the code`,
349 |
350 | bg: `Изчакай приятеля си да напише кода`,
351 | },
352 |
353 | "wait-start-game": {
354 | en: `Waiting for your friend to start the game`,
355 |
356 | bg: `Изчакай приятеля си да стартира игра`,
357 | },
358 |
359 | download: {
360 | en: `Download the full rules here`,
361 |
362 | bg: `Изтегли правилата от тук`,
363 | },
364 |
365 | "single-rules": {
366 | en: `In the single player mode of the game you play against the computer. To find out the coordinates of the enemy battleships
367 | you have to crack 2 codes - generated by a computer. <b>The numbers must be with the numbers form 0 to 7 including.</b>
368 | There are 3 difficulties:
369 | <ul>
370 | <li class="text-primary">Easy - You have to crack a 3-number code</li>
371 | <li style="color:#db7e32";>Medium - You have to crack a 4-number code </li>
372 | <li class="text-danger">Hard - You have to crack a 5-number code</li>
373 | </ul>
374 | There are also 2 tasks:
375 | <ul>
376 | <li> First task – On the first task the numbers cannot be repeated</li>
377 | <li>Second task – On the second task the numbers can be repeated. </li>
378 | </ul>
379 | <strong>You have 13 attempts</strong> to guess the number, otherwise you lose.`,
380 |
381 | bg: `Във самостоятелния режим на играта вие играете срещу компютър. За да разберете
382 | координатите на вражеския кораб трябва да разбиете 2 кода, които са генерирани от компютър.
383 | <b>Цифрите на кода са между 0 и 7 включително.</b>
384 | Играта има 3 нива на трудност:
385 | <ul>
386 | <li class="text-primary">Лесно - Трябва да се разбие 3-цифрен код</li>
387 | <li style="color:#db7e32";>Средно - Трябва да се разбие 4-цифрен код</li>
388 | <li class="text-danger">Трудно - Трябва да се разбие 5-цифрен код</li>
389 | </ul>
390 | Във 2-те задачи кодовете ще бъдат генерирани по различен начин.
391 | <ul>
392 | <li>Първа задача - Кодът <b>не може</b> да има повтарящи се чифри.</li>
393 | <li>Втора задача - Кодът <b>може</b> да има повтарящи се чифри.</li>
394 | </ul>
395 | <strong>Имате 13 опита</strong>, за да познаете координатите на вражеския кораб, в противен случай ще загубите.`,
396 | },
397 |
398 | "multi-rules": {
399 | en: ` In the multiplayer mode of the game 2 people can play against each other.<br> One person creates a room and
400 | gives the code that was given to him so that the other one can join it. <b>The numbers must be with the numbers form 0 to 7 including.</b> <br>The person who creates the
401 | room can
402 | choose his role. There are 2 different roles:
403 | <ul>
404 | <li class="text-danger">German – If you choose to be German you create the code. Your task is the code
405 | to be hard so that the British cannot defeat you easy.</li>
406 | <li class="text-primary">British – Or if you choose to be the British you are guessing the code that was
407 | created by the German.<strong> You have 13 attempts</strong> to guess the code.</li>
408 | </ul>
409 | There are also 2 tasks:
410 | <ul>
411 | <li> First task – On the first task the numbers<b> cannot</b> be repeated</li>
412 | <li> Second task – On the second task the numbers<b> can</b> be repeated. </li>
413 | </ul>`,
414 |
415 | bg: `В груповия режима на играта 2-ма човека вие може ад играете един срещу друг. Единия от двамата прави стая и дава
416 | кода за нея на другия, койото го въвжеда
417 | Този който прави стаята може да си избере каква роля да е, а другият ще е другата.
418 | Двете различни роли на играта са:
419 | <ul>
420 | <li class="text-danger">Германец - Ако изберете да сте германец, ролята ви е да създадете кода, който трябва да
421 | бъде възможно най-труден, за да може вашият кораб да не бъде разбит</li>
422 | <li class="text-primary">Британец - Ако изберете да сте британец, ролята ви е да разбиете кода създаден от
423 | германеца. Така вие ще унищожите неговият кораб</li>
424 | </ul>
425 | Кода който създава германеца <b>трябва да е с цифрите от 0 до 7 включително.</b> Има и 2 различни задачи, които имат следните условия:
426 | <ul>
427 | <li>Първа задача - Кодът <b>не може</b> да има повтарящи се чифри.</li>
428 | <li>Втора задача - Кодът <b>може</b> да има повтарящи се чифри.</li>
429 | </ul>`,
430 | },
431 |
432 | rules: {
433 | en: `Rules`,
434 |
435 | bg: `Правила`,
436 | },
437 |
438 | "start-game": {
439 | en: `Start Game`,
440 |
441 | bg: `Стартирай играта`,
442 | },
443 | };
444 |
445 | var currentLanguage = "en";
446 |
447 | /**
448 | * Replaces the text on the page with the chosen language.
449 | *
450 | * @param {string} item The item that has to be replaced.
451 | * @param {string} text The text that the item is going to be replaced with.
452 | */
453 | function replaceElementText(item, text) {
454 | if (!item.is("button")) {
455 | item.html(text);
456 | } else {
457 | item.text(text);
458 | }
459 | }
460 |
461 | /**
462 | * Translates the elements with the data-lang attribute.
463 | *
464 | * @param {string} langId The identificator of the language (bg/en).
465 | */
466 | function translateLabel(langId) {
467 | console.log(langId);
468 | currentLanguage = langId;
469 |
470 | // Gets all tags that have 'data-lang' attribute present
471 | $("[data-lang]").each(function () {
472 | let item = $(this);
473 | if (
474 | textTranslation.hasOwnProperty(item.data("lang")) &&
475 | textTranslation[item.data("lang")].hasOwnProperty(langId)
476 | ) {
477 | let text = textTranslation[item.data("lang")][langId];
478 | replaceElementText(item, text);
479 | } else {
480 | replaceElementText(
481 | item,
482 | "<font color='red'>" + item.data("lang") + "</font>"
483 | );
484 | }
485 | });
486 | }
487 |
488 | /**
489 | * Gets the translated elements.
490 | *
491 | * @param {string} elementId The element's Id.
492 | * @return {string} textTranslation The translated text.
493 | */
494 | function getTranslatedText(elementId) {
495 | return textTranslation[elementId][currentLanguage];
496 | }
497 |
498 |
499 |