mirror of
				https://github.com/excalidraw/excalidraw.git
				synced 2025-11-04 12:54:23 +01:00 
			
		
		
		
	* feat: decouple package deps and introduce yarn workspaces * update root directory * fix * fix scripts * fix lint * update path in scripts * remove yarn.lock files from packages * ignore workspace * dummy * dummy * remove comment check * revert workflow changes * ignore ws when installing gh actions * remove log * update path * fix * fix typo
		
			
				
	
	
		
			38 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const { readdirSync, writeFileSync } = require("fs");
 | 
						|
const files = readdirSync(`${__dirname}/../packages/excalidraw/locales`);
 | 
						|
 | 
						|
const flatten = (object = {}, result = {}, extraKey = "") => {
 | 
						|
  for (const key in object) {
 | 
						|
    if (typeof object[key] !== "object") {
 | 
						|
      result[extraKey + key] = object[key];
 | 
						|
    } else {
 | 
						|
      flatten(object[key], result, `${extraKey}${key}.`);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return result;
 | 
						|
};
 | 
						|
 | 
						|
const locales = files.filter(
 | 
						|
  (file) => file !== "README.md" && file !== "percentages.json",
 | 
						|
);
 | 
						|
 | 
						|
const percentages = {};
 | 
						|
 | 
						|
for (let index = 0; index < locales.length; index++) {
 | 
						|
  const currentLocale = locales[index];
 | 
						|
  const data = flatten(
 | 
						|
    require(`${__dirname}/../packages/excalidraw/locales/${currentLocale}`),
 | 
						|
  );
 | 
						|
 | 
						|
  const allKeys = Object.keys(data);
 | 
						|
  const translatedKeys = allKeys.filter((item) => data[item] !== "");
 | 
						|
  const percentage = Math.floor((100 * translatedKeys.length) / allKeys.length);
 | 
						|
  percentages[currentLocale.replace(".json", "")] = percentage;
 | 
						|
}
 | 
						|
 | 
						|
writeFileSync(
 | 
						|
  `${__dirname}/../packages/excalidraw/locales/percentages.json`,
 | 
						|
  `${JSON.stringify(percentages, null, 2)}\n`,
 | 
						|
  "utf8",
 | 
						|
);
 |