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: add translation hooks and packages #1980

Merged
merged 14 commits into from
Aug 2, 2023

Conversation

anshgoyalevil
Copy link
Member

Description

  • This PR adds the translation hooks and packages for configuring the i18n on the AsyncAPI website.
  • As per conversation with the mentor, the website would initially support i18n for German Language, and would gradually support more languages as the community contributes.
  • The fallback language is en
  • I have added the initial translation for the heroHeading on Landing Page to test the package. Would be adding more translations in the subsequent PRs.

Related issue(s)

fixes #1978

@netlify
Copy link

netlify bot commented Jul 22, 2023

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 27dccdf
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/64ca01b65f269e0008dd6c6f
😎 Deploy Preview https://deploy-preview-1980--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link

github-actions bot commented Jul 22, 2023

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 27
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🔴 PWA 30

Lighthouse ran on https://deploy-preview-1980--asyncapi-website.netlify.app/

Copy link
Member

derberg commented Jul 25, 2023

German 👀
Is there already someone volunteering to provide translation for German? Cause if it is Polish, we at least have people that could try to provide some simple translations, same for Spanish I guess

@anshgoyalevil
Copy link
Member Author

@derberg I was testing the translation thing, and sticked to the German Language.
Though I used Google Translator for that.

Would add Spanish Language (or maybe Polish) in the upcoming PRs.

@magicmatatjahu
Copy link
Member

@anshgoyalevil @derberg Yeah, it was my fault. I suggested German only for testing (we don't need the proper translation tbh, we can even use lorem ipsum on German texts). However if we wanna go with "production" translations we can go with Spanish or Polish from beginning. Sorry for that misunderstood!

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

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

Awesome! 🚀 I see some "problems" but overall it's great start. We need to remember (before merge) to disable the language switcher and also add the proper blockers in the crawler bots config to disable crawling (now) the translations. We will enable that in last PR :)

components/Hero.js Outdated Show resolved Hide resolved
next.config.js Show resolved Hide resolved
next-i18next-static-site-config.js Outdated Show resolved Hide resolved
locales/en/common.json Outdated Show resolved Hide resolved
pages/[lang]/index.js Outdated Show resolved Hide resolved
components/navigation/NavBar.js Outdated Show resolved Hide resolved
@anshgoyalevil
Copy link
Member Author

@magicmatatjahu Done with the changes. Thanks for the inputs 😄

components/navigation/NavBar.js Show resolved Hide resolved
components/navigation/NavBar.js Outdated Show resolved Hide resolved
pages/[lang]/index.js Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

If you are migrating the file, can you please do the refactoring of this codebase in terms of formatting and spacing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes sure.

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!

lib/locales.js Outdated
Comment on lines 5 to 16
const locales = {};
languages.map((language) => {
locales[language] = {};

namespaces.map((namespace) => {
locales[language][namespace] = require("./../locales/" +
language +
"/" +
namespace +
".json");
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Kindly wrap this in a function and then return the required response from the 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.

Actually, this is not my implementation. It is suggested by the plugin author since were in need to use the static site built due to Netlify restrictions.

Copy link
Member

Choose a reason for hiding this comment

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

Can you please share the source you are following to create this file?

IMHO, even if we have to implement such logic, I don't think it will make any difference while implementing it inside functions. Reason why I'm asking for making it as a function is that we should work on code quality as well, instead of just writing it as plain implementation of js. Also, it will be easier to add unit tests (later on) for this file.

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! I totally agree with your points.

I am following this package. Their one of the examples is what I tried imitating in our project.

The reason to use this package is that previously I was using the next-i18next package to handle the translation-related logic, and everything was going smoothly inside the local dev. environment.
As I pushed that code, it became useless because Netlify cannot process translations on the server, and need pre-generated translations.
Another option was to use a Node.JS environment to host the website, but that doesn't seem viable.

@anshgoyalevil
Copy link
Member Author

Thanks for the inputs @akshatnema 🚀
I will be making the changes like refactoring in subsequent PRs.
The purpose of this PR is to create a base over the other pages of the project, as you might have seen that currently, only the homepage is moved under [lang] directory, and that is because, as we would move towards translating other pages, they would also be moved under the [lang] folder.

This PR is ready to be merged. The scope of this PR is limited to:

  • Initialising translation hooks and packages
  • Creating a base structure for other pages of the project.
  • Creating the Language Selected in Navbar, which would be un-commented in the last PR, as per @magicmatatjahu

@akshatnema
Copy link
Member

@anshgoyalevil Kindly resolve the comments only if either the discussion made using the comment satisfies the reviewer or you made changes requested by the reviewer.

magicmatatjahu
magicmatatjahu previously approved these changes Aug 2, 2023
Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

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

Ok for me :) Please only change the label for Github button and we can merge :)

components/buttons/GithubButton.js Outdated Show resolved Hide resolved
@anshgoyalevil
Copy link
Member Author

Thanks @magicmatatjahu 😄. Changed the GitHub Button 🚀

@magicmatatjahu
Copy link
Member

magicmatatjahu commented Aug 2, 2023

@anshgoyalevil It still has Gtihub text - probably you changed the text inside navbar (and override default text):

image

Please fix that :)

It has to be:

image

@anshgoyalevil
Copy link
Member Author

@magicmatatjahu Sorry for that. Missed that. Fixed now

@magicmatatjahu
Copy link
Member

@akshatnema Hi! Could you check PR?

@magicmatatjahu
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 97f0446 into asyncapi:master Aug 2, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add translation package and hooks
5 participants