Code Monkey home page Code Monkey logo

qamoos's Introduction

qamoos

qamoos is a multilingual index package for node.js.

qamoos is a small dictionnary to manage internationalization of an application. You can define indexes of messages in different languages and access to them with a code.

How does it work ?

You should define different messages inside a qamoos defined by its name. Data is stored in a global variable so you can define it once in the project and use it while needed.

**First define a qamoos ** (run this once in the project)

var Qamoos = require("qamoos")(req);

var myBook = Qamoos.define("myBook");

myBook.set('run', {"fr":"Serveur a l'ecoute du port " , en:"Server listening port " });
myBook.set('name', {"fr":"Nom de l'application" , en:"appName" });
myBook.set('def', {"fr":"defaut" , "en":"default"});

Now, somewhere in your project, when you need a translation:

var Qamoos = require("qamoos")(req);
var myBook = Qamoos.define("myBook");

console.log(myBook.get('run'),81);
Qamoos.lang("fr"); // define french as default language (english is the default value)
console.log(myBook.get('run'),81);

Data persistence

  • A 'qamoos' dictionnary is stored in a server variable (global object) so that it can be accessible from any module.
  • Language information is stored as a session variable (cookie), so it could be changed for each session. So, you should use "express-session" middleware to store session information in coockies:
var express = require('express');
var app = express();
var expressSession = require('express-session');

app.use( expressSession({secret:'mySecretKey', cookie: { maxAge: 60000 }, resave:false, saveUninitialized:true}) );

You can create a qamoos for each module or application. The data is grouped as ONE global object in the server and shared by users and sessions.

Error messages

You can attribute a code to your messages and get the translation in the form of an error object:

var Qamoos = require("qamoos")(req);
var myBook = Qamoos.define("myBook");

myBook.set('badLogin', {fr:"Login incorrect", en:"Bad login"},-101);
myBook.set('badPassword', {fr:"Mot de passe incorrect", en:"Bad password"},-102);


console.log(myBook.getErr('badLogin'),81);

Will give you:

{ err:-101, msg:'Bad login'}

qamoos's People

Contributors

rouabhi avatar

Stargazers

Hadj H. avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.