forked from asyncapi/website
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add translation hooks and packages (asyncapi#1980)
- Loading branch information
1 parent
94e0ddc
commit 97f0446
Showing
16 changed files
with
730 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { twMerge } from 'tailwind-merge' | ||
export default function LanguageSelect({ | ||
className = '', | ||
onChange = () => { }, | ||
options = [], | ||
selected, | ||
}) { | ||
return ( | ||
<select data-testid="Select-form" | ||
onChange={(ev) => onChange(ev.target.value)} | ||
className={twMerge(`form-select h-full py-0 px-3 pr-7 inline-flex justify-center rounded-md border border-gray-300 shadow-sm py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500 ${className}`)} | ||
value={selected} | ||
> | ||
{options.map((option, index) => ( | ||
<option key={index} selected={option.value === selected} value={option.value} data-testid="Option-form"> | ||
{option.text} | ||
</option> | ||
))} | ||
</select> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import { defaultLanguage, languages } from "next-i18next-static-site"; | ||
|
||
const LinkComponent = ({ children, locale, ...props }) => { | ||
const router = useRouter(); | ||
const { pathname, query, asPath } = router; | ||
|
||
// Detect current language | ||
const slug = asPath.split("/")[1]; | ||
const langSlug = languages.includes(slug) && slug; | ||
const language = query.lang || langSlug || defaultLanguage; | ||
|
||
let href = props.href || pathname; | ||
|
||
if (locale) { | ||
if (props.href) { | ||
href = `/${locale}${href}`; | ||
} else { | ||
if (pathname.startsWith("/404")) { | ||
href = `/${locale}`; | ||
} else { | ||
href = pathname.replace("[lang]", locale); | ||
} | ||
} | ||
} else { | ||
if (language) { | ||
href = `/${language}${href}`; | ||
} else { | ||
href = `/${href}`; | ||
} | ||
} | ||
|
||
// Fix double slashes | ||
href = href.replace(/([^:]\/)\/+/g, "$1").replace("//", "/"); | ||
|
||
return ( | ||
<Link href={href} passHref> | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
export const LinkText = ({ href, children, ...props }) => { | ||
return <Link href={href || ""}>{children}</Link>; | ||
}; | ||
|
||
export default LinkComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { languages, namespaces } from "next-i18next-static-site"; | ||
|
||
function loadLocales() { | ||
// Load all locales, required for next-i18n-static-site | ||
const locales = {}; | ||
languages.map((language) => { | ||
locales[language] = {}; | ||
namespaces.map((namespace) => { | ||
locales[language][namespace] = require("./../locales/" + | ||
language + | ||
"/" + | ||
namespace + | ||
".json"); | ||
}); | ||
}); | ||
return locales; | ||
} | ||
|
||
export default loadLocales; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"main": { | ||
"header": "Die Zukunft gestalten", | ||
"subHeader": "Ereignisgesteuerte Architekturen (EDA)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"main": { | ||
"header": "Building the future of", | ||
"subHeader": "Event-Driven Architectures (EDA)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
i18n: { | ||
languages: ["en", "de"], | ||
defaultLanguage: "en", | ||
namespaces: ["landing-page"], | ||
defaultNamespace: "landing-page", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.