-
-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable i18n support for AsyncAPI website #2184
Changes from 13 commits
22da891
01972c9
b86965a
0062e7d
952c1ef
8a32016
0e95bd8
0b63e20
f8a981b
4bb2f3b
13a375e
32af36f
9e49072
9d62657
ba9e97a
6af5eeb
40b2dd4
99858db
863cdff
fbf1226
883ac0b
e671b8b
597cdb5
a7c1f90
c6d53c8
3444dad
563a817
db8d0f1
c308f23
4f85edf
fd28f05
64accd0
c3d72f0
c64e922
3a6c90c
867b943
4642b9a
2f07331
30aded4
ca1e82b
a0c81e4
66a5186
e6c95e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import { defaultLanguage, languages } from "../lib/i18n"; | ||
import i18nPaths from "../lib/i18nPaths"; | ||
|
||
const LinkComponent = ({ children, locale, ...props }) => { | ||
const router = useRouter(); | ||
|
||
if (!router) { | ||
return ( | ||
<Link href={props.href} passHref> | ||
{children} | ||
</Link> | ||
); | ||
} | ||
|
||
const { pathname, query, asPath } = router; | ||
|
||
// Detect current language | ||
|
@@ -13,6 +23,14 @@ const LinkComponent = ({ children, locale, ...props }) => { | |
|
||
let href = props.href || pathname; | ||
|
||
if ((props.href && i18nPaths[language] && !i18nPaths[language].includes(href)) || href.includes("http", 0)) { | ||
return ( | ||
<Link href={href} passHref> | ||
{children} | ||
</Link> | ||
); | ||
} | ||
Comment on lines
+30
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment for the usecase handled with this condtion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
if (locale) { | ||
if (props.href) { | ||
href = `/${locale}${href}`; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ export default function NavBar({ | |
const changeLanguage = async (locale, langPicker) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add jsdocs to specify the functionality and params of this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
// Verifies if the language change is from langPicker or the browser-api | ||
if(langPicker){ | ||
if (langPicker) { | ||
localStorage.setItem('i18nLang', locale); | ||
} | ||
|
||
|
@@ -72,10 +72,9 @@ export default function NavBar({ | |
router.push(href); | ||
}; | ||
|
||
// To be enabled on the last PR | ||
// useEffect(() => { | ||
// changeLanguage(browserLanguageDetector(), false); | ||
// }, []); | ||
useEffect(() => { | ||
changeLanguage(browserLanguageDetector(), false); | ||
}, []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What function does this useEffect do on initial render? specify this in a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
function outsideClick(menu) { | ||
if (open !== menu) return; | ||
|
@@ -180,14 +179,19 @@ export default function NavBar({ | |
</SearchButton> | ||
|
||
{/* // Language Picker Component */} | ||
{/* <LanguageSelect | ||
<LanguageSelect | ||
options={uniqueLangs} | ||
onChange={(value) => { | ||
changeLanguage(value.toLowerCase(), true); | ||
}} | ||
className="" | ||
selected={i18n.language.toLocaleUpperCase()} | ||
/> */} | ||
selected={() => { | ||
if (i18n.language) { | ||
return i18n.language.toLocaleUpperCase(); | ||
} | ||
return "EN"; | ||
}} | ||
/> | ||
|
||
<GithubButton text="Star on GitHub" href="https://github.com/asyncapi/spec" className="py-2 ml-2" inNav="true" /> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const i18nPaths = { | ||
en: [ | ||
"/tools/cli" | ||
], | ||
de: [ | ||
"/tools/cli" | ||
] | ||
}; | ||
|
||
export default i18nPaths; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,8 @@ import NewsroomSection from '../components/newsroom/NewsroomSection' | |
import { languageDetection } from "../lib/i18n"; | ||
|
||
function HomePage() { | ||
//To be enabled in a future PR | ||
//languageDetection(); | ||
|
||
languageDetection(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function should be inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a preloader same as tools dashboard page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 🚀 |
||
return ( | ||
<> | ||
<Head /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment for the usecase handled with this condtion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done