Skip to content

Commit 0caccfe

Browse files
committed
Reorder locales
1 parent cfd6863 commit 0caccfe

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

src/components/Regulators.astro

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
import { resolve } from '../i18n/resolve';
3+
import { marked } from 'marked';
4+
import regulators from '../data/regulators.yaml';
5+
6+
interface Props {
7+
locale: string;
8+
}
9+
10+
const { locale } = Astro.props;
11+
12+
/** Parse inline markdown and add target="_blank" + ↗ to http/https links */
13+
function renderInline(md: string): string {
14+
let html = marked.parseInline(md) as string;
15+
html = html.replace(/<a href="(https?:\/\/[^"]*)">/g, '<a href="$1" target="_blank">');
16+
html = html.replace(/<a href="(https?:\/\/[^"]*)" target="_blank">([^<]*)<\/a>/g,
17+
'<a href="$1" target="_blank">$2 ↗</a>');
18+
return html;
19+
}
20+
21+
/** Parse block markdown and add target="_blank" + ↗ to http/https links */
22+
function renderBlock(md: string): string {
23+
let html = marked.parse(md) as string;
24+
html = html.replace(/<a href="(https?:\/\/[^"]*)">/g, '<a href="$1" target="_blank">');
25+
html = html.replace(/<a href="(https?:\/\/[^"]*)" target="_blank">([^<]*)<\/a>/g,
26+
'<a href="$1" target="_blank">$2 ↗</a>');
27+
return html;
28+
}
29+
30+
const countries = regulators.countries.filter((c: any) =>
31+
!c.locales || c.locales.includes(locale)
32+
);
33+
34+
// Korean locale puts South Korea first
35+
const orderedCountries = locale === 'ko'
36+
? [
37+
...countries.filter((c: any) => c.id === 'south-korea'),
38+
...countries.filter((c: any) => c.id !== 'south-korea'),
39+
]
40+
: countries;
41+
---
42+
43+
<h3 id="consumers">{resolve(regulators.heading, locale)}</h3>
44+
45+
<Fragment set:html={renderBlock(resolve(regulators.intro, locale))} />
46+
<Fragment set:html={renderBlock(resolve(regulators.follow_up, locale))} />
47+
48+
{orderedCountries.map((country: any) => {
49+
const items = country.items.filter((item: any) =>
50+
!item.locales || item.locales.includes(locale)
51+
);
52+
return (
53+
<>
54+
<h4>{resolve(country.name, locale)}</h4>
55+
<ul>
56+
{items.map((item: any) => (
57+
<li set:html={renderInline(resolve(item.text, locale))} />
58+
))}
59+
</ul>
60+
</>
61+
);
62+
})}

src/i18n/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ export const languages = {
55
es: { label: 'Español', path: '/es/' },
66
id: { label: 'Indonesia', path: '/id/' },
77
it: { label: 'Italiano', path: '/it/' },
8+
pl: { label: 'Polski', path: '/pl/'},
89
'pt-BR': { label: 'Português', path: '/pt-BR/' },
910
cs: { label: 'Čeština', path: '/cs/' },
1011
sk: { label: 'Slovenčina', path: '/sk/' },
11-
th: { label: 'ไทย', path: '/th/' },
1212
tr: { label: 'Türkçe', path: '/tr/' },
13+
el: { label: 'Ελληνικά', path: '/el/'},
14+
th: { label: 'ไทย', path: '/th/' },
1315
uk: { label: 'Українська', path: '/uk/' },
16+
ko: { label: '한국어', path: '/ko/' },
1417
'zh-CN': { label: '简体中文', path: '/zh-CN/' },
1518
'zh-TW': { label: '正體中文', path: '/zh-TW/' },
16-
ko: { label: '한국어', path: '/ko/' },
17-
el: { label: 'Ελληνικά', path: '/el/'},
18-
pl: { label: 'Polski', path: '/pl/'},
1919
} as const;
2020

2121
export type Locale = keyof typeof languages;

0 commit comments

Comments
 (0)