UNPKG

@neiderruiz/translate-files

Version:

Internationalize and manage your website easily with (CSV or JSON to i18n)

25 lines (23 loc) 560 B
import { TranslationsOrder, TypeSimpleJson } from "../types/types"; export const sortByLanguage = (jsonObj: TypeSimpleJson[]) => { let n: TranslationsOrder[] = []; jsonObj.map((row) => { // filas Object.keys(row).map((fila) => { const exists = n.find((val) => val[fila]); if (exists) { exists[fila] = { ...exists[fila], [row["key"]]: row[fila], }; } else { n.push({ [fila]: { [row["key"]]: row[fila], }, }); } }); }); return n; };