Created
May 16, 2017 13:42
-
-
Save rawroland/3f779804713f20b513c1bace797cb15d to your computer and use it in GitHub Desktop.
Local storage for translations / locales
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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