Skip to content

Commit 1b91305

Browse files
authored
chore: Move i18n generation, pre-commit hooks (outline#3410)
1 parent b10802a commit 1b91305

File tree

7 files changed

+297
-60
lines changed

7 files changed

+297
-60
lines changed

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

i18next-parser.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,8 @@ module.exports = {
8080
// message: "${defaultValue}",
8181
// description: "${maxLength}", // t('my-key', {maxLength: 150})
8282
// }
83+
84+
i18nextOptions: {
85+
compatibilityJSON: "v3",
86+
},
8387
};

lint-staged.config.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
// Efficiently run prettier and translation updates on changes to JS and
3+
// TypeScript files
4+
"**/*.[tj]s?(x)": [
5+
(f) => (f.length > 20 ? `yarn lint --fix` : `eslint ${f.join(" ")} --fix`),
6+
() => `yarn build:i18n`,
7+
() => "git add shared/i18n/locales/en_US/translation.json",
8+
],
9+
10+
// Automatically de-duplicate packages as yarn is terrible at it
11+
"(yarn.lock|package.json)": () => `yarn yarn-deduplicate yarn.lock`,
12+
};

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"build": "yarn clean && yarn build:webpack && yarn build:i18n && yarn build:server",
1313
"start": "node ./build/server/index.js",
1414
"dev": "NODE_ENV=development yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=collaboration,websockets,admin,web,worker\"",
15-
"dev:watch": "nodemon --exec \"yarn build:server && yarn build:i18n && yarn dev\" -e js,ts --ignore build/ --ignore app/ --ignore shared/editor",
15+
"dev:watch": "nodemon --exec \"yarn build:server && yarn dev\" -e js,ts --ignore build/ --ignore app/ --ignore shared/editor",
1616
"lint": "eslint app server shared",
1717
"deploy": "git push heroku master",
18-
"prepare": "yarn yarn-deduplicate yarn.lock",
18+
"prepare": "husky install",
1919
"heroku-postbuild": "yarn build:webpack && yarn build:server && yarn copy:i18n && yarn db:migrate",
2020
"sequelize:migrate": "sequelize db:migrate",
2121
"db:create-migration": "sequelize migration:create",
@@ -159,7 +159,7 @@
159159
"react-dom": "^17.0.2",
160160
"react-dropzone": "^11.3.2",
161161
"react-helmet": "^6.1.0",
162-
"react-i18next": "^11.13.0",
162+
"react-i18next": "^11.16.6",
163163
"react-medium-image-zoom": "^3.1.3",
164164
"react-portal": "^4.2.0",
165165
"react-router-dom": "^5.2.0",
@@ -296,11 +296,13 @@
296296
"eslint-plugin-react-hooks": "^4.1.0",
297297
"fetch-test-server": "^1.1.0",
298298
"html-webpack-plugin": "4.5.1",
299-
"i18next-parser": "^4.7.0",
299+
"husky": "^7.0.4",
300+
"i18next-parser": "^6.3.0",
300301
"jest-cli": "^27.4.5",
301302
"jest-fetch-mock": "^3.0.3",
302303
"koa-webpack-dev-middleware": "^1.4.5",
303304
"koa-webpack-hot-middleware": "^1.0.3",
305+
"lint-staged": "^12.3.8",
304306
"nodemon": "^2.0.15",
305307
"prettier": "^2.0.5",
306308
"react-refresh": "^0.9.0",

server/routes/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ router.get("/locales/:lng.json", async (ctx) => {
133133

134134
await send(ctx, path.join(lng, "translation.json"), {
135135
setHeaders: (res) => {
136-
if (process.env.NODE_ENV === "production") {
137-
res.setHeader("Cache-Control", `max-age=${7 * 24 * 60 * 60}`);
138-
}
136+
res.setHeader(
137+
"Cache-Control",
138+
process.env.NODE_ENV === "production"
139+
? `max-age=${7 * 24 * 60 * 60}`
140+
: "no-cache"
141+
);
139142
},
140143
root: path.join(__dirname, "../../shared/i18n/locales"),
141144
});

shared/i18n/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const initI18n = () => {
8484
.use(backend)
8585
.use(initReactI18next)
8686
.init({
87+
compatibilityJSON: "v3",
8788
backend: {
8889
// this must match the path defined in routes. It's the path that the
8990
// frontend UI code will hit to load missing translations.

0 commit comments

Comments
 (0)