multi-lang-exa
v1.0.25
Published
Package for multi-lang
Downloads
10
Maintainers
Readme
multi-lang-exa
Features
- Datas are saved in DB
- Fetch and display required data from package
Tech
- Node JS, MongoDB
Simple example
import {getMessage} from "multi-lang-exa"
async function main() {
console.log(await getMessage("greeting", "en"))
console.log(await getMessage("greeting", "ar"))
}
Mongo Database Settings
Log in to MongoDB Atlas: Go to the MongoDB Atlas website (https://www.mongodb.com/cloud/atlas) and log in with your account credentials.
Create a New Cluster (if not already created):
On the MongoDB Atlas dashboard, click the "Build a Cluster" button. Follow the guided setup to create a new cluster. You can choose the cloud provider, region, and other configuration options. You may also need to set up network access and configure other settings. Create a Database:
Once your cluster is created and running, click on the "Clusters" option in the left sidebar. Select the cluster you just created. Click the "Collections" tab. Click the "Add My Own Data" button. Create a Database:
In the "Create Database" dialog, specify a name for your database (e.g., Multilangs). Create a Collection:
Inside your database, click the "Add Collection" button. Specify a name for your collection (e.g., Langs). You can configure additional settings for your collection as needed, such as indexing or shard key, but for a simple setup, you can keep the default settings. Add Documents to the Collection:
With the collection created, you can add documents to it. Each document can represent a translation, with fields for the translation key and translations in different languages.
Sample Collection
{
"_id": ObjectId("some-unique-id"), // Not required
"translationKey": "greeting",
"translations": {
"en": "Hello!",
"es": "¡Hola!",
"fr": "Bonjour!",
"de": "Hallo!"
}
}
.env file
create the env file and add the Mongo uri
MONGODB_URI=mongodb+srv://Yourusername:[email protected]/?retryWrites=true&w=majority