O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Date format by country

Internationalization is a cross-cutting concern. When you are changing the locale, it usually affects multiple modules. So, I suggest going with the observer pattern that we already examined while working on DirService: ./js/Service/I18n.js

const EventEmitter = require( "events" );  class I18nService extends EventEmitter {   constructor(){ 

   super();    this.locale = "en-US";   }   notify(){    this.emit( "update" );   } }  exports.I18nService = I18nService;

As you see, we can change the locale property by setting a new value to the locale property. As soon as we call the notify method, all the subscribed modules immediately respond.

However, locale is a public property and therefore we have no control over its access and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required