developertools-tech / developertools.tech

A collection of tools for developers served as a PWA
https://www.developertools.tech
MIT License
39 stars 45 forks source link

[Req]: Internationalization #61

Closed dlford closed 2 years ago

dlford commented 2 years ago

Contact Details

No response

Explain the proposed feature

This project will benefit from displaying in many languages, but first we need a system to handle translations.

Explain the possible use cases for the feature

Not everyone speaks or reads the english language, and even those who do may prefer another for ease of use.

Any other details you would like to provide?

A PR for this issue should:

It is not required to add any other languages in the PR for this issue, I will open a new issue for that, but if you know another language please feel free to add it.

shu1007 commented 2 years ago

If you would like, could you also assign this issue?

dlford commented 2 years ago

@shu1007 all yours, thank you!

dlford commented 2 years ago

@shu1007 Not sure if this helps, or I'm too late, but this seems like a good implementation - https://github.com/i18next/next-i18next

shu1007 commented 2 years ago

It's still in process, but I'll show you the implementation. #62

I also found out about next-i18next but I wanted to do some cleanup against the translation files. So I am trying to implement the idea of defining a translation data object in TypeScript and using it.

Is it acceptable to implement this policy?

shu1007 commented 2 years ago

i18n uses the following features of Next.js https://nextjs.org/docs/advanced-features/i18n-routing#sub-path-routing

Then add the following several files to implement i18n

dlford commented 2 years ago

@shu1007 This looks like a great start, I think the two problems I see that need solving are:

  1. The types or schema of the translations, I think it would be a pain to maintain that in TypeScript
  2. Fallbacks, as the project grows and new tools are added, they may only have one language to start, so it will have to fall back to that language.

If you can solve those two things, I don't mind how you implement it, I only suggested i18next because I thought it might save you some time, but it is up to you either way.

Thanks!

Edit: Looks like you already have fallbacks solved maybe? The demos look great!

dlford commented 2 years ago

Maybe we can use generics instead?

shu1007 commented 2 years ago

Sorry for the delay in contacting you. I've decided to change my policy and use next i18-next https://github.com/shu1007/developertools.tech/tree/make-i18n-next

Most of the implementation is done, but it will take a little longer.

dlford commented 2 years ago

@shu1007 No worries, thank you!

dlford commented 2 years ago

@shu1007 This is looking great! Thanks so much for your hard work!

I'm not sure if it helps, but we can also add locale to the Jest mock of next/router here - https://github.com/shu1007/developertools.tech/blob/make-i18n/jest.setup.js#L13

shu1007 commented 2 years ago

@dlford

I'm not sure if it helps, but we can also add locale to the Jest mock of next/router here -

Thanks. However currently on test, i18n outputs mock or English only, so I don't think it is necessary.

shu1007 commented 2 years ago

Sorry for the delay. I finally submitted a pull request.

dlford commented 2 years ago

No worries!