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

not able to find way to add new key-value pair and how to initialize i18n with value from mongoDB #21

Open
premnkl opened this issue Sep 16, 2022 · 10 comments

Comments

@premnkl
Copy link

premnkl commented Sep 16, 2022

Dear Team,

Need help for below points. I am not getting references for below things:

  1. How do we initialize the mongoDB with language data
  2. How to upsert existing key value pair
  3. How i18n in react initializes with the mongoDB data as resource

I followed the readMe and initialized the i18next using nodeJS as below, which created a new table in mongoDB:

i18next.use(Backend).init({
// Backend Options
backend: {
host: 'localhost',
port: 27017,
dbName: 'dy-mde', // Required field
},
})_

image

Regards,
Prem

@premnkl
Copy link
Author

premnkl commented Sep 19, 2022

@Unknown051 @lamualfa @mobaabid please for your comments

@lamualfa
Copy link
Owner

How do we initialize the mongoDB with language data

The initializing process should be done in i18next layer. A backend layer like this library can't do it directly. See https://www.i18next.com/how-to/add-or-load-translations for further information.


How to upsert existing key value pair

You can update the locale data directly via i18next. This Backend plugin with update it automatically.


How i18n in react initializes with the mongoDB data as resource

I am not sure I fully understand this question.

If you mean to use i18next in the React.js application, you can follow this guide https://react.i18next.com/getting-started.

But if you mean the mechanism that i18next use to interact with their backend, the backend will implement some of the abstraction methods that i18next provided before. For further information, you can follow this guide about creating your own plugin https://www.i18next.com/misc/creating-own-plugins#backend.

@lamualfa
Copy link
Owner

I followed the readMe and initialized the i18next using nodeJS as below, which created a new table in mongoDB:

Yeah, it's already correct. The collection is still empty because you don't initialize any data using i18next.

@premnkl
Copy link
Author

premnkl commented Sep 19, 2022

@lamualfa thanks for your comments. Please for your inputs to below cases what we have

we have 2 cases to implement

  1. To use mongoDB to store all the translation values and to fetch the value from mongoDB as a source for initializing i18next

similar to below sample code
i18next.use(Backend).use(middleware.LanguageDetector).init({
debug: true,
load: ['ar','en'],
fallbackLng: 'ar',
backend: {
uri: 'mongodb://localhost/test',
collection: 'translations'
},

  1. Providing user an option to add new translation text on runtime. Once we receive the input from user, we need to update the existing key-value pair in mongoDB with the new value received. Once mongoDB is updated with user input. We need to reload the resource for i18n

we believe this can be implemented with the help of 'i18next-node-mongodb-backend-next'

regards,
prem

@lamualfa
Copy link
Owner

lamualfa commented Sep 19, 2022

To use mongoDB to store all the translation values and to fetch the value from mongoDB as a source for initializing i18next

You must insert and read the translation data via i18next, not directly into the database. The Backend layer, like this library, doesn't provide any of those features.


Providing user an option to add new translation text on runtime. Once we receive the input from user, we need to update the existing key-value pair in mongoDB with the new value received. Once mongoDB is updated with user input. We need to reload the resource for i18n

Use t method to read the translation data. Use addResource method to add or update the translation data. Use reloadResources to synchronize data between i18next and the database. Those methods was provided by i18next.

References

@premnkl
Copy link
Author

premnkl commented Sep 19, 2022

@lamualfa thanks for quick response

sorry for more questions, I am trying to understand how I can use i18next-node-mongodb-backend-next

from below point in the readMe
This is a i18next backend to be used Node JS. It will load resources from a MongoDB database with official node mongodb

I understood this package can be used to load data from mongoDB for i18next initialization. Am I right ?

@lamualfa
Copy link
Owner

I understood this package can be used to load data from mongoDB for i18next initialization. Am I right ?

Yeah, of course. This library has been officially approved by i18next team.

@premnkl
Copy link
Author

premnkl commented Sep 19, 2022

@lamualfa I am looking for sample to understand how to do the same

can u help me with that ?

thanks,
prem

@lamualfa
Copy link
Owner

@lamualfa I am looking for sample to understand how to do the same

can u help me with that ?

thanks,
prem

Try looking these examples https://github.com/lamualfa/i18next-node-mongodb-backend-next/tree/v0.x-examples.

@premnkl
Copy link
Author

premnkl commented Sep 19, 2022

@lamualfa I am going through the examples

will comeback, If I need more info

might trouble you again with questions, sorry for that :)

Regards,
prem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants