An open API service indexing awesome lists of open source software.

https://github.com/betomorrow/clean-wording

Utility for cleaning up unused wordings
https://github.com/betomorrow/clean-wording

Last synced: 9 months ago
JSON representation

Utility for cleaning up unused wordings

Awesome Lists containing this project

README

          

# Clean-Wording

## Description

Utility for cleaning up unused wordings.

## Create configuration

Create wording config file named for exemple '.clean_wording_config.json' at your project root location.

All required config :

```
{
"projectSourcePath": "",
"projectSourceParser": {
"parser": [
{ "type":"match", "regex": "" },
]
},
"wordingsSource": "",
}
```

All configs :

```
{
"projectSourcePath": "",
"projectSourceParser": {
"parser": [
{
"type": "",
"regex": "",
"position": ,
"by": "",
"post_regex": {
"type":"",
"regex": "",
"post_regex": {
...
}
}
},
...
],
onlyFilesWithExtensions: ["", ...]
},
"wordingsSource": "",
"wordingsSourceParser": {
"replaces": [
{ "regex": "", "by": "" },
...
],
},
"compare" : {
"dynamicRegexValue": ""
}
}
```

Exemple for a React project (simple) :

```
{
"projectSourcePath": "src/",
"projectSourceParser": {
"parser": [{ "type": "match", "regex": "i18n\\.t\\(\"((.|\n)+?)\"" }]
},
"wordingsSource": "assets/strings/map.json",
"wordingsSourceParser": {
"replaces": [
{
"_comment": "remove .zero & .one & .other",
"regex": "(.zero|.one|.other)$"
}
]
}
}
```

Exemple for a React project (more complexe -> trying to manage dynamic wordings) :

```
{
"projectSourcePath": "src/",
"projectSourceParser": {
"parser": [
{
"_comment": "match all I18n.t(*)",
"type": "match",
"regex": "I18n\\.t\\(((?:[^()]*|\\((?:[^()]*|\\([^()]*\\))*\\))*)\\)",
"post_regex": {
"_comment": "match all \"*\" ",
"type": "match",
"regex": "(?:\"|`|')(.*?)(?:\"|`|')",
"post_regex": {
"_comment": "replace dynamic value by *",
"type": "replace",
"regex": "(\\${.*})",
"by": "*",
"post_regex": {
"_comment": "keep only valid wordings because previous regex can have bad values",
"type": "replace",
"regex": "^.*[^a-zA-Z0-9._\\-*].*$",
}
}
}
}
]
},
"wordingsSource": "assets/strings/EN-en.json"
"wordingsSourceParser": {
"replaces": [
{
"_comment": "remove wordings used only for config, store, ...",
"regex": "(NSCameraUsageDescription)|<...>"
}
]
}
"compare" : {
"dynamicRegexValue": "\\*"
}
}
```

Exemple for a Flutter project :

```
{
"projectSourcePath": "lib/src/",
"projectSourceParser": {
"parser": [
{ "type": "match", "regex": "context\\.curLocalizations\\.([a-zA-Z0-9_]+)" },
{ "type": "match", "regex": "AppLocalizations\\.of\\(context\\)!?\\.([a-zA-Z0-9_]+)" }
]
},
"wordingsSource": "lib/asset/translations/intl_fr.arb",
"wordingsSourceParser": {
"replaces": [
{
"_comment": "remove all keys begining by @",
"regex": "^@.*"
}
]
}
}
```

## Integration & Run

### React

Install it as dev dependencies

```
# With npm

npm install @betomorrow/clean-wording --save-dev

# With yarn

yarn add @betomorrow/clean-wording --save-dev
```

Add scripts lines to invoke tools easily with npm in package.json

```
{
"scripts": {
"clean-wording": "clean-wording -c .clean_wording_config.json"
}
}
```

### Flutter

Use directly this command

```
npx -p @betomorrow/clean-wording clean-wording -c .clean_wording_config.json
```

## Command options

```
Options:
-c, --config [Required] Path on config json file (ex: .clean_wording_config.json)
-sp, --showAllProjectWordingKeys Show all detected project wording-keys
-sf, --showAllFileWordingKeys Show all detected file wording-keys
-spo, --showOrphanProjectKeys Show project wording-keys not present in the file wording-keys
-sfo, --showOrphanFileWordingKeys [Default] Show file wording-keys not present in the project wording-keys
-v, --verbose show verbose logs
-h, --help display help for command
```