From c53bd499c78976df6a186670f42edd54940768d1 Mon Sep 17 00:00:00 2001 From: Ronald Langeveld Date: Wed, 31 May 2023 10:37:21 +0200 Subject: [PATCH] Added typescript declerations to i18n (#16894) refs https://github.com/TryGhost/Team/issues/3307 Added TypeScript support and a new namespace for the `i18n` module. This enables type checking and localisation for the new signup form component and future typescript projects that may need to add i18n support. --- ghost/i18n/lib/i18n.js | 2 +- ghost/i18n/package.json | 5 ++++- ghost/i18n/tsconfig.json | 12 ++++++++++++ yarn.lock | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 ghost/i18n/tsconfig.json diff --git a/ghost/i18n/lib/i18n.js b/ghost/i18n/lib/i18n.js index bf4eb5a70f..ffa6deefe9 100644 --- a/ghost/i18n/lib/i18n.js +++ b/ghost/i18n/lib/i18n.js @@ -39,7 +39,7 @@ const SUPPORTED_LOCALES = [ /** * @param {string} [lng] - * @param {'ghost'|'portal'|'test'} ns + * @param {'ghost'|'portal'|'test'|'signup-form'} ns */ module.exports = (lng = 'en', ns = 'portal') => { const i18nextInstance = i18next.createInstance(); diff --git a/ghost/i18n/package.json b/ghost/i18n/package.json index 79e12e12e9..ddba8c0130 100644 --- a/ghost/i18n/package.json +++ b/ghost/i18n/package.json @@ -5,8 +5,10 @@ "author": "Ghost Foundation", "private": true, "main": "index.js", + "types": "./build/i18n.d.ts", "scripts": { "dev": "echo \"Implement me!\"", + "build": "tsc", "test:unit:base": "NODE_ENV=testing c8 --include index.js --include lib --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'", "test:unit": "yarn test:unit:base && yarn translate", "test": "yarn test:unit", @@ -25,7 +27,8 @@ "devDependencies": { "c8": "7.13.0", "i18next-parser": "8.0.0", - "mocha": "10.2.0" + "mocha": "10.2.0", + "typescript": "5.0.4" }, "dependencies": { "i18next": "22.5.0" diff --git a/ghost/i18n/tsconfig.json b/ghost/i18n/tsconfig.json new file mode 100644 index 0000000000..d9f1f307aa --- /dev/null +++ b/ghost/i18n/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "./build", + "skipLibCheck": true, + "esModuleInterop": true + }, + "include": ["lib/**/*.js"], + "exclude": ["node_modules", "test"] + } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f1177396c3..cab1644c3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -31949,7 +31949,7 @@ typescript-memoize@^1.0.0-alpha.3, typescript-memoize@^1.0.1: resolved "https://registry.yarnpkg.com/typescript-memoize/-/typescript-memoize-1.1.1.tgz#02737495d5df6ebf72c07ba0d002e8f4cf5ccfa0" integrity sha512-GQ90TcKpIH4XxYTI2F98yEQYZgjNMOGPpOgdjIBhaLaWji5HPWlRnZ4AeA1hfBxtY7bCGDJsqDDHk/KaHOl5bA== -typescript@5.0.4: +typescript@5.0.4, typescript@^5.0.4: version "5.0.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==