Skip to content

Instantly share code, notes, and snippets.

@rawroland
Created May 16, 2017 13:42
Show Gist options
  • Save rawroland/3f779804713f20b513c1bace797cb15d to your computer and use it in GitHub Desktop.
Save rawroland/3f779804713f20b513c1bace797cb15d to your computer and use it in GitHub Desktop.
Local storage for translations / locales
import {EventEmitter} from 'fbemitter';
const CHANGE_EVENT = 'change';
export default class Translation extends EventEmitter {
constructor(eventEmitter = null, storage = null) {
super();
this.eventEmitter = eventEmitter || new EventEmitter();
this.localeStorage = storage || localStorage;
}
saveLocale(locale = 'de') {
this.localeStorage.setItem('vsm.locale', locale);
this.eventEmitter.emit(CHANGE_EVENT);
}
locale() {
return this.localeStorage.getItem('vsm.locale')
}
addListener(eventType, func) {
this.eventEmitter.addListener(eventType, func);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment