Are you a NodeJS user? If true
, we provide the same library for NodeJS. See: Mongo Backend for NodeJS
This is a i18next backend to be used in Deno. It will load resources from a MongoDB database.
IMPORTANT: Because we use
mongo@v0.7.0
as a driver to connect to MongoDB, please also follow the guidelines and requirements of the library. See Mongo in Deno for further information.
import i18next from 'https://deno.land/x/i18next/index.js'
import { Backend } from 'https://deno.land/x/i18next_mongo_backend/mod.ts'
i18next.use(Backend).init({
// Backend Options
backend: options,
})
{
// Database Name
dbName: '<DB Name>', // Required
// Or
// MongoDB standard configuration
host: '<DB Host>',
port: 27017,
// Or
// Use collection - See: https://doc.deno.land/https/deno.land/x/mongo/mod.ts#Collection
collection: Collection,
// MongoDB authentication. Remove it if not needed
user: '<DB User>',
password: '<DB Password>',
// Collection name in database will be used to store i18next data
colName: 'i18n',
// MongoDB field name
// Language data
langFieldName: 'lang',
// Namespace data
nsFieldName: 'ns',
// Data
dataFieldName: 'data',
// Remove MongoDB special character from field name - See https://jira.mongodb.org/browse/SERVER-3229
sanitizeFieldName: true,
// Error handlers
readOnError: console.error,
readMultiOnError: console.error,
createOnError: console.error,
// MongoClient Options - See: https://doc.deno.land/https/deno.land/x/mongo/mod.ts#ClientOptions
mongodb: ClientOptions
};
{
host: 'localhost',
port: 27017,
dbName: 'test' // Required field
}
If you already have your own connection, use this to avoid useless connections
{
collection: Collection, // See: https://doc.deno.land/https/deno.land/x/mongo/mod.ts#Collection
dbName: 'test', // Required field
}
// Key name is according to provided in options
{
"lang": "en-US",
"ns": "translations",
"data": {
"key": "Thank you!"
}
}