-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(i18n): generate types * fix: types * chore: cleanup * chore: remove test file strings * fix: types * fix: types * fix: replace child_process with cross-spawn for type generation * fix: refactor type generation script and improve output format * chore: update yarn.lock * chore: update yarn.lock
- Loading branch information
1 parent
f2c0cf6
commit 084dbf2
Showing
91 changed files
with
2,167 additions
and
301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ CHANGELOG.md | |
node_modules | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
src/types/i18n.d.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,38 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const escapeString = string => { | ||
return string | ||
.replace(/\\/g, '\\\\') // Escape backslashes first | ||
.replace(/'/g, "\\'") // Escape single quotes | ||
.replace(/\n/g, '\\n') // Escape newlines | ||
.replace(/\r/g, '\\r') // Escape carriage returns | ||
.replace(/\t/g, '\\t'); // Escape tabs | ||
}; | ||
|
||
const generateTypeDefinitions = (jsonPath, outputPath) => { | ||
const json = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); | ||
|
||
const header = `// This file is autogenerated by the script. DO NOT EDIT BY HAND. | ||
// To update this file, run: yarn run translate:generate-types | ||
`; | ||
|
||
const body = Object.entries(json) | ||
.map(([key, value]) => ` '${key}': \`${escapeString(value)}\`;`) | ||
.join('\n'); | ||
|
||
const content = `${header}declare module 'I18n/en-US.json' { | ||
const translations: { | ||
${body} | ||
}; | ||
export default translations; | ||
} | ||
`; | ||
|
||
fs.writeFileSync(outputPath, content); | ||
}; | ||
|
||
const ROOT_PATH = path.resolve(__dirname, '..'); | ||
|
||
generateTypeDefinitions(path.join(ROOT_PATH, 'src/i18n/en-US.json'), path.join(ROOT_PATH, 'src/types/i18n.d.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
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
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
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.