panel icon indicating copy to clipboard operation
panel copied to clipboard

Implementing i18n

Open fabm3n opened this issue 4 years ago • 18 comments

This is currently a WIP Implementation for basic i18n in account and auth components. There won't be any language switching in this PR.

  • [x] Implement (and / or update) the 18n backend and dependencies
  • [x] Implement i18n in all account and auth components
  • [x] resources/scripts/routers/DashboardRouter.tsx

Files i need help:

  • [ ] resources/scripts/components/elements/ScreenBlock.tsx

Things to do:

  • [ ] Remove Trans component. From the docs: "It does ONLY interpolation. It does not rerender on language change or load any translations needed."

I will update this post if more progress is done.

This will not close #2518 because this is only a small step for i18n.

fabm3n avatar Dec 18 '20 18:12 fabm3n

I wonder if we can make webpack bundle the english translations into the bundle itself so they're immediately available until whatever language is selected is loaded in?

DaneEveritt avatar Dec 18 '20 18:12 DaneEveritt

Now the translations are bundled into the bundle.js. Currently are all translations bundled into the file. I think you don't like this, right?

fabm3n avatar Dec 19 '20 23:12 fabm3n

@fabm3n No, it should bundle one language, I don't want to bloat the download size unnecessarily. If the user needs a different language than is bundled it should load it from the server.

DaneEveritt avatar Dec 20 '20 18:12 DaneEveritt

This is still WIP. The Translations are not fully implemented.

fabm3n avatar Mar 01 '21 17:03 fabm3n

Hey @fabm3n I'm actually making some changes to how the translation files are laid out to avoid a huge nest of strings, might want to hold off for a little bit until I can get that change pushed up. Should make it much easier to work with the files and re-use strings where needed. 👍🏼

DaneEveritt avatar May 11 '21 15:05 DaneEveritt

Hey @fabm3n I'm actually making some changes to how the translation files are laid out to avoid a huge nest of strings, might want to hold off for a little bit until I can get that change pushed up. Should make it much easier to work with the files and re-use strings where needed. 👍🏼

Ok, i will commit my latest changes and then i will wait.

fabm3n avatar May 11 '21 15:05 fabm3n

@fabm3n Okay, I pushed up a change to the translation file structure. Look at en-us/dashboard.json for the new format (specifically the 2fa section). Basically, when you have a bunch of keys related to specific fields and what-not it is much easier for someone else to understand and find when they're grouped together.

Currently with all of the keys in a long single file it is super difficult to know where they are being used, and figure out if there are keys that can be re-used. The elements.json file contains single-word/button titles that can be re-used a lot.

Also, I noticed there were a lot of instances of keys being added but not used yet. Let's try to avoid that for now because it makes it super difficult to see at a glance what is going on.

Finally, for the sake of keeping this review pretty easy and whatnot, lets only translate the dashboard/auth/account areas and leave out the server views for now. It should be much easier to make sure we're happy with the whole setup and figure out a good organization structure. From there we can do future PRs to translate more of the frontend (also, for now only translate to en-us, we'll do a second translation run once this is done and merged to add more languages).

DaneEveritt avatar May 16 '21 18:05 DaneEveritt

I think my latest merge develop into i18n broke a lot of stuff....

fabm3n avatar Jun 11 '21 20:06 fabm3n

@fabm3n What are the problems with the ScreanBlock and DashboardRouter files?

Ferks-FK avatar Dec 06 '21 20:12 Ferks-FK

@fabm3n What are the problems with the ScreanBlock and DashboardRouter files?

I tried withTranslation, useTranslation and the Trans Component but i didn't got anything working. I will have a new look into it in the next days if i can get it working now.

fabm3n avatar Dec 06 '21 22:12 fabm3n

try this in DashboardRouter

<NavLink to={'/account'} exact>{i18n.t('KEY-HERE')}</NavLink> <NavLink to={'/account/api'}>{i18n.t('KEY-HERE')}</NavLink>

Ferks-FK avatar Dec 06 '21 22:12 Ferks-FK

try this in DashboardRouter

<NavLink to={'/account'} exact>{i18n.t('KEY-HERE')}</NavLink> <NavLink to={'/account/api'}>{i18n.t('KEY-HERE')}</NavLink>

You can't use the i18n.t function because i18n isn't initialized. You need to use the reacti18n package. I found a solution for the dashboard router.

fabm3n avatar Dec 09 '21 16:12 fabm3n

I add the zh-cn translations. -> https://github.com/fabm3n/panel/pull/6

SerinaNya avatar Dec 31 '21 01:12 SerinaNya

I add the zh-cn translations. -> fabm3n#6

@jinzhijie Unfortunately, this is not merged, since this PR only contains the basic implementation of i18n.

fabm3n avatar Jan 18 '22 21:01 fabm3n

This PR will be maintained even with the PR policy changes mentioned here: https://github.com/pterodactyl/panel/blob/develop/CONTRIBUTING.md

I believe at least getting the base logic into the codebase needed to support i18n will be beneficial in the long run, even if we only end up doing small pieces of the codebase at a time. That is far easier to review and handle rolling forward, rather than dealing with the mental overhead and complexity of doing the whole codebase at once.

I believe we settled on adding in the base logic for i18n and just doing the dashboard for this @fabm3n? I can't remember anymore, but if we can make that be the case here I'm good to merge the work through.

DaneEveritt avatar Mar 28 '22 19:03 DaneEveritt

Yes the plan for this PR is only auth and dahboard components and the basic i18n implementation (without language switcher. This should be implemented when all string are managed by i18n).

There are currently the following tasks left: i18n in this file: resources/scripts/components/elements/ScreenBlock.tsx

And i planned to remove all trans components (from the docs: "It does ONLY interpolation. It does not rerender on language change or load any translations needed. Check [useTranslation hook] or [withTranslation HOC] for those cases.")

I will have a look into it tomorrow.

fabm3n avatar Mar 29 '22 20:03 fabm3n

is there an idea when this could be done because i need a russian translation for ptero

ThnksCJ avatar Aug 02 '22 17:08 ThnksCJ

Any updates on this? Could be awesome if we could get inplemented more languages. I have translated several opensource projects, and several of them have used Crowdin. It makes it easy for anyone to contribute translations, even for those with no coding experience.

Maybe you could implement Crowdin in the project?

victorpahuus avatar Mar 23 '24 13:03 victorpahuus