/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define("@angular/compiler-cli/src/transformers/i18n", ["require", "exports", "@angular/compiler", "path"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.i18nSerialize = exports.i18nExtract = exports.i18nGetExtension = void 0; var compiler_1 = require("@angular/compiler"); var path = require("path"); function i18nGetExtension(formatName) { var format = formatName.toLowerCase(); switch (format) { case 'xmb': return 'xmb'; case 'xlf': case 'xlif': case 'xliff': case 'xlf2': case 'xliff2': return 'xlf'; } throw new Error("Unsupported format \"" + formatName + "\""); } exports.i18nGetExtension = i18nGetExtension; function i18nExtract(formatName, outFile, host, options, bundle, pathResolve) { if (pathResolve === void 0) { pathResolve = path.resolve; } formatName = formatName || 'xlf'; // Checks the format and returns the extension var ext = i18nGetExtension(formatName); var content = i18nSerialize(bundle, formatName, options); var dstFile = outFile || "messages." + ext; var dstPath = pathResolve(options.outDir || options.basePath, dstFile); host.writeFile(dstPath, content, false, undefined, []); return [dstPath]; } exports.i18nExtract = i18nExtract; function i18nSerialize(bundle, formatName, options) { var format = formatName.toLowerCase(); var serializer; switch (format) { case 'xmb': serializer = new compiler_1.Xmb(); break; case 'xliff2': case 'xlf2': serializer = new compiler_1.Xliff2(); break; case 'xlf': case 'xliff': default: serializer = new compiler_1.Xliff(); } return bundle.write(serializer, getPathNormalizer(options.basePath)); } exports.i18nSerialize = i18nSerialize; function getPathNormalizer(basePath) { // normalize source paths by removing the base path and always using "/" as a separator return function (sourcePath) { sourcePath = basePath ? path.relative(basePath, sourcePath) : sourcePath; return sourcePath.split(path.sep).join('/'); }; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaTE4bi5qcyIsInNvdXJjZVJvb3Q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