Skip to content

Commit

Permalink
feat: 🎸 Adjusted translation system to support directories
Browse files Browse the repository at this point in the history
✅ Closes: #54
  • Loading branch information
MadejaMaciej committed Mar 23, 2024
1 parent 14be7b6 commit c4ca655
Show file tree
Hide file tree
Showing 182 changed files with 567 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Lost Dutchman Mine Change Log
0.0.3 April 7, 2024
-------------------

- Enh #54: Adjust translation system (MadejaMaciej)
- Enh #83: Turn off double click. (MadejaMaciej)
- Enh #84: Do not let players resize window under certain size. (MadejaMaciej)
- Enh #81: Add new languages and correct old ones if code is off. (MadejaMaciej)
Expand Down
4 changes: 1 addition & 3 deletions code-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"scripts": {
"dev": "electron-forge start",
"package": "electron-forge package",
"build:windows": "electron-forge package -- --platform win32",
"build:mac": "electron-forge package -- --platform darwin",
"build:unix": "electron-forge package -- --platform linux",
"build": "electron-forge make",
"publish": "electron-forge publish",
"test": "jest",
"test:coverage": "jest --coverage",
Expand Down
12 changes: 6 additions & 6 deletions code-desktop/src/components/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback, useMemo } from "react";
import React, { useState, useEffect, useCallback } from "react";
import { v4 } from "uuid";
import Menu from "./ui/Menu";
import PauseScreen from "./ui/PauseScreen";
Expand Down Expand Up @@ -30,7 +30,7 @@ function Main() {
uuid: v4(),
saveName: '',
location: 'town',
backgroundAlt: setText('bgTown'),
backgroundAlt: 'bgTown',
playerPosition: {
x: player.getX(),
y: player.getY()
Expand Down Expand Up @@ -68,7 +68,7 @@ function Main() {
const stringifiedGames = JSON.stringify(games);
window.localStorage.setItem('saved-games', stringifiedGames);
} catch(e) {
setError(setText('couldNotSave'));
setError('couldNotSave');
}
} else {
// If there are no saved games, create new array and add new game to it
Expand All @@ -83,7 +83,7 @@ function Main() {

// If there are no saved games, show error message
if (!gamesToLoad) {
setError(setText('couldNotLoad'));
setError('couldNotLoad');
return;
}

Expand All @@ -101,7 +101,7 @@ function Main() {
}
})
} catch(e) {
setError(setText('fileCorrupted'));
setError('fileCorrupted');
return;
}
}, [gameState, setScreen, setError]);
Expand Down Expand Up @@ -156,7 +156,7 @@ function Main() {

useEffect(() => {
// Set document title based on language
document.title = setText('title');
document.title = 'Lost Dutchman Mine';
}, [language])

if (screen === 'splash') {
Expand Down
2 changes: 1 addition & 1 deletion code-desktop/src/components/game/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useMemo, useRef, useEffect, useCallback } from "react";
import React, { useState, useMemo, useRef, useEffect } from "react";
import GameMenu from "../ui/GameMenu";
import PauseScreen from "../ui/PauseScreen";
import { mainLoop } from "../../services/game";
Expand Down
2 changes: 1 addition & 1 deletion code-desktop/src/components/ui/GameTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function GameTitle() {
return (
<div>
<h2>
{setText('title')}
{'Lost Dutchman Mine'}
</h2>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion code-desktop/src/components/ui/Language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Language({ language, setLanguage }: LanguageProps) {

return (
<>
<label htmlFor="language" className="white">{setText('language')}</label>
<label htmlFor="language" className="white">{'Language'}</label>
<select name="language" onChange={(e) => chooseAndSaveLanguage(e.target.value)} value={language}>
<option value={'en'}>EN</option>
<option value={'pl'}>PL</option>
Expand Down
6 changes: 3 additions & 3 deletions code-desktop/src/components/ui/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ function Menu({ setScreen, language, setLanguage }: MenuProps) {

return (
<div>
<Title classes="center white" text={setText('mainMenu')} />
<Title classes="center white" text={'Main Menu'} />
<Language language={language} setLanguage={setLanguage} />
<MenuButton clickHandler={startNewGame} text={setText('startGame')} />
<MenuButton clickHandler={startNewGame} text={'Start Game'} />
<MenuButton clickHandler={loadGames} text={'Load game'} />
<MenuButton clickHandler={quitGame} text={setText('quitGame')} />
<MenuButton clickHandler={quitGame} text={'Quit game'} />
</div>
)
}
Expand Down
29 changes: 22 additions & 7 deletions code-desktop/src/context/language.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import english from "../language/en.json";
import polish from "../language/pl.json";
import english from "../language/en";
import polish from "../language/pl";
import german from "../language/de";
import spanish from "../language/es";
import french from "../language/fr";
import italian from "../language/it";
import silesian from "../language/sx";
import hindi from "../language/hi";
import ukrainian from "../language/uk";

const languageContext: any = {
en: english,
pl: polish,
de: german,
es: spanish,
fr: french,
it: italian,
sx: silesian,
hi: hindi,
uk: ukrainian
}

export const setText = (text: string) => {
export const setText = (directory: string, text: string) => {
const lang = window.localStorage.getItem('language') || 'en';
if (!languageContext[lang]) {
return languageContext.en[text];
}

return languageContext[lang][text] || languageContext.en[text];
if (!languageContext[lang] || !languageContext[lang][directory]) {
return languageContext.en[directory][text];
}

return languageContext[lang][directory][text] || languageContext.en[directory][text];
}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/sx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/assay/uk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/sx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/bank/uk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/sx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/credits/uk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
41 changes: 41 additions & 0 deletions code-desktop/src/language/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import assay from "./assay/de.json";
import bank from "./bank/de.json";
import credits from "./credits/de.json";
import doctor from "./doctor/de.json";
import end from "./end/de.json";
import events from "./events/de.json";
import health from "./health/de.json";
import jail from "./jail/de.json";
import mercantile from "./mercantile/de.json";
import mines from "./mines/de.json";
import newspaper from "./newspaper/de.json";
import options from "./options/de.json";
import other from "./other/de.json";
import river from "./river/de.json";
import saloon from "./saloon/de.json";
import stable from "./stable/de.json";
import startup from "./startup/de.json";
import time from "./time/de.json";

const lang = {
assay,
bank,
credits,
doctor,
end,
events,
health,
jail,
mercantile,
mines,
newspaper,
options,
other,
river,
saloon,
stable,
startup,
time
}

export default lang;
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/sx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/doctor/uk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
12 changes: 0 additions & 12 deletions code-desktop/src/language/en.json

This file was deleted.

41 changes: 41 additions & 0 deletions code-desktop/src/language/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import assay from "./assay/en.json";
import bank from "./bank/en.json";
import credits from "./credits/en.json";
import doctor from "./doctor/en.json";
import end from "./end/en.json";
import events from "./events/en.json";
import health from "./health/en.json";
import jail from "./jail/en.json";
import mercantile from "./mercantile/en.json";
import mines from "./mines/en.json";
import newspaper from "./newspaper/en.json";
import options from "./options/en.json";
import other from "./other/en.json";
import river from "./river/en.json";
import saloon from "./saloon/en.json";
import stable from "./stable/en.json";
import startup from "./startup/en.json";
import time from "./time/en.json";

const lang = {
assay,
bank,
credits,
doctor,
end,
events,
health,
jail,
mercantile,
mines,
newspaper,
options,
other,
river,
saloon,
stable,
startup,
time
}

export default lang;
1 change: 1 addition & 0 deletions code-desktop/src/language/end/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/sx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/end/uk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
41 changes: 41 additions & 0 deletions code-desktop/src/language/es.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import assay from "./assay/es.json";
import bank from "./bank/es.json";
import credits from "./credits/es.json";
import doctor from "./doctor/es.json";
import end from "./end/es.json";
import events from "./events/es.json";
import health from "./health/es.json";
import jail from "./jail/es.json";
import mercantile from "./mercantile/es.json";
import mines from "./mines/es.json";
import newspaper from "./newspaper/es.json";
import options from "./options/es.json";
import other from "./other/es.json";
import river from "./river/es.json";
import saloon from "./saloon/es.json";
import stable from "./stable/es.json";
import startup from "./startup/es.json";
import time from "./time/es.json";

const lang = {
assay,
bank,
credits,
doctor,
end,
events,
health,
jail,
mercantile,
mines,
newspaper,
options,
other,
river,
saloon,
stable,
startup,
time
}

export default lang;
1 change: 1 addition & 0 deletions code-desktop/src/language/events/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/hi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/sx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions code-desktop/src/language/events/uk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit c4ca655

Please sign in to comment.