Multilingual interface and content using mongo / node

We are developing a new application that will be serviced online in the saas model. The user will have access to certain tools and some tutorials on how to use them.

My question is what would be the best approach to a multilingual interface (interface and content). To give you an example, imagine a simple navigation with the following links:

section 1 | page a
| page b
section 2
section 3
| -page c

Each page obviously contains certain tags, headings, buttons, etc.

I searched for a while, and the closest answer I found was here: Scheme of a multilingual database however it describes an approach to a relational database.

After exploring other issues, it seems like a better approach is to store each section / page / label / title / button name as an object with an identifier that stores the translation in a separate table, including the corresponding object identifier, language, and content. In the SQL world, a simple connection will do the job, however, since we are using Mongo, I think there is a better way to do this.

+6
source share
1 answer

I would suggest storing all translations in your mongoDb database, and then using the Express API, execute the query from the first page about translations.

[FRONT] ----> [Send mongoDB _id(s)] ---> [EXPRESS API] ===> [MONGOOSE] [FRONT] <---------- [Translations] <---- [EXPRESS API] <=== [MONGOOSE] 

Mongoose Scheme

  const Content = Schema({ // Type of item you are dealing with contentType: { type: String, enum: ['link', 'title', 'section', 'page'], }, // Value of translations translations: [{ languageName: String, value: String, }], // All Contents that are inside childs: [{ type: Schema.Types.ObjectId, ref: 'Content', }], }); 

Sample data (MongoDB document)

  [{ _id: '00000000000000000000001', contentType: 'section', translations: [{ languageName: 'French', value: 'Section Enfant', }, { languageName: 'English', value: 'Child Section', }], dads: ['00000000000000000000002'], }, { _id: '00000000000000000000002', contentType: 'page', translations: [{ languageName: 'French', value: 'Page Baguette', }, { languageName: 'English', value: 'Tee Page', }], childs: [], }] 

Example request: get all data about one random section

  Content.find({ contentType: 'section', }) .then((ret) => { if (!ret) return []; // Here recursively get childs and childs and childs // until you got everything }) .then(() => {}) .catch(err => {}); 

Instruments

Mongoose

----> Mongoose queries

----> Mongoose Population

Express

PS : Here is the github project, which explains how to start the web / node project from (installation tools ... etc.) [Babel, Gulp, Webpack, ES6 ...]

0
source

Source: https://habr.com/ru/post/1012031/


All Articles