Skip to content

Commit

Permalink
refactor(docs): proper sorting of locales in the i18n table
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinTh committed Nov 17, 2024
1 parent a1519e1 commit fdf8855
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions packages/docs/src/data/i18n.data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SiteConfig } from 'vitepress';
import { sortBy } from 'lodash-es';
import { orderBy } from 'lodash-es';
import { createMarkdownRenderer } from 'vitepress';
import { locales } from '../../../app-client/src/locales/locales';

Expand All @@ -22,21 +22,27 @@ function countKeysDeep(obj: Record<string, unknown>): number {

const defaultLocaleKeyCount = countKeysDeep(await import(`../../../app-client/src/locales/en.json`).then(({ default: fileContent }) => fileContent));

const localeConfigs = sortBy(await Promise.all(locales.map(async ({ key, name }) => {
const { default: fileContent } = await import(`../../../app-client/src/locales/${key}.json`);
const keyCount = countKeysDeep(fileContent);
const ratio = keyCount / defaultLocaleKeyCount;
const isComplete = keyCount === defaultLocaleKeyCount;
const localeConfigs = orderBy(
await Promise.all(locales.map(async ({ key, name }) => {
const { default: fileContent } = await import(`../../../app-client/src/locales/${key}.json`);
const keyCount = countKeysDeep(fileContent);
const ratio = keyCount / defaultLocaleKeyCount;
const isComplete = keyCount === defaultLocaleKeyCount;

return {
key,
name,
content: fileContent,
keyCount,
ratio,
isComplete,
};
})), 'ratio').reverse();
return {
key,
name,
content: fileContent,
keyCount,
ratio,
isComplete,
};
})),

// 'en' first, then by ratio, then by key
[({ key }) => key === 'en', 'ratio', 'key'],
['desc', 'desc', 'asc'],
);

const mdTable = [
'| Locale | Key | Translation completion | Actions |',
Expand Down

0 comments on commit fdf8855

Please sign in to comment.