Skip to content

Commit

Permalink
refactor: generate locale options from object
Browse files Browse the repository at this point in the history
  • Loading branch information
puppy-girl committed Sep 22, 2024
1 parent 095bf95 commit 12cf98e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ If desired, include your modworkshop username in your pull request to be added t

To contribute localisations:
1. in the `lang` directory, duplicate `en.json`, rename it to your language's language code, and translate the value of each key
2. in `index.html`, under the `<select>` element, create a new `<option>` above uwu with a value matching your new localisation file
2. in `localisation.js`, add your locale to the `supportedLocales` object above `uwu`

### importing weapon data:
1. Open Payday 3's files in FModel
Expand Down
9 changes: 1 addition & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ <h1 data-localisation-key="title">Payday 3 Weapon Bench</h1>
d="m10.5 21 5.25-11.25L21 21m-9-3h7.5M3 5.621a48.474 48.474 0 0 1 6-.371m0 0c1.12 0 2.233.038 3.334.114M9 5.25V3m3.334 2.364C11.176 10.658 7.69 15.08 3 17.502m9.334-12.138c.896.061 1.785.147 2.666.257m-4.589 8.495a18.023 18.023 0 0 1-3.827-5.802"
/>
</svg>
<select name="locale-switcher" id="locale-switcher">
<option value="en">English</option>
<option value="cn">简体中文</option>
<option value="tr">Türkçe</option>
<option value="ru">Русский</option>
<option value="pl">Polski</option>
<option value="uwu">uwu</option>
</select>
<select name="locale-switcher" id="locale-switcher"></select> </select>
</div>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,14 @@ document.addEventListener('DOMContentLoaded', async () => {

const localeSwitcher = document.querySelector('#locale-switcher');

for (const locale in supportedLocales) {
const option = localeSwitcher.appendChild(
document.createElement('option')
);
option.value = locale;
option.textContent = supportedLocales[locale];
}

localeSwitcher.value = currentLocale;

localeSwitcher.onchange = (event) => {
Expand Down
12 changes: 10 additions & 2 deletions scripts/localisation.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
const defaultLocale = 'en';
const supportedLocales = ['en', 'cn', 'tr', 'ru', 'pl'];

const supportedLocales = {
en: 'English',
cn: '简体中文',
tr: 'Türkçe',
ru: 'Русский',
pl: 'Polski',
uwu: 'uwu',
};

let currentLocale = defaultLocale;

if (localStorage.getItem('locale')) {
const storedLocale = localStorage.getItem('locale');

if (!supportedLocales.includes(storedLocale)) {
if (!Object.keys(supportedLocales).includes(storedLocale)) {
localStorage.removeItem('locale');
} else {
currentLocale = localStorage.getItem('locale');
Expand Down

0 comments on commit 12cf98e

Please sign in to comment.