Skip to content

Commit

Permalink
improve language selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Herkarl committed Jul 2, 2024
1 parent e32c385 commit 880b022
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ const createLinks = (nav, lang) => nav
)

const renderMethone = (path, lang) => {
const info = {
"en": "Svenska",
"sv": "English"
}[lang || 'sv'] || "Svenska";

const redir = {
"en": path,
"sv": path + "?lang=en"
}[lang || 'sv'] || path;
// currently we only have support for 2 languages. If we want to add more, we'll have to
// figure out a more complex language switching solution, and can't just piggyback of methone.
const loginTargetLang = lang === 'en' ? 'sv' : 'en';

const targetLangLabel = {
"sv": "Svenska",
"en": "English"
}[loginTargetLang];

const targetLangHref = {
"sv": path,
"en": path + "?lang=en"
}[loginTargetLang];

const methoneRenderFunc = ({ nav }) => {
const links = nav ? createLinks(nav, lang) : [];
Expand All @@ -38,8 +43,8 @@ const renderMethone = (path, lang) => {
<Methone config={{
sytem_name: 'bawang',
color_scheme: 'cerise',
login_text: info,
login_href: redir,
login_text: targetLangLabel,
login_href: targetLangHref,
links: links
}} />
)
Expand All @@ -63,7 +68,7 @@ export const App = () => {
<Routes>
<Route path="/" exact element={<Frontpage lang={lang} />} />
<Route path="/nyheter/:postId" element={<SingleNews lang={lang} />} />
<Route path="/nyheter" element={<News lang={lang} location={location}/>} />
<Route path="/nyheter" element={<News lang={lang} location={location} />} />
<Route path="/*" element={<Default lang={lang} />} />
</Routes>
</LanguageContext.Provider>
Expand Down

0 comments on commit 880b022

Please sign in to comment.