UNPKG

@o3r/localization

Version:

This module provides a runtime dynamic language/translation support and debug tools.

36 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("node:fs"); const path = require("node:path"); const architect_1 = require("@angular-devkit/architect"); const extractors_1 = require("@o3r/extractors"); const globby_1 = require("globby"); exports.default = (0, architect_1.createBuilder)((0, extractors_1.createBuilderWithMetricsIfInstalled)((options, context) => { const posixWorkspaceRoot = context.workspaceRoot.split(path.sep).join(path.posix.sep); options.localizationConfigs.forEach((config) => { const fileNames = (0, globby_1.sync)(config.localizationFiles.map((files) => path.posix.join(posixWorkspaceRoot, files))); fileNames.forEach((filePath) => { const localizationJson = JSON.parse(fs.readFileSync(filePath, { encoding: 'utf8' })); const newContent = JSON.stringify(Object.entries(localizationJson) .filter(([, value]) => !value.dictionary && !value.$ref && value.defaultValue !== undefined) .sort((a, b) => a[0] < b[0] ? -1 : 1) .reduce((acc, [key, { defaultValue }]) => { acc[key] = defaultValue; return acc; }, {}), null, 2); const dir = path.dirname(filePath); const i18nPath = path.join(dir, config.i18nFolderPath); if (!fs.existsSync(i18nPath)) { fs.mkdirSync(i18nPath, { recursive: true }); } const defaultLanguageFile = path.join(i18nPath, options.defaultLanguageFile); fs.writeFileSync(defaultLanguageFile, newContent + '\n'); }); }); return { success: true }; })); //# sourceMappingURL=index.js.map