UNPKG

translate-maker

Version:

Lightweight translation module. Internationalize your great project.

85 lines (66 loc) 2.17 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultResolvePath = defaultResolvePath; exports.default = void 0; var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); var _Adapter = _interopRequireDefault(require("./Adapter")); function defaultResolvePath(locale, namespace, options) { const { ext, path } = options; const fileName = ext ? `${locale}${ext}` : locale; const namespacePath = namespace ? `/${namespace.replace('.', '/')}` : ''; const namespaceFilePath = namespacePath ? `${namespacePath}/${fileName}` : fileName; return path ? `${path}/${namespaceFilePath}` : namespaceFilePath; } class File extends _Adapter.default { constructor(options = {}) { if (!options.getData) { throw new Error('You need to set getData'); } super((0, _objectSpread2.default)({ path: undefined, ext: undefined, getData: undefined, setData: undefined, resolvePath: defaultResolvePath }, options)); } get(locale, namespace) { var _this = this; return (0, _asyncToGenerator2.default)(function* () { const options = _this.getOptions(); const { resolvePath, getData } = options; const path = resolvePath(locale, namespace, options); return getData(path); })(); } set(locale, value, namespace) { var _this2 = this; return (0, _asyncToGenerator2.default)(function* () { if (typeof namespace === 'function') { return _this2.set(locale, value, null, namespace); } const options = _this2.getOptions(); const { resolvePath, setData } = options; if (!setData) { throw new Error('You need to set option setData'); } const path = resolvePath(locale, namespace, options); return setData(path, value); })(); } } exports.default = File; //# sourceMappingURL=File.js.map