Skip to content

Commit 1ff18e1

Browse files
authored
Language detection/selection + russian and spanish locales (#11)
* Language detection/selection + russian and spanish locales * Fixed locale not persisting, fixed Download buttons being english only * Fixed quickstore translation
1 parent 7343b4b commit 1ff18e1

7 files changed

Lines changed: 414 additions & 11 deletions

File tree

src/AppDetails.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ class AppDetails extends Component {
111111
let dlButton;
112112

113113
if (ua.includes("Switch" || "WiiU")) {
114-
dlButton = (<button onClick={() => alert(t("noDownloadsOnThisDevice"))}>Download</button>);
114+
dlButton = (<button onClick={() => alert(t("noDownloadsOnThisDevice"))}>{t("download")}</button>);
115115
}
116116
else {
117-
dlButton = (<a target="_blank" rel="noopener noreferrer" href={`${repo}/zips/${name}.zip`}>Download</a>
117+
dlButton = (<a target="_blank" rel="noopener noreferrer" href={`${repo}/zips/${name}.zip`}>{t("download")}</a>
118118
);
119119
}
120120

src/Footer.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import React, { Component } from 'react';
22
import {init_theme, toggle_theme} from './Utils';
33
import './MainDisplay.css';
44
import { withTranslation } from 'react-i18next';
5+
import i18n from './i18n';
6+
7+
const LANGUAGES = [
8+
{ code: 'en', label: 'English' },
9+
{ code: 'ru', label: 'Русский' },
10+
{ code: 'es', label: 'Español' },
11+
];
512

613
class Footer extends Component {
7-
// on mount, set the theme
814
componentDidMount() {
915
init_theme();
1016
}
@@ -19,6 +25,15 @@ class Footer extends Component {
1925
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a className="copyright" href="/request-takedown">{t("dmca")}</a>
2026
</div>
2127
<div className="right">
28+
<select
29+
style={{fontSize: 10, padding: 4, marginRight: 8, verticalAlign: "top"}}
30+
value={i18n.language}
31+
onChange={e => { localStorage.setItem('lang', e.target.value); i18n.changeLanguage(e.target.value); }}
32+
>
33+
{LANGUAGES.map(({ code, label }) => (
34+
<option key={code} value={code}>{label}</option>
35+
))}
36+
</select>
2237
<button style={{fontSize: 10, padding: 4, marginRight: 15, verticalAlign: "top"}} onClick={toggle_theme}>
2338
{t("changeTheme")}
2439
</button>

src/QuickStore.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Fragment, useEffect, useState } from 'react';
2+
import { useTranslation } from 'react-i18next';
23
import { Spacer, Mobile, getParams } from './Utils';
34
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
45
import { IconProp } from '@fortawesome/fontawesome-svg-core';
@@ -38,6 +39,7 @@ const formatGH = (url: string) => {
3839
type Platform = "wiiu" | "switch" | "3ds";
3940

4041
const QuickStore = (props: { platform: Platform }) => {
42+
const { t } = useTranslation();
4143

4244
const [ allApps, setAllApps ] = useState([]);
4345
const { platform: plat } = getParams(props) as {platform?: Platform};
@@ -65,9 +67,7 @@ const QuickStore = (props: { platform: Platform }) => {
6567
<div className="catTitle">
6668
QuickStore
6769
</div>
68-
<p>
69-
This page allows you to download multiple apps in a single zip file, that can then be extracted directly to the root of the SD card.
70-
</p>
70+
<p>{t("qsPurpose")}</p>
7171
<p className="disabled">
7272
<input type="checkbox" id="experimental" disabled/>
7373
<label htmlFor="experimental">Fetch releases directly from <FontAwesomeIcon icon={faPropIcon} /> Github where possible (Coming Soon)</label>
@@ -146,7 +146,7 @@ const QuickStore = (props: { platform: Platform }) => {
146146
const progress = (<div className='progress'><button className="progressBar">
147147
<FontAwesomeIcon icon={faCirclePropIcon} className={"fa-spin"} />
148148
&nbsp;
149-
Downloading {selectedPackages.length} packages...
149+
{t("downloadVerb", { count: selectedPackages.length })}
150150
</button></div>);
151151

152152
const dlButton = <div>
@@ -186,7 +186,7 @@ const QuickStore = (props: { platform: Platform }) => {
186186
>
187187
<FontAwesomeIcon icon={faDLPropIcon} />
188188
&nbsp;
189-
Download&nbsp;{selectedPackages.length}&nbsp;Selected
189+
{t("downloadPrompt", { count: selectedPackages.length })}
190190
</button>
191191
</div>;
192192

src/i18n.jsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@ import i18n from 'i18next';
22
import { initReactI18next } from 'react-i18next';
33

44
import enTranslation from './locales/en.json';
5+
import ruTranslation from './locales/ru.json';
6+
import esTranslation from './locales/es.json';
7+
8+
const SUPPORTED = ['en', 'ru', 'es'];
9+
const browserLang = (navigator.languages?.length ? navigator.languages : [navigator.language])
10+
.map(l => l.split('-')[0])
11+
.find(l => SUPPORTED.includes(l)) || 'en';
12+
const detectedLang = localStorage.getItem('lang') || browserLang;
513

614
i18n
715
.use(initReactI18next)
816
.init({
917
resources: {
1018
en: {
1119
translation: enTranslation
20+
},
21+
ru: {
22+
translation: ruTranslation
23+
},
24+
es: {
25+
translation: esTranslation
1226
}
1327
},
14-
lng: 'en',
28+
lng: detectedLang,
1529
fallbackLng: 'en',
1630
interpolation: {
1731
escapeValue: false

src/locales/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
"allTime": "Show data for All Time (automatically sets time range)",
7979
"- QuickStore": "-",
8080
"qsPurpose": "This page allows you to download multiple apps in a single zip file, that can then be extracted directly to the root of the SD card.",
81-
"downloadPrompt": "Download <0>NUM</0> Selected",
82-
"downloadVerb": "Downloading <0>NUM</0> packages...",
81+
"downloadPrompt": "Download {{count}} Selected",
82+
"downloadVerb": "Downloading {{count}} packages...",
8383
"- About Page": "-",
8484
"aboutTitle": "About hb-appstore",
8585
"aboutDescription1": "Homebrew App Store is a free and open-source repository of <0>homebrew apps</0> for the Wii U and Switch consoles. This listing is maintained by the <2>ForTheUsers team</2>, with the goal of making accessible and preserving the efforts of independent developers and hobbyists to end users.",

0 commit comments

Comments
 (0)