UNPKG

@jsverse/transloco-keys-manager

Version:

Extract translatable keys from projects that uses Transloco

29 lines 1.14 kB
import { messages } from '../messages.js'; import { isNil } from '../utils/validators.utils.js'; export function addKey({ defaultValue, scopeToKeys, scopeAlias, keyWithoutScope, scopes, params = [], }) { if (!keyWithoutScope) { return; } const scopePath = scopeAlias && scopes.aliasToScope[scopeAlias]; const keyWithScope = scopeAlias ? `${scopeAlias}.${keyWithoutScope}` : keyWithoutScope; const paramsWithInterpolation = params.map((p) => `{{${p}}}`).join(' '); const keyValue = isNil(defaultValue) ? `${messages.missingValue} '${keyWithScope}'` : defaultValue .replace('{{key}}', keyWithScope) .replace('{{keyWithoutScope}}', keyWithoutScope) .replace('{{params}}', paramsWithInterpolation) .replace('{{scope}}', scopeAlias || ''); if (scopePath) { if (!scopeToKeys[scopePath]) { scopeToKeys[scopePath] = {}; } scopeToKeys[scopePath][keyWithoutScope] = keyValue; } else { scopeToKeys.__global[keyWithoutScope] = keyValue; } } //# sourceMappingURL=add-key.js.map