{"id":28214528,"url":"https://github.com/goodrequest/joi-messages-extractor","last_synced_at":"2025-06-11T23:31:30.303Z","repository":{"id":81791989,"uuid":"557158400","full_name":"GoodRequest/joi-messages-extractor","owner":"GoodRequest","description":"Script for extracting joi messages. Useful for translations.","archived":false,"fork":false,"pushed_at":"2024-06-12T06:48:03.000Z","size":140,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-05T06:53:25.989Z","etag":null,"topics":["backend","i18n","joi","nodejs","typescript","web-utils"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoodRequest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-25T07:20:15.000Z","updated_at":"2024-06-12T06:48:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b93b7c9-84af-453b-87e4-4279f1c15ae0","html_url":"https://github.com/GoodRequest/joi-messages-extractor","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/GoodRequest/joi-messages-extractor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-messages-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-messages-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-messages-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-messages-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoodRequest","download_url":"https://codeload.github.com/GoodRequest/joi-messages-extractor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-messages-extractor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259363017,"owners_count":22846183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","i18n","joi","nodejs","typescript","web-utils"],"created_at":"2025-05-17T21:08:01.409Z","updated_at":"2025-06-11T23:31:30.292Z","avatar_url":"https://github.com/GoodRequest.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# joi-messages-extractor\n\nThis script creates joiErrorMessages.ts file which contain all possible error messages which could be generated by Joi and exports them like *joiErrorMessages*. *joiErrorMessages* object can be used for custom translations of Joi error messages.\n\nTested versions:\n* 17.6.4 +\n* 17.6.3 +\n* 17.6.0 +\n* 17.5.0 +\n* 17.4.0 +\n* 17.3.0 +\n* 17.2.0 +\n* 17.1.1 - Problem with TypeScript types. Error message: Could not find a declaration file for module 'joi'\n## Usage\n\nScript is using environment variables:\n\n- JOI_MESSAGES_FILE_PATH - which describes the folder where joiErrorMessages.ts will be generated. **By default** the same folder with script\n- JOI_CHECK_ONLY - Is a boolean. *false* - generate joiErrorMessages.ts, *true* - check translations and if there are missing some throw an error. **By default** is *false*\n\nFor running this script is used the following command:\n\n``npx GoodRequest/joi-messages-extractor``\n\nBut this script is recommended to install with npm: \n\n``npm install GoodRequest/joi-messages-extractor``\n\nAnd use like:\n\n``npx joi-messages-extractor``\n\nUsage example with env variables in command:\n\n``cross-env JOI_MESSAGES_FILE_PATH=./locales JOI_CHECK_ONLY=false npx GoodRequest/joi-messages-extractor``\n\n## Error messages file - joiErrorMessages.ts\n\njoiErrorMessages.ts - is a default filename where all Joi error message keys with default translations are generated and exported. With common usage this file will never be overwritten, it will be appended with missing types only. File has the following structure:\n\n```typescript\nconst joiErrorMessages: any = {\n    en: {\n        'any.custom': '{{#label}} failed custom validation because {{#error.message}}',\n        'any.default': '{{#label}} threw an error when running default method',\n        ...\n    },\n    sk: {\n        'any.custom': '{{#label}} failed custom validation because {{#error.message}}',\n        'any.default': '{{#label}} threw an error when running default method',\n        ...\n    },\n    ...\n}\nexport default joiErrorMessages\n```\nIt contains keys *.en* and *.sk* which describe translation language. Script is trying to find them in *i18next.fallbackLng* from config module. Default values are *.en* and *.sk*.\n\nEach key contains type of Joi error message, and it's translation. By default all messages are in English and must be translated manually.\n\n## Usage of joiErrorMessages.ts in code\n\nTo use custom error messages is enough to pass *joiErrorMessages* object to Joi validation methode:\n\n```typescript\nimport joiErrorMessages from 'joiErrorMessages.ts' // Importing our generated messages\nimport i18next from 'i18next' // Importing i18next\n\nconst result = schema.validate(validationValue, { \n    messages: joiErrorMessages, // Passing joiErrorMessages object to Joi\n    errors: { \n        language: i18next.resolvedLanguage // Telling Joi which langage to use\n    } \n})\n```\n\nAs a result, in case of error we'll get a custom error message from Joi. Such patterns like *{{#label}}* or *{{#limit}} key{if(#limit == 1, \"\", \"s\")}* will be compiled by Joi itself.\n\n## Usage script in pipelines\n\nTo avoid mistakes in project this script could be usefully to use in pipelines, for example *bitbucket-pipelines.yml*\n\n```yaml\nimage: node:10.15.0\n   \npipelines:\n  default:\n    - step:\n        name: Build and test\n        script:\n          - npm install\n          - npm test\n          - npm joi:check\n```\n\n*joi:extract* in *package.json*:\n\n```json\n\"scripts\": {\n    \"joi:check\": \"cross-env JOI_MESSAGES_FILE_PATH=./locales JOI_CHECK_ONLY=true npx joi-messages-extractor\",\n    ...\n},\n...\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodrequest%2Fjoi-messages-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodrequest%2Fjoi-messages-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodrequest%2Fjoi-messages-extractor/lists"}