-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Rework i18n types, update blog path, update some styles
- Loading branch information
Showing
40 changed files
with
632 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const sourceDir = path.join(__dirname, '../src'); | ||
const translationDir = path.join(sourceDir, 'languages'); | ||
const typesDir = path.join(__dirname, '../types/generated'); | ||
|
||
const readLocaleFile = (locale: string) => { | ||
const filePath = path.join(translationDir, `${locale}.json`); | ||
const fileContent = fs.readFileSync(filePath, 'utf-8'); | ||
return JSON.parse(fileContent); | ||
}; | ||
|
||
const extractKeys = (obj: object, prefix = ''): string[] => | ||
Object.entries(obj).flatMap(([key, value]) => { | ||
const newKey = prefix ? `${prefix}.${key}` : key; | ||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) { | ||
return extractKeys(value, newKey); | ||
} | ||
return newKey; | ||
}); | ||
|
||
const generateTypes = (keys: string[]) => { | ||
const unionType = keys | ||
.map((key) => (key.includes("'") ? `"${key}"` : `'${key}'`)) | ||
.join(' | '); | ||
|
||
return `export type LocaleKey = ${unionType};`; | ||
}; | ||
|
||
const compareLocales = (locale1: object, locale2: object) => { | ||
const keys1 = extractKeys(locale1); | ||
const keys2 = extractKeys(locale2); | ||
return keys1.filter((key) => keys2.includes(key)); | ||
}; | ||
|
||
const enLocale = readLocaleFile('en'); | ||
const frLocale = readLocaleFile('fr'); | ||
|
||
const commonKeys = compareLocales(enLocale, frLocale); | ||
const typesContent = generateTypes(commonKeys); | ||
|
||
fs.writeFileSync(path.join(typesDir, 'index.ts'), typesContent); | ||
|
||
console.log('Generated types for locales: ./types/generated/index.ts'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
|
||
const args = Bun.argv.slice(2); | ||
const filePaths: string[] = args; | ||
|
||
if (!filePaths.length) { | ||
throw new Error('[sort-json] No file path(s) provided'); | ||
} else if (filePaths.some((p) => !p.match(/\.json$/i))) { | ||
throw new Error('[sort-json] File(s) must be JSON'); | ||
} | ||
|
||
const sortObjectKeys = (obj: Record<string, unknown>) => { | ||
const sortedKeys = Object.keys(obj).sort(); | ||
|
||
return sortedKeys.reduce((acc, key) => { | ||
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) { | ||
acc[key] = sortObjectKeys(obj[key] as Record<string, unknown>); | ||
} | ||
acc[key] = obj[key]; | ||
return acc; | ||
}, {}); | ||
}; | ||
|
||
filePaths.forEach((filePath) => { | ||
if (!filePath.match(/languages\/[a-z]{2}\.json/i)) { | ||
return; | ||
} | ||
|
||
const contents = JSON.parse(readFileSync(filePath, 'utf-8')); | ||
const sortedContents = sortObjectKeys(contents); | ||
|
||
writeFileSync(filePath, JSON.stringify(sortedContents, null, 2), 'utf-8'); | ||
console.log(`[sort-json] Sorted '${filePath}'`); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
export let title: string, description: string; | ||
</script> | ||
|
||
<section> | ||
<div> | ||
<h3>{title}</h3> | ||
<p>{description}</p> | ||
</div> | ||
|
||
<slot /> | ||
</section> | ||
|
||
<style lang="scss"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.