Skip to content

Instantly share code, notes, and snippets.

View Floffah's full-sized avatar

Floffah Floffah

View GitHub Profile
@Floffah
Floffah / A fully typed next-translate hook using codegen.md
Last active June 22, 2022 14:05
Fully typed next-translate useTranslate hook using automatically generated type definitions

This gist contains 3 files:

  • codegen.ts: this file scans the locales directory and writes a typings.d.ts file based on it
  • useTranslation.ts: this file use the typings.d.ts file produced by codegen.ts to type namespaces & messages
  • typings.d.ts: this is the file produced by codegen.ts, i put an example here of what to expect

Please note, you may need to change the paths in codegen.ts (line 14 and line 127)

This code was made for use with next-translate and nextjs but can easily be adapted for anything else. If you are using nextjs, you should import codegen.ts in your app component and the codegen file will run in development on the server side (with on demand imports as to stop next/swc bundling fs and typescript into your client bundles)

@Floffah
Floffah / index.js
Last active December 20, 2019 21:49
Script for deleting all node_modules from sub-folders
let inquirer = require('inquirer'),
rimraf = require('rimraf'),
fs = require('fs'),
path = require('path'),
chalk = require('chalk'),
dl = require('draftlog'),
gfs = require('graceful-fs');
dl(console);