Skip to content
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

Merged
merged 43 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
22da891
add custom i18n link
anshgoyalevil Sep 8, 2023
01972c9
Merge branch 'asyncapi:master' into i18n-link
anshgoyalevil Sep 9, 2023
b86965a
fix link.js
anshgoyalevil Sep 9, 2023
0062e7d
Merge branch 'master' into i18n-link
anshgoyalevil Sep 15, 2023
952c1ef
Merge branch 'master' into i18n-link
anshgoyalevil Sep 16, 2023
8a32016
Merge branch 'master' into i18n-link
anshgoyalevil Sep 18, 2023
0e95bd8
Merge branch 'master' into i18n-link
anshgoyalevil Sep 22, 2023
0b63e20
Merge branch 'master' into i18n-link
anshgoyalevil Sep 26, 2023
f8a981b
Merge branch 'master' into i18n-link
anshgoyalevil Sep 28, 2023
4bb2f3b
Enable i18n
anshgoyalevil Sep 28, 2023
13a375e
Fix type error
anshgoyalevil Sep 28, 2023
32af36f
Merge branch 'master' into enable-i18n
anshgoyalevil Oct 1, 2023
9e49072
Merge branch 'master' into enable-i18n
anshgoyalevil Oct 7, 2023
9d62657
Merge branch 'master' into enable-i18n
anshgoyalevil Oct 9, 2023
ba9e97a
change select value
anshgoyalevil Oct 9, 2023
6af5eeb
Merge branch 'master' into enable-i18n
anshgoyalevil Oct 11, 2023
40b2dd4
Merge branch 'master' into enable-i18n
anshgoyalevil Oct 15, 2023
99858db
Merge branch 'master' into enable-i18n
akshatnema Oct 21, 2023
863cdff
Merge branch 'master' into enable-i18n
anshgoyalevil Nov 3, 2023
fbf1226
Merge branch 'master' into enable-i18n
anshgoyalevil Nov 21, 2023
883ac0b
Merge branch 'master' into enable-i18n
anshgoyalevil Nov 29, 2023
e671b8b
Merge branch 'master' into enable-i18n
anshgoyalevil Dec 7, 2023
597cdb5
Merge branch 'master' into enable-i18n
anshgoyalevil Dec 16, 2023
a7c1f90
Merge branch 'master' into enable-i18n
anshgoyalevil Dec 27, 2023
c6d53c8
make changes to LanguageSelect
anshgoyalevil Dec 27, 2023
3444dad
Merge branch 'enable-i18n' of https://github.com/anshgoyalevil/websit…
anshgoyalevil Dec 27, 2023
563a817
Merge branch 'master' into enable-i18n
anshgoyalevil Jan 18, 2024
db8d0f1
Merge branch 'master' into enable-i18n
anshgoyalevil Feb 2, 2024
c308f23
add changes
anshgoyalevil Feb 2, 2024
4f85edf
Merge branch 'master' into enable-i18n
anshgoyalevil Feb 4, 2024
fd28f05
add comments and fix router
anshgoyalevil Feb 4, 2024
64accd0
remove unused import
anshgoyalevil Feb 4, 2024
c3d72f0
updated js doc comments
Feb 4, 2024
c64e922
update jsdoc comments
anshgoyalevil Feb 4, 2024
3a6c90c
Merge branch 'enable-i18n' of https://github.com/anshgoyalevil/websit…
anshgoyalevil Feb 4, 2024
867b943
Merge branch 'master' into enable-i18n
akshatnema Feb 6, 2024
4642b9a
add navbar and centered logo
anshgoyalevil Feb 6, 2024
2f07331
add infinite loop fix
anshgoyalevil Feb 6, 2024
30aded4
Merge branch 'master' into enable-i18n
anshgoyalevil Feb 6, 2024
ca1e82b
update UI of LanguageSelect
akshatnema Feb 7, 2024
a0c81e4
Merge branch 'master' into enable-i18n
akshatnema Feb 7, 2024
66a5186
Merge branch 'master' into enable-i18n
anshgoyalevil Feb 9, 2024
e6c95e0
Merge branch 'master' into enable-i18n
akshatnema Feb 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/link.js
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>
);
}
Comment on lines +10 to +16
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


const { pathname, query, asPath } = router;

// Detect current language
Expand All @@ -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
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if (locale) {
if (props.href) {
href = `/${locale}${href}`;
Expand Down
5 changes: 3 additions & 2 deletions components/navigation/MenuBlocks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LinkComponent from '../link';
import Paragraph from '../typography/Paragraph';
import Label from './Label'
import Link from 'next/link'
Expand All @@ -11,7 +12,7 @@ export default function MenuBlocks ({
items.map((item, index) => {
const isExternalHref = item.href && item.href.startsWith('http');
return (
<Link href={item.comingSoon ? '' : item.href} key={index}>
<LinkComponent href={item.comingSoon ? '' : item.href} key={index}>
<a data-testid="MenuBlocks-Link"
className="-m-3 p-3 flex items-start space-x-4 rounded-lg hover:bg-gray-50 transition ease-in-out duration-150"
target={isExternalHref ? "_blank" : undefined}
Expand All @@ -29,7 +30,7 @@ export default function MenuBlocks ({
</Paragraph>
</div>
</a>
</Link>
</LinkComponent>
)
})
}
Expand Down
20 changes: 12 additions & 8 deletions components/navigation/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function NavBar({
const changeLanguage = async (locale, langPicker) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add jsdocs to specify the functionality and params of this function.

Copy link
Member Author

Choose a reason for hiding this comment

The 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);
}

Expand Down Expand Up @@ -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);
}, []);
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


function outsideClick(menu) {
if (open !== menu) return;
Expand Down Expand Up @@ -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>
Expand Down
10 changes: 10 additions & 0 deletions lib/i18nPaths.js
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;
4 changes: 2 additions & 2 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should be inside useEffect because the initial rendering of the Homepage takes place (in "EN") first before changing the language of the page.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually languageDetection() is itself a hook so cannot be called inside useEffect()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a preloader same as tools dashboard page.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 🚀

return (
<>
<Head />
Expand Down
Loading