From 7864e9d2b96824e891599025481567ddae1b9c6c Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 5 Jul 2023 13:07:28 +0200 Subject: [PATCH] Add new find script --- .gitignore | 3 + package-lock.json | 5 +- package.json | 276 +++++++++++++++++++---------------- scripts/find-localization.js | 60 ++++++++ 4 files changed, 220 insertions(+), 124 deletions(-) create mode 100644 scripts/find-localization.js diff --git a/.gitignore b/.gitignore index 6c3b1330..f850006d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ todo.md e2e/storage e2e/extensions e2e/sample + +localization.log +localization.md \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6138cfb6..b28ac114 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "@types/react": "17.0.0", "@types/react-datepicker": "^4.1.7", "@types/react-dom": "17.0.0", - "@types/vscode": "^1.70.0", + "@types/vscode": "^1.73.0", "@typescript-eslint/eslint-plugin": "^5.50.0", "@typescript-eslint/parser": "^5.50.0", "@vscode/codicons": "0.0.20", @@ -48,6 +48,7 @@ "assert": "^2.0.0", "autoprefixer": "^10.4.13", "chai": "^4.3.6", + "cheerio": "^1.0.0-rc.12", "css-loader": "5.2.7", "date-fns": "2.23.0", "downshift": "6.0.6", @@ -112,7 +113,7 @@ "yawn-yaml": "^1.5.0" }, "engines": { - "vscode": "^1.70.0" + "vscode": "^1.73.0" } }, "node_modules/@actions/core": { diff --git a/package.json b/package.json index 9c1fd6ea..202e8259 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "color": "#0e131f", "theme": "dark" }, - "badges": [{ + "badges": [ + { "description": "version", "url": "https://img.shields.io/github/package-json/v/estruyf/vscode-front-matter?color=green&label=vscode-front-matter&style=flat-square", "href": "https://github.com/estruyf/vscode-front-matter" @@ -61,7 +62,8 @@ "**/.frontmatter/config/*.json": "jsonc" } }, - "keybindings": [{ + "keybindings": [ + { "command": "frontMatter.dashboard", "key": "alt+d" }, @@ -79,20 +81,24 @@ } ], "viewsContainers": { - "activitybar": [{ - "id": "frontmatter-explorer", - "title": "Front Matter", - "icon": "assets/frontmatter-short-min.svg" - }] + "activitybar": [ + { + "id": "frontmatter-explorer", + "title": "Front Matter", + "icon": "assets/frontmatter-short-min.svg" + } + ] }, "views": { - "frontmatter-explorer": [{ - "id": "frontMatter.explorer", - "name": "Front Matter", - "icon": "assets/frontmatter-short-min.svg", - "contextualTitle": "Front Matter", - "type": "webview" - }] + "frontmatter-explorer": [ + { + "id": "frontMatter.explorer", + "name": "Front Matter", + "icon": "assets/frontmatter-short-min.svg", + "contextualTitle": "Front Matter", + "type": "webview" + } + ] }, "configuration": { "$id": "#globalconfiguration", @@ -156,7 +162,8 @@ "frontMatter.content.defaultFileType": { "type": "string", "default": "md", - "oneOf": [{ + "oneOf": [ + { "enum": [ "md", "mdx" @@ -172,7 +179,8 @@ "frontMatter.content.defaultSorting": { "type": "string", "default": "", - "oneOf": [{ + "oneOf": [ + { "enum": [ "LastModifiedAsc", "LastModifiedDesc", @@ -505,7 +513,8 @@ "command": { "$id": "#scriptCommand", "type": "string", - "anyOf": [{ + "anyOf": [ + { "enum": [ "node", "bash", @@ -705,7 +714,8 @@ "title", "file" ], - "anyOf": [{ + "anyOf": [ + { "required": [ "schema" ] @@ -759,7 +769,8 @@ "id", "path" ], - "anyOf": [{ + "anyOf": [ + { "required": [ "schema" ] @@ -1127,7 +1138,8 @@ "default": "", "description": "The ID of your taxonomy field. It cannot contain the \"tags\" or \"categories\" value.", "not": { - "anyOf": [{ + "anyOf": [ + { "const": "" }, { @@ -1311,7 +1323,8 @@ "type", "name" ], - "allOf": [{ + "allOf": [ + { "if": { "properties": { "type": { @@ -1483,48 +1496,51 @@ "fields" ] }, - "default": [{ - "name": "default", - "pageBundle": false, - "fields": [{ - "title": "Title", - "name": "title", - "type": "string" - }, - { - "title": "Description", - "name": "description", - "type": "string" - }, - { - "title": "Publishing date", - "name": "date", - "type": "datetime", - "default": "{{now}}", - "isPublishDate": true - }, - { - "title": "Content preview", - "name": "preview", - "type": "image" - }, - { - "title": "Is in draft", - "name": "draft", - "type": "boolean" - }, - { - "title": "Tags", - "name": "tags", - "type": "tags" - }, - { - "title": "Categories", - "name": "categories", - "type": "categories" - } - ] - }], + "default": [ + { + "name": "default", + "pageBundle": false, + "fields": [ + { + "title": "Title", + "name": "title", + "type": "string" + }, + { + "title": "Description", + "name": "description", + "type": "string" + }, + { + "title": "Publishing date", + "name": "date", + "type": "datetime", + "default": "{{now}}", + "isPublishDate": true + }, + { + "title": "Content preview", + "name": "preview", + "type": "image" + }, + { + "title": "Is in draft", + "name": "draft", + "type": "boolean" + }, + { + "title": "Tags", + "name": "tags", + "type": "tags" + }, + { + "title": "Categories", + "name": "categories", + "type": "categories" + } + ] + } + ], "scope": "Taxonomy" }, "frontMatter.taxonomy.customTaxonomy": { @@ -1537,7 +1553,8 @@ "type": "string", "description": "ID for your taxonomy field. It cannot contain the \"tags\" or \"categories\" value.", "not": { - "anyOf": [{ + "anyOf": [ + { "const": "" }, { @@ -1719,7 +1736,8 @@ } } }, - "commands": [{ + "commands": [ + { "command": "frontMatter.project.switch", "title": "Switch project", "category": "Front Matter", @@ -2048,12 +2066,15 @@ "category": "Front Matter" } ], - "submenus": [{ - "id": "frontmatter.submenu", - "label": "Front Matter" - }], + "submenus": [ + { + "id": "frontmatter.submenu", + "label": "Front Matter" + } + ], "menus": { - "editor/title": [{ + "editor/title": [ + { "command": "frontMatter.markup.heading", "group": "navigation@-133", "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" @@ -2134,11 +2155,14 @@ "when": "resourceFilename == 'frontmatter.json'" } ], - "explorer/context": [{ - "submenu": "frontmatter.submenu", - "group": "frontmatter@1" - }], - "frontmatter.submenu": [{ + "explorer/context": [ + { + "submenu": "frontmatter.submenu", + "group": "frontmatter@1" + } + ], + "frontmatter.submenu": [ + { "command": "frontMatter.createFromTemplate", "when": "explorerResourceIsFolder", "group": "frontmatter@1" @@ -2154,7 +2178,8 @@ "group": "frontmatter@3" } ], - "commandPalette": [{ + "commandPalette": [ + { "command": "frontMatter.init", "when": "frontMatterCanInit" }, @@ -2299,7 +2324,8 @@ "when": "frontMatter:file:isValid == true" } ], - "view/title": [{ + "view/title": [ + { "command": "frontMatter.chatbot", "group": "navigation@0", "when": "view == frontMatter.explorer" @@ -2326,52 +2352,57 @@ } ] }, - "grammars": [{ - "path": "./syntaxes/hugo.tmLanguage.json", - "scopeName": "frontmatter.markdown.hugo", - "injectTo": [ - "text.html.markdown" - ] - }], - "walkthroughs": [{ - "id": "frontmatter.welcome", - "title": "Get started with Front Matter", - "description": "Discover the features of Front Matter and learn how to use the CMS for your SSG or static site.", - "steps": [{ - "id": "frontmatter.welcome.init", - "title": "Get started", - "description": "Initial steps to get started.\n[Open dashboard](command:frontMatter.dashboard)", - "media": { - "markdown": "assets/walkthrough/get-started.md" + "grammars": [ + { + "path": "./syntaxes/hugo.tmLanguage.json", + "scopeName": "frontmatter.markdown.hugo", + "injectTo": [ + "text.html.markdown" + ] + } + ], + "walkthroughs": [ + { + "id": "frontmatter.welcome", + "title": "Get started with Front Matter", + "description": "Discover the features of Front Matter and learn how to use the CMS for your SSG or static site.", + "steps": [ + { + "id": "frontmatter.welcome.init", + "title": "Get started", + "description": "Initial steps to get started.\n[Open dashboard](command:frontMatter.dashboard)", + "media": { + "markdown": "assets/walkthrough/get-started.md" + }, + "completionEvents": [ + "onContext:frontMatterInitialized" + ] }, - "completionEvents": [ - "onContext:frontMatterInitialized" - ] - }, - { - "id": "frontmatter.welcome.documentation", - "title": "Documentation", - "description": "Check out the documentation for Front Matter.\n[View our documentation](https://frontmatter.codes/docs)", - "media": { - "markdown": "assets/walkthrough/documentation.md" + { + "id": "frontmatter.welcome.documentation", + "title": "Documentation", + "description": "Check out the documentation for Front Matter.\n[View our documentation](https://frontmatter.codes/docs)", + "media": { + "markdown": "assets/walkthrough/documentation.md" + }, + "completionEvents": [ + "onLink:https://frontmatter.codes/docs" + ] }, - "completionEvents": [ - "onLink:https://frontmatter.codes/docs" - ] - }, - { - "id": "frontmatter.welcome.supporter", - "title": "Support the project", - "description": "Become a supporter.\n[Support the project](https://github.com/sponsors/estruyf)", - "media": { - "markdown": "assets/walkthrough/support-the-project.md" - }, - "completionEvents": [ - "onLink:https://github.com/sponsors/estruyf" - ] - } - ] - }] + { + "id": "frontmatter.welcome.supporter", + "title": "Support the project", + "description": "Become a supporter.\n[Support the project](https://github.com/sponsors/estruyf)", + "media": { + "markdown": "assets/walkthrough/support-the-project.md" + }, + "completionEvents": [ + "onLink:https://github.com/sponsors/estruyf" + ] + } + ] + } + ] }, "scripts": { "dev:ext": "npm run clean && npm run localization:generate && npm-run-all --parallel watch:*", @@ -2436,6 +2467,7 @@ "assert": "^2.0.0", "autoprefixer": "^10.4.13", "chai": "^4.3.6", + "cheerio": "^1.0.0-rc.12", "css-loader": "5.2.7", "date-fns": "2.23.0", "downshift": "6.0.6", @@ -2502,4 +2534,4 @@ "vsce": { "dependencies": false } -} \ No newline at end of file +} diff --git a/scripts/find-localization.js b/scripts/find-localization.js new file mode 100644 index 00000000..2ebec949 --- /dev/null +++ b/scripts/find-localization.js @@ -0,0 +1,60 @@ +const fs = require('fs'); +const path = require('path'); +const glob = require('glob'); +const cheerio = require('cheerio'); + +const files = glob.sync('src/**/*.ts*'); +console.log('Total files:', files.length); + +const enumFile = fs.createWriteStream(path.join(__dirname, '../localization.log')); + +// for (const file of files) { +// // Get the file and its contents +// const fileContent = fs.readFileSync(path.join(__dirname, "../", file), 'utf8'); + +// const regex = />[A-Za-z]{1,}/g; + +// const matches = fileContent.match(regex); + +// if (matches && matches.length > 0) { +// enumFile.write(`File: ${path.join(__dirname, "../", file)}\n`); +// enumFile.write(`Matches: ${matches.toString()}\n`); +// enumFile.write(`\n`); +// } +// } + +for (const file of files) { + const fileContent = fs.readFileSync(path.join(__dirname, "../", file), 'utf8'); + + const $ = cheerio.load(fileContent, { + recognizeSelfClosing: true, + xmlMode: true, + }); + + const matches = []; + + $('*').each(function () { + const node = $(this); + + let text = node.contents().first().text(); + text = text.trim(); + + if (text && + !text.startsWith('{') && + !text.includes(`{`) && + !text.includes(`}`) && + !text.includes(`(`) && + !text.includes(`)`) && + text.split('\n').length === 1) { + matches.push(`Text: ${text}\n`); + } + }); + + if (matches && matches.length > 0) { + enumFile.write(`File: ${path.join(__dirname, "../", file)}\n`); + enumFile.write(`${matches.join('')}\n`); + enumFile.write(`\n`); + } +} + +enumFile.close(); \ No newline at end of file