Skip to content

feat: add unused locales #2463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/khaki-ways-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unused-i18n": patch
---

Add unused locales to scaleway-lib
82 changes: 19 additions & 63 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,107 +1,63 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"assignees": [
"team:console"
],
"assignees": ["team:console"],
"assigneesSampleSize": 1,
"automerge": false,
"dependencyDashboard": true,
"enabledManagers": [
"github-actions",
"npm"
],
"extends": [
"config:recommended",
":combinePatchMinorReleases"
],
"labels": [
"dependencies"
],
"enabledManagers": ["github-actions", "npm"],
"extends": ["config:recommended", ":combinePatchMinorReleases"],
"labels": ["dependencies"],
"prConcurrentLimit": 10,
"prHourlyLimit": 5,
"rangeStrategy": "pin",
"rebaseWhen": "auto",
"reviewers": [
"team:console"
],
"reviewers": ["team:console"],
"reviewersSampleSize": 2,
"semanticCommitScope": "deps",
"semanticCommitType": "chore",
"ignorePaths": [
"packages_deprecated/**/package.json"
],
"ignorePaths": ["packages_deprecated/**/package.json"],
"packageRules": [
{
"matchDepTypes": [
"engines",
"peerDependencies"
],
"matchDepTypes": ["engines", "peerDependencies"],
"rangeStrategy": "widen"
},
{
"matchManagers": [
"github-actions"
],
"matchManagers": ["github-actions"],
"semanticCommitScope": "devDeps",
"automerge": true,
"autoApprove": true
},
{
"semanticCommitScope": "devDeps",
"matchDepTypes": [
"packageManager",
"devDependencies"
],
"matchUpdateTypes": [
"major"
]
"matchDepTypes": ["packageManager", "devDependencies"],
"matchUpdateTypes": ["major"]
},
{
"semanticCommitScope": "devDeps",
"matchDepTypes": [
"packageManager",
"devDependencies"
],
"matchUpdateTypes": [
"minor",
"patch"
]
"matchDepTypes": ["packageManager", "devDependencies"],
"matchUpdateTypes": ["minor", "patch"]
},
{
"labels": [
"UPDATE-MAJOR"
],
"labels": ["UPDATE-MAJOR"],
"minimumReleaseAge": "14 days",
"matchUpdateTypes": [
"major"
]
"matchUpdateTypes": ["major"]
},
{
"labels": [
"UPDATE-MINOR"
],
"labels": ["UPDATE-MINOR"],
"minimumReleaseAge": "7 days",
"matchUpdateTypes": [
"minor"
],
"matchUpdateTypes": ["minor"],
"automerge": true,
"autoApprove": true
},
{
"labels": [
"UPDATE-PATCH"
],
"labels": ["UPDATE-PATCH"],
"minimumReleaseAge": "3 days",
"matchUpdateTypes": [
"patch"
],
"matchUpdateTypes": ["patch"],
"automerge": true,
"autoApprove": true
},
{
"matchDepTypes": [
"engines"
],
"matchDepTypes": ["engines"],
"rangeStrategy": "widen"
}
]
Expand Down
7 changes: 7 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,11 @@ export default [
'import/no-relative-packages': 'off',
},
},
{
files: ['packages/unused-i18n/**/*.ts'],
rules: {
'no-console': 'off',
'no-cond-assign': 'off',
},
},
]
5 changes: 5 additions & 0 deletions packages/unused-i18n/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": "off"
}
}
5 changes: 5 additions & 0 deletions packages/unused-i18n/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/__tests__/**
examples/
src
.eslintrc.cjs
!.npmignore
120 changes: 120 additions & 0 deletions packages/unused-i18n/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Unused i18n

Simplifies managing and cleaning up unused translation keys in localization files

## Features

- Analyzes source files to identify used and unused translation keys.
- Supports multiple scoped translation functions.
- Can display or remove unused translation keys.
- Configurable through a JSON, CJS, or JS config file.

## Installation

You can install `unused-i18n` via npm:

```sh
npm install -g unused-i18n

or

npm install -D unused-i18n
```

## Configuration

Create a unused-i18n.config.json or unused-i18n.config.js file in the root of your project. Here's an example configuration:

```cjs
module.exports = {
paths: [
{
srcPath: ['src/pages/products'],
localPath: 'src/pages/products/locales',
},
],
localesExtensions: 'ts',
localesNames: 'en',
scopedNames: ['scopedT', 'scopedTOne'],
ignorePaths: ['src/pages/products/ignoreThisFolder'],
excludeKey: ['someKey'],
}
```

| Option | Type | Default | Required | Description |
| ------------------- | ---------------- | ------- | -------- | ---------------------------------------------------------------------------- |
| `paths` | Array of Objects | `[]` | Yes | An array of objects defining the source paths and local paths to be checked. |
| `paths.srcPath` | Array of Strings | `[]` | Yes | Source paths to search for translations. |
| `paths.localPath` | Strings | `""` | Yes | Path to the translation files. |
| `localesExtensions` | String | `js` | No | Extension of the locale files. |
| `localesNames` | String | `en` | No | Name of the locale files without the extension. |
| `scopedNames` | Array of Strings | `[]` | No | Names of the scoped translation functions used in your project. |
| `ignorePaths` | Array of Strings | `[]` | No | Paths to be ignored during the search. |
| `excludeKey` | Array of Strings | `[]` | No | Specific translation keys to be excluded from the removal process. |

## Usage

### Using with Config File

To use unused-i18n with your config file, simply run:

```sh
npx unused-i18n display
```

### Using with Command Line Options

You can also specify the source and local paths directly in the command line:

##### Display Unused Translations

```sh
npx unused-i18n display --srcPath="src/folders/bla" --localPath="src/folders/bla/locales"
```

##### Remove Unused Translations

```sh
npx unused-i18n remove --srcPath="src/folders/bla" --localPath="src/folders/bla/locales"
```

## API

`processTranslations(paths, action)`
Processes translations based on the specified paths and action.

- paths: Array of objects containing srcPath and localPath.
- action: Action to perform, either 'display' or 'remove'.

## Development

### Building the Project

To build the project, run:

```sh
npm run build
```

#### Running Tests

To run the tests, use:

```sh
npm run test
```

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/Lawndlwd/unused-i18n/blob/HEAD/LICENSE) file for details.

## Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or suggestions.

Acknowledgements

- [Vite](https://vitejs.dev/) - Next Generation Frontend Tooling.
- [TypeScript](https://www.typescriptlang.org/) - Typed JavaScript used in this project.
- [Vitest](https://vitest.dev/guide/cli) - Testing framework used in this project.
- [Commander](https://github.com/tj/commander.js#readme) - Node.js command-line interfaces.
51 changes: 51 additions & 0 deletions packages/unused-i18n/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "unused-i18n",
"version": "0.2.0",
"description": "React provider to handle website end user consent cookie storage based on segment integrations",
"type": "module",
"main": "dist/cli.cjs",
"types": "dist/index.d.ts",
"bin": {
"unused-i18n": "dist/cli.cjs"
},
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"prebuild": "shx rm -rf dist",
"build": "vite build --config vite.config.ts && pnpm run type:generate",
"type:generate": "tsc --declaration -p tsconfig.build.json",
"typecheck": "tsc --noEmit",
"release": "pnpm build && pnpm changeset publish",
"coverage": "vitest run --coverage",
"lint": "eslint --report-unused-disable-directives --cache --cache-strategy content --ext ts,tsx .",
"test:unit": "vitest --run --config vite.config.ts",
"test:unit:coverage": "pnpm test:unit --coverage"
},
"repository": {
"type": "git",
"url": "https://github.com/scaleway/scaleway-lib",
"directory": "packages/unused-i18n"
},
"dependencies": {
"commander": "12.1.0",
"esbuild": "0.24.2"
},
"keywords": [
"i18n",
"unused-i18n",
"i18n-unused",
"locales",
"next-international",
"internationalization",
"translate",
"next"
],
"engines": {
"node": ">=22.x",
"pnpm": ">=9.x"
}
}
Loading
Loading