cal/i18n-unused.config.js
Richard Poelderl 829a103f6b
chore: enable i18n-unused GH action in `website` (#10296)
* regen yarn.lock?

* chore: enable i18n-unused GH action in `website`

* Generated yarn.lock with submodules

* Added yarn.lock auth

---------

Co-authored-by: Alex van Andel <me@alexvanandel.com>
2023-07-25 18:30:18 +01:00

36 lines
1.5 KiB
JavaScript

const path = require("path");
/**
* # Regex for translation keys
* This regex matches the following function calls:
* 1. `t("<some_key>")`,
* 2. `t("<some_key>", {key: "<some_string>"})`, or
* 3. `<Trans i18nKey="home_hero_subtitle" t={t}>`
*
* It also ensure that we don't match any other similar function calls (e.g. `format("dddd")`).
*
* ## Explanation of the regex
* - (?<!\w): negative lookbehind to ensure that there is no word character before "t" or "i18nKey"
* - (?: ... ): non-capturing group
* - t: for the use of `t("..")` OR `t("..", {key: ".."})`
* - \(("[^"]*"): captures a string enclosed in double quotes followed by an opening parenthesis
* - (?:,\s*\{[^}]*\})?: optional non-capturing group so that we match the optional interpolation object
* - i18nKey=".+"[^\w]: for the usage of `<Trans i18nKey="home_hero_subtitle" t={t}>`
*
* */
const translationKeyRegex = /(?<!\w)(?:t\(("[^"]*")(?:,\s*\{[^}]*\})?\)|i18nKey=".+"[^\w])/gi;
/** @type {import("i18n-unused/src/types/index.ts").RunOptions} */
const config = {
// localesPath: localePath, // uncomment to run on all locales (to calculate kb savings)
localesPath: path.join("./apps/website", "/public/static/locales", "/en"),
srcPath: "./apps/website",
srcExtensions: ["ts", "tsx"],
translationContextSeparator: ":",
translationKeyMatcher: translationKeyRegex,
missedTranslationParser: translationKeyRegex,
ignorePaths: ["node_modules", ".next"],
};
module.exports = config;