Skip to content

Commit be0f201

Browse files
committed
update locale menu in order to better reflect website usage and translation status
1 parent 67e61e1 commit be0f201

File tree

10 files changed

+73
-85
lines changed

10 files changed

+73
-85
lines changed

components/head.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export default function Head({
2525
{locales.map((locale) => (
2626
<meta
2727
property={
28-
router.locale === locale ? "og:locale" : "og:locale:alternative"
28+
router.locale === locale.code
29+
? "og:locale"
30+
: "og:locale:alternative"
2931
}
30-
content={locale}
31-
key={locale}
32+
content={locale.code}
33+
key={locale.code}
3234
/>
3335
))}
3436
<script type="application/ld+json">

components/langSelect/index.tsx

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,89 +8,37 @@ import {
88
} from "@material-ui/core";
99
import React from "react";
1010
import { useRouter } from "next/router";
11+
import locales from "lib/locales";
1112
import classes from "./style.module.css";
1213

13-
const languages: { name: string; locale: string; icon: string }[] = [
14-
{
15-
name: "Deutsch",
16-
locale: "de",
17-
icon: "de",
18-
},
19-
{
20-
name: "English",
21-
locale: "en",
22-
icon: "gb",
23-
},
24-
{
25-
name: "Esperanto",
26-
locale: "eo",
27-
icon: "eo",
28-
},
29-
{
30-
name: "Español",
31-
locale: "es",
32-
icon: "mx",
33-
},
34-
// {
35-
// name: "Hindi",
36-
// locale: "hi",
37-
// icon: "india",
38-
// },
39-
{
40-
name: "Hrvatski",
41-
locale: "hr",
42-
icon: "hr",
43-
},
44-
{
45-
name: "Italiano",
46-
locale: "it",
47-
icon: "it",
48-
},
49-
{
50-
name: "Malayalam",
51-
locale: "ml",
52-
icon: "india",
53-
},
54-
{
55-
name: "Ukrainian",
56-
locale: "uk",
57-
icon: "uk",
58-
},
59-
{
60-
name: "中文(简体)",
61-
locale: "zh_Hans",
62-
icon: "zh",
63-
},
64-
];
65-
6614
function MenuContent() {
6715
const router = useRouter();
6816

6917
return (
7018
<>
71-
{languages.map((language) => (
19+
{locales.map((locale) => (
7220
<MenuItem
73-
key={language.locale}
74-
selected={router.locale === language.locale}
21+
key={locale.code}
22+
selected={router.locale === locale.code}
7523
onClick={() => {
7624
router.push(
7725
{
7826
pathname: router.pathname,
7927
query: router.query,
8028
},
8129
undefined,
82-
{ locale: language.locale }
30+
{ locale: locale.code }
8331
);
8432
}}
8533
>
8634
<ListItemIcon>
8735
<img
88-
src={`/flags/${language.icon}.svg`}
89-
alt={language.icon}
36+
src={`/flags/${locale.icon}.svg`}
37+
alt={locale.icon}
9038
className={classes.icon}
9139
/>
9240
</ListItemIcon>
93-
<ListItemText>{language.name}</ListItemText>
41+
<ListItemText>{locale.name}</ListItemText>
9442
</MenuItem>
9543
))}
9644
</>

lib/algorithms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function getAlgorithmSlugs() {
1111
params: {
1212
algorithm: file.replace(".json", ""),
1313
},
14-
locale,
14+
locale: locale.code,
1515
}))
1616
);
1717
}

lib/categories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function getCategories() {
1818
params: {
1919
category: normalize(category),
2020
},
21-
locale,
21+
locale: locale.code,
2222
}))
2323
);
2424
}

lib/languages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function getLanguages() {
1111
params: {
1212
language,
1313
},
14-
locale,
14+
locale: locale.code,
1515
}))
1616
);
1717
}

lib/locales.js

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
1-
module.exports = [
2-
"de",
3-
"en",
4-
"eo",
5-
"es",
6-
"hr",
7-
"it",
8-
"ml",
9-
"uk",
10-
"zh_Hans"
1+
const locales = [
2+
{
3+
name: "English",
4+
code: "en",
5+
icon: "gb",
6+
},
7+
{
8+
name: "简体中文",
9+
code: "zh_Hans",
10+
icon: "zh",
11+
},
12+
{
13+
name: "Malayalam",
14+
code: "ml",
15+
icon: "india",
16+
},
17+
{
18+
name: "Deutsch",
19+
code: "de",
20+
icon: "de",
21+
},
22+
{
23+
name: "Esperanto",
24+
code: "eo",
25+
icon: "eo",
26+
},
27+
{
28+
name: "Español",
29+
code: "es",
30+
icon: "mx",
31+
},
32+
{
33+
name: "Italiano",
34+
code: "it",
35+
icon: "it",
36+
},
37+
{
38+
name: "Hrvatski",
39+
code: "hr",
40+
icon: "hr",
41+
},
42+
{
43+
name: "Ukrainian",
44+
code: "uk",
45+
icon: "uk",
46+
},
1147
];
48+
49+
module.exports = locales;

next-env.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference types="next" />
2-
/// <reference types="next/types/global" />
32
/// <reference types="next/image-types/global" />
43

54
// NOTE: This file should not be edited

next-i18next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ const locales = require("./lib/locales");
33
module.exports = {
44
i18n: {
55
defaultLocale: "en",
6-
locales,
6+
locales: locales.map((locale) => locale.code),
77
},
88
};

scripts/fetch-algorithms.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,16 @@ const categoriesToSkip = ["main", "src", "algorithms", "problems"];
265265
process.chdir("./algorithms-explanation");
266266
await Promise.all(
267267
locales.map(async (locale) => {
268-
if (fs.existsSync(locale)) {
269-
for await (const dir of walk(locale)) {
268+
if (fs.existsSync(locale.code)) {
269+
for await (const dir of walk(locale.code)) {
270270
const match = dir.replace(/\\/g, "/").match(/(?:.+)\/(.+)\.md/);
271271
if (match) {
272272
const algorithm = algorithms[normalizeAlgorithm(match[1])];
273273
if (algorithm) {
274274
algorithm.explanationUrl[
275-
locale
275+
locale.code
276276
] = `https://github.com/TheAlgorithms/Algorithms-Explanation/tree/master/${dir}`;
277-
algorithm.body[locale] = await renderMarkdown(
277+
algorithm.body[locale.code] = await renderMarkdown(
278278
(await fs.promises.readFile(dir))
279279
.toString()
280280
.split("\n")
@@ -300,8 +300,9 @@ const categoriesToSkip = ["main", "src", "algorithms", "problems"];
300300
).toString()
301301
);
302302
locales.forEach((locale) => {
303-
if (algorithm.body[locale]) algorithm.body[locale] += `\n${render}`;
304-
else algorithm.body[locale] = render;
303+
if (algorithm.body[locale.code])
304+
algorithm.body[locale.code] += `\n${render}`;
305+
else algorithm.body[locale.code] = render;
305306
});
306307
}
307308
})

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"incremental": true
1818
},
1919
"exclude": ["node_modules"],
20-
"include": ["**/*.ts", "**/*.tsx", "next-env.d.ts", "next.config.js"]
20+
"include": ["**/*.ts", "**/*.tsx", "next-env.d.ts", "next.config.mjs"]
2121
}

0 commit comments

Comments
 (0)