refine icon indicating copy to clipboard operation
refine copied to clipboard

[DOC] i18n Provider Section -> i18n trying to fetch translation.json & updating the installation

Open shahan007 opened this issue 2 years ago • 4 comments

Documentation issue

Currently, i18n is trying to fetch translation.json file in the relative language directory before falling back to the defaultNs. Can be seen below refine-lang-error

This is the code thats responsible for it https://github.com/refinedev/refine/blob/2d48c4e368da1c06f28f7eca36c85b5900dea66a/examples/i18n-react/src/i18n.ts#L6-L17

Another problem that I noticed is that in the docs we only installed 2 packages but missed out on installing i18next-http-backend and i18next-browser-languagedetector packages which are then later immediately imported in the next section where we creating the i18n instance:

image

Describe the thing to improve

  1. For the first issue, Just add the ns property and set it to be an array of common namespace that is being used in the defaultNs
  2. For the second one, we can just import all the required packages, instead of installing them separately since they are being imported immediately in the next session when creating the i18n instance.

Describe the solution (optional)

1. Just by setting ns option to be an array of the namespace that is used in the defaultNs fixes it.
This is because by default ns is set to translation and it still tries to fetch it before it uses the defaultNs

 i18n.use(Backend) 
     .use(detector) 
     .use(initReactI18next) 
     .init({ 
         supportedLngs: ["en", "de"], 
         backend: { 
             loadPath: "/locales/{{lng}}/{{ns}}.json", 
         }, 
+       ns: ["common"],
         defaultNS: "common", 
         fallbackLng: ["en", "de"], 
     }); 

2. For the second issue we can just install the two packages togather:

- npm install react-i18next i18next
+ npm install react-i18next i18next i18next-http-backend i18next-browser-languagedetector

shahan007 avatar Jun 17 '23 12:06 shahan007

Hey @shahan007, We are sorry for this issue. If you want to support us, can you open a PR for this issue? 🙏🏼

yildirayunlu avatar Jun 19 '23 07:06 yildirayunlu

Hi ! sure I will do that

shahan007 avatar Jun 20 '23 11:06 shahan007

Hello @shahan007 We've fixed this issue on refine.new and our cli generated projects, only thing left is documentation. Are you still interested in working on this one? If so, let us know so we can close this issue.

BatuhanW avatar Jun 23 '23 12:06 BatuhanW

I wasnt feeling well for couple of days 😅 Yup, I will work on it. @BatuhanW I have created a pull request for this https://github.com/refinedev/refine/pull/4597

shahan007 avatar Jun 24 '23 09:06 shahan007

Thanks for the PR @shahan007 and congrats on your first contribution! Hope it'll one first of many!

BatuhanW avatar Jun 25 '23 13:06 BatuhanW