i18n-ai-translate
Version:
AI-powered localization CLI, Node library, and GitHub Action. Translate i18next JSON, Gettext PO, Java .properties, and iOS .strings with ChatGPT, Claude, Gemini, or local Ollama models.
27 lines • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildGroupShards = buildGroupShards;
/**
* Greedy balance-by-item-count: assign each similarity group to the shard
* whose running total is smallest. Groups stay whole, so related items
* remain in one worker's chat history instead of being split across
* unrelated context windows.
*/
function buildGroupShards(groups, concurrency) {
const n = Math.max(1, concurrency);
const shards = Array.from({ length: n }, () => ({}));
const counts = Array.from({ length: n }, () => 0);
for (const group of groups) {
let minIdx = 0;
for (let i = 1; i < n; i++) {
if (counts[i] < counts[minIdx])
minIdx = i;
}
for (const [k, v] of Object.entries(group)) {
shards[minIdx][k] = v;
}
counts[minIdx] += Object.keys(group).length;
}
return shards.filter((shard) => Object.keys(shard).length > 0);
}
//# sourceMappingURL=sharding.js.map