`check-usage`: Finds translation calls in source code and checks if keys exist in en.ts
()
| 603 | |
| 604 | /** `check-usage`: Finds translation calls in source code and checks if keys exist in en.ts */ |
| 605 | async function checkUsage() { |
| 606 | console.log('Checking i18n key usage in source code...\n'); |
| 607 | |
| 608 | const manifest = loadJson(MANIFEST_PATH); |
| 609 | |
| 610 | if (Object.keys(manifest).length === 0) { |
| 611 | console.error('❌ Error: No manifest found. Run "npm run i18n:sync" first.'); |
| 612 | process.exit(1); |
| 613 | } |
| 614 | |
| 615 | // Find all translation function calls in the codebase using ripgrep |
| 616 | // Matches: t("key"), translate("key"), this.t("key"), this.translate("key"), and plugin.i18n.translate("key") |
| 617 | let grepOutput1 = ''; |
| 618 | let grepOutput2 = ''; |
| 619 | let grepOutput3 = ''; |
| 620 | let grepOutput4 = ''; |
| 621 | let grepOutput5 = ''; |
| 622 | |
| 623 | try { |
| 624 | // Pattern 1: t("key") - standalone function |
| 625 | grepOutput1 = execSync( |
| 626 | `rg --no-filename --no-heading --no-line-number '\\bt\\(["\\x27]([^"\\x27]+)["\\x27]\\)' -o -r '\$1' src/`, |
| 627 | { encoding: 'utf8', shell: '/bin/bash' } |
| 628 | ); |
| 629 | } catch (error) { |
| 630 | if (error.status !== 1) throw error; |
| 631 | // No matches is fine |
| 632 | } |
| 633 | |
| 634 | try { |
| 635 | // Pattern 2: plugin.i18n.translate("key") or i18n.translate("key") |
| 636 | grepOutput2 = execSync( |
| 637 | `rg --no-filename --no-heading --no-line-number 'i18n\\.translate\\(["\\x27]([^"\\x27]+)["\\x27]' -o -r '\$1' src/`, |
| 638 | { encoding: 'utf8', shell: '/bin/bash' } |
| 639 | ); |
| 640 | } catch (error) { |
| 641 | if (error.status !== 1) throw error; |
| 642 | // No matches is fine |
| 643 | } |
| 644 | |
| 645 | try { |
| 646 | // Pattern 3: this.t("key") |
| 647 | grepOutput3 = execSync( |
| 648 | `rg --no-filename --no-heading --no-line-number 'this\\.t\\(["\\x27]([^"\\x27]+)["\\x27]' -o -r '\$1' src/`, |
| 649 | { encoding: 'utf8', shell: '/bin/bash' } |
| 650 | ); |
| 651 | } catch (error) { |
| 652 | if (error.status !== 1) throw error; |
| 653 | // No matches is fine |
| 654 | } |
| 655 | |
| 656 | try { |
| 657 | // Pattern 4: this.translate("key") |
| 658 | grepOutput4 = execSync( |
| 659 | `rg --no-filename --no-heading --no-line-number 'this\\.translate\\(["\\x27]([^"\\x27]+)["\\x27]' -o -r '\$1' src/`, |
| 660 | { encoding: 'utf8', shell: '/bin/bash' } |
| 661 | ); |
| 662 | } catch (error) { |
no test coverage detected