UNPKG

translate-maker

Version:

Lightweight translation module. Internationalize your great project.

57 lines (46 loc) 1.38 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _objectSpread from "@babel/runtime/helpers/objectSpread"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import get from 'lodash/get'; import set from 'lodash/set'; import Adapter from './Adapter'; export default class Memory extends Adapter { constructor(options = {}) { const { data = {} } = options, rest = _objectWithoutProperties(options, ["data"]); super(_objectSpread({}, rest)); this.data = data; } static getPath(locale, namespace) { return namespace ? `${namespace}.${locale}` : locale; } get(locale, namespace) { var _this = this; return _asyncToGenerator(function* () { if (!locale) { throw new Error('Locale is undefined'); } const path = Memory.getPath(locale, namespace); return get(_this.data, path); })(); } set(locale, value, namespace) { var _this2 = this; return _asyncToGenerator(function* () { if (!locale) { throw new Error('Locale is undefined'); } const path = Memory.getPath(locale, namespace); return set(_this2.data, path, value); })(); } dehydrate() { return _objectSpread({}, this.data); } rehydrate(state) { this.data = state; } } //# sourceMappingURL=Memory.js.map