gtx-cli 2.6.31 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -1261
- package/README.md +12 -3
- package/dist/bin/bin-entry.js +2 -1
- package/dist/config/generateSettings.d.ts +1 -9
- package/dist/config/generateSettings.js +1 -214
- package/dist/config/resolveConfig.d.ts +1 -4
- package/dist/config/resolveConfig.js +1 -33
- package/dist/fs/config/setupConfig.d.ts +1 -17
- package/dist/fs/config/setupConfig.js +1 -50
- package/dist/fs/matchFiles.d.ts +1 -1
- package/dist/fs/matchFiles.js +1 -8
- package/dist/functions.d.ts +1 -7
- package/dist/functions.js +1 -6
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -27
- package/dist/main.js +2 -2
- package/dist/next/parse/handleInitGT.d.ts +1 -7
- package/dist/next/parse/handleInitGT.js +1 -157
- package/dist/next/parse/wrapContent.d.ts +1 -12
- package/dist/next/parse/wrapContent.js +1 -164
- package/dist/react/parse/wrapContent.d.ts +1 -12
- package/dist/react/parse/wrapContent.js +1 -162
- package/dist/types/index.d.ts +1 -243
- package/dist/types/index.js +1 -1
- package/dist/utils/installPackage.d.ts +1 -3
- package/dist/utils/installPackage.js +1 -77
- package/dist/utils/packageInfo.d.ts +1 -3
- package/dist/utils/packageInfo.js +1 -17
- package/dist/utils/packageJson.d.ts +1 -6
- package/dist/utils/packageJson.js +1 -68
- package/dist/utils/packageManager.d.ts +1 -28
- package/dist/utils/packageManager.js +1 -269
- package/package.json +11 -97
- package/dist/api/collectUserEditDiffs.d.ts +0 -9
- package/dist/api/collectUserEditDiffs.js +0 -159
- package/dist/api/downloadFileBatch.d.ts +0 -23
- package/dist/api/downloadFileBatch.js +0 -190
- package/dist/api/saveLocalEdits.d.ts +0 -6
- package/dist/api/saveLocalEdits.js +0 -38
- package/dist/cli/base.d.ts +0 -59
- package/dist/cli/base.js +0 -529
- package/dist/cli/commands/download.d.ts +0 -8
- package/dist/cli/commands/download.js +0 -51
- package/dist/cli/commands/enqueue.d.ts +0 -9
- package/dist/cli/commands/enqueue.js +0 -27
- package/dist/cli/commands/setupProject.d.ts +0 -7
- package/dist/cli/commands/setupProject.js +0 -37
- package/dist/cli/commands/stage.d.ts +0 -9
- package/dist/cli/commands/stage.js +0 -59
- package/dist/cli/commands/translate.d.ts +0 -7
- package/dist/cli/commands/translate.js +0 -70
- package/dist/cli/commands/upload.d.ts +0 -13
- package/dist/cli/commands/upload.js +0 -142
- package/dist/cli/commands/utils/validation.d.ts +0 -13
- package/dist/cli/commands/utils/validation.js +0 -38
- package/dist/cli/flags.d.ts +0 -15
- package/dist/cli/flags.js +0 -70
- package/dist/cli/inline.d.ts +0 -17
- package/dist/cli/inline.js +0 -135
- package/dist/cli/next.d.ts +0 -10
- package/dist/cli/next.js +0 -12
- package/dist/cli/node.d.ts +0 -10
- package/dist/cli/node.js +0 -9
- package/dist/cli/react.d.ts +0 -12
- package/dist/cli/react.js +0 -72
- package/dist/config/optionPresets.d.ts +0 -3
- package/dist/config/optionPresets.js +0 -65
- package/dist/config/utils.d.ts +0 -2
- package/dist/config/utils.js +0 -4
- package/dist/config/validateSettings.d.ts +0 -3
- package/dist/config/validateSettings.js +0 -32
- package/dist/console/colors.d.ts +0 -6
- package/dist/console/colors.js +0 -19
- package/dist/console/displayTranslateSummary.d.ts +0 -1
- package/dist/console/displayTranslateSummary.js +0 -42
- package/dist/console/formatting.d.ts +0 -1
- package/dist/console/formatting.js +0 -7
- package/dist/console/index.d.ts +0 -34
- package/dist/console/index.js +0 -46
- package/dist/console/logger.d.ts +0 -35
- package/dist/console/logger.js +0 -250
- package/dist/console/logging.d.ts +0 -52
- package/dist/console/logging.js +0 -175
- package/dist/formats/files/aggregateFiles.d.ts +0 -4
- package/dist/formats/files/aggregateFiles.js +0 -156
- package/dist/formats/files/collectFiles.d.ts +0 -6
- package/dist/formats/files/collectFiles.js +0 -49
- package/dist/formats/files/convertToFileTranslationData.d.ts +0 -15
- package/dist/formats/files/convertToFileTranslationData.js +0 -21
- package/dist/formats/files/fileMapping.d.ts +0 -11
- package/dist/formats/files/fileMapping.js +0 -115
- package/dist/formats/files/preprocess/mdx.d.ts +0 -6
- package/dist/formats/files/preprocess/mdx.js +0 -14
- package/dist/formats/files/preprocess/mintlify.d.ts +0 -5
- package/dist/formats/files/preprocess/mintlify.js +0 -15
- package/dist/formats/files/preprocessContent.d.ts +0 -8
- package/dist/formats/files/preprocessContent.js +0 -23
- package/dist/formats/files/save.d.ts +0 -5
- package/dist/formats/files/save.js +0 -17
- package/dist/formats/files/supportedFiles.d.ts +0 -11
- package/dist/formats/files/supportedFiles.js +0 -20
- package/dist/formats/json/extractJson.d.ts +0 -15
- package/dist/formats/json/extractJson.js +0 -101
- package/dist/formats/json/flattenJson.d.ts +0 -14
- package/dist/formats/json/flattenJson.js +0 -64
- package/dist/formats/json/mergeJson.d.ts +0 -13
- package/dist/formats/json/mergeJson.js +0 -367
- package/dist/formats/json/parseJson.d.ts +0 -2
- package/dist/formats/json/parseJson.js +0 -109
- package/dist/formats/json/utils.d.ts +0 -47
- package/dist/formats/json/utils.js +0 -150
- package/dist/formats/utils.d.ts +0 -2
- package/dist/formats/utils.js +0 -24
- package/dist/formats/yaml/mergeYaml.d.ts +0 -5
- package/dist/formats/yaml/mergeYaml.js +0 -61
- package/dist/formats/yaml/parseYaml.d.ts +0 -5
- package/dist/formats/yaml/parseYaml.js +0 -24
- package/dist/formats/yaml/utils.d.ts +0 -2
- package/dist/formats/yaml/utils.js +0 -23
- package/dist/fs/clearLocaleDirs.d.ts +0 -8
- package/dist/fs/clearLocaleDirs.js +0 -126
- package/dist/fs/config/downloadedVersions.d.ts +0 -21
- package/dist/fs/config/downloadedVersions.js +0 -50
- package/dist/fs/config/loadConfig.d.ts +0 -1
- package/dist/fs/config/loadConfig.js +0 -9
- package/dist/fs/config/parseFilesConfig.d.ts +0 -27
- package/dist/fs/config/parseFilesConfig.js +0 -150
- package/dist/fs/config/updateConfig.d.ts +0 -21
- package/dist/fs/config/updateConfig.js +0 -57
- package/dist/fs/config/updateVersions.d.ts +0 -11
- package/dist/fs/config/updateVersions.js +0 -30
- package/dist/fs/copyFile.d.ts +0 -7
- package/dist/fs/copyFile.js +0 -39
- package/dist/fs/createLoadTranslationsFile.d.ts +0 -1
- package/dist/fs/createLoadTranslationsFile.js +0 -49
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -53
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -90
- package/dist/fs/index.d.ts +0 -1
- package/dist/fs/index.js +0 -1
- package/dist/fs/loadJSON.d.ts +0 -6
- package/dist/fs/loadJSON.js +0 -17
- package/dist/fs/saveJSON.d.ts +0 -1
- package/dist/fs/saveJSON.js +0 -7
- package/dist/fs/utils.d.ts +0 -1
- package/dist/fs/utils.js +0 -16
- package/dist/generated/version.d.ts +0 -1
- package/dist/generated/version.js +0 -2
- package/dist/git/branches.d.ts +0 -7
- package/dist/git/branches.js +0 -88
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -110
- package/dist/locadex/setupFlow.d.ts +0 -2
- package/dist/locadex/setupFlow.js +0 -9
- package/dist/next/config/parseNextConfig.d.ts +0 -10
- package/dist/next/config/parseNextConfig.js +0 -53
- package/dist/next/jsx/utils.d.ts +0 -7
- package/dist/next/jsx/utils.js +0 -42
- package/dist/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -119
- package/dist/react/jsx/evaluateJsx.d.ts +0 -24
- package/dist/react/jsx/evaluateJsx.js +0 -123
- package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
- package/dist/react/jsx/utils/buildImportMap.js +0 -30
- package/dist/react/jsx/utils/constants.d.ts +0 -15
- package/dist/react/jsx/utils/constants.js +0 -49
- package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +0 -9
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +0 -32
- package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -21
- package/dist/react/jsx/utils/getPathsAndAliases.js +0 -91
- package/dist/react/jsx/utils/isNumberLiteral.d.ts +0 -7
- package/dist/react/jsx/utils/isNumberLiteral.js +0 -13
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.d.ts +0 -9
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +0 -138
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -197
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -33
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -918
- package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -65
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.d.ts +0 -2
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +0 -61
- package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
- package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
- package/dist/react/jsx/utils/mapAttributeName.d.ts +0 -11
- package/dist/react/jsx/utils/mapAttributeName.js +0 -12
- package/dist/react/jsx/utils/parseAst.d.ts +0 -31
- package/dist/react/jsx/utils/parseAst.js +0 -278
- package/dist/react/jsx/utils/parseDeclareStatic.d.ts +0 -15
- package/dist/react/jsx/utils/parseDeclareStatic.js +0 -540
- package/dist/react/jsx/utils/parseString.d.ts +0 -25
- package/dist/react/jsx/utils/parseString.js +0 -540
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -30
- package/dist/react/jsx/utils/parseStringFunction.js +0 -348
- package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
- package/dist/react/jsx/utils/resolveImportPath.js +0 -111
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts +0 -29
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +0 -86
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.d.ts +0 -14
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts +0 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +0 -31
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.d.ts +0 -22
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.js +0 -51
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.d.ts +0 -18
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +0 -39
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.d.ts +0 -24
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +0 -68
- package/dist/react/jsx/utils/stringParsing/types.d.ts +0 -41
- package/dist/react/jsx/utils/stringParsing/types.js +0 -1
- package/dist/react/jsx/utils/types.d.ts +0 -14
- package/dist/react/jsx/utils/types.js +0 -1
- package/dist/react/jsx/utils/validateStringFunction.d.ts +0 -7
- package/dist/react/jsx/utils/validateStringFunction.js +0 -31
- package/dist/react/jsx/wrapJsx.d.ts +0 -51
- package/dist/react/jsx/wrapJsx.js +0 -387
- package/dist/react/parse/addVitePlugin/index.d.ts +0 -22
- package/dist/react/parse/addVitePlugin/index.js +0 -41
- package/dist/react/parse/addVitePlugin/installCompiler.d.ts +0 -8
- package/dist/react/parse/addVitePlugin/installCompiler.js +0 -22
- package/dist/react/parse/addVitePlugin/updateViteConfig.d.ts +0 -19
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +0 -120
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.d.ts +0 -9
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +0 -34
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.d.ts +0 -11
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +0 -48
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.d.ts +0 -15
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +0 -113
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.d.ts +0 -12
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +0 -32
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -187
- package/dist/react/parse/createInlineUpdates.d.ts +0 -13
- package/dist/react/parse/createInlineUpdates.js +0 -161
- package/dist/react/utils/flattenDictionary.d.ts +0 -20
- package/dist/react/utils/flattenDictionary.js +0 -75
- package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
- package/dist/react/utils/getEntryAndMetadata.js +0 -11
- package/dist/react/utils/getVariableName.d.ts +0 -25
- package/dist/react/utils/getVariableName.js +0 -37
- package/dist/setup/agentInstructions.d.ts +0 -24
- package/dist/setup/agentInstructions.js +0 -138
- package/dist/setup/detectFramework.d.ts +0 -31
- package/dist/setup/detectFramework.js +0 -106
- package/dist/setup/frameworkUtils.d.ts +0 -3
- package/dist/setup/frameworkUtils.js +0 -30
- package/dist/setup/instructions/base.md +0 -29
- package/dist/setup/instructions/gt-next.md +0 -107
- package/dist/setup/instructions/gt-react.md +0 -98
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -32
- package/dist/setup/wizard.d.ts +0 -3
- package/dist/setup/wizard.js +0 -147
- package/dist/state/recentDownloads.d.ts +0 -12
- package/dist/state/recentDownloads.js +0 -18
- package/dist/state/translateWarnings.d.ts +0 -10
- package/dist/state/translateWarnings.js +0 -13
- package/dist/translation/parse.d.ts +0 -17
- package/dist/translation/parse.js +0 -77
- package/dist/translation/stage.d.ts +0 -3
- package/dist/translation/stage.js +0 -44
- package/dist/translation/validate.d.ts +0 -14
- package/dist/translation/validate.js +0 -100
- package/dist/types/branch.d.ts +0 -14
- package/dist/types/branch.js +0 -1
- package/dist/types/data/json.d.ts +0 -6
- package/dist/types/data/json.js +0 -1
- package/dist/types/data.d.ts +0 -37
- package/dist/types/data.js +0 -1
- package/dist/types/files.d.ts +0 -8
- package/dist/types/files.js +0 -1
- package/dist/types/libraries.d.ts +0 -31
- package/dist/types/libraries.js +0 -72
- package/dist/types/parsing.d.ts +0 -3
- package/dist/types/parsing.js +0 -1
- package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
- package/dist/utils/addExplicitAnchorIds.js +0 -416
- package/dist/utils/constants.d.ts +0 -5
- package/dist/utils/constants.js +0 -6
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -120
- package/dist/utils/flattenJsonFiles.d.ts +0 -2
- package/dist/utils/flattenJsonFiles.js +0 -36
- package/dist/utils/gitDiff.d.ts +0 -8
- package/dist/utils/gitDiff.js +0 -34
- package/dist/utils/gt.d.ts +0 -2
- package/dist/utils/gt.js +0 -2
- package/dist/utils/hash.d.ts +0 -6
- package/dist/utils/hash.js +0 -11
- package/dist/utils/headers.d.ts +0 -1
- package/dist/utils/headers.js +0 -14
- package/dist/utils/localizeRelativeAssets.d.ts +0 -8
- package/dist/utils/localizeRelativeAssets.js +0 -166
- package/dist/utils/localizeStaticImports.d.ts +0 -15
- package/dist/utils/localizeStaticImports.js +0 -397
- package/dist/utils/localizeStaticUrls.d.ts +0 -19
- package/dist/utils/localizeStaticUrls.js +0 -450
- package/dist/utils/mintlifyTitleFallback.d.ts +0 -6
- package/dist/utils/mintlifyTitleFallback.js +0 -80
- package/dist/utils/parse/needsCJS.d.ts +0 -20
- package/dist/utils/parse/needsCJS.js +0 -72
- package/dist/utils/persistPostprocessHashes.d.ts +0 -12
- package/dist/utils/persistPostprocessHashes.js +0 -39
- package/dist/utils/processAnchorIds.d.ts +0 -6
- package/dist/utils/processAnchorIds.js +0 -56
- package/dist/utils/processOpenApi.d.ts +0 -8
- package/dist/utils/processOpenApi.js +0 -651
- package/dist/utils/sanitizeFileContent.d.ts +0 -6
- package/dist/utils/sanitizeFileContent.js +0 -29
- package/dist/utils/sharedStaticAssets.d.ts +0 -9
- package/dist/utils/sharedStaticAssets.js +0 -384
- package/dist/utils/validateMdx.d.ts +0 -10
- package/dist/utils/validateMdx.js +0 -25
- package/dist/utils/wrapPlainUrls.d.ts +0 -8
- package/dist/utils/wrapPlainUrls.js +0 -72
- package/dist/workflows/download.d.ts +0 -32
- package/dist/workflows/download.js +0 -131
- package/dist/workflows/enqueue.d.ts +0 -17
- package/dist/workflows/enqueue.js +0 -59
- package/dist/workflows/setupProject.d.ts +0 -13
- package/dist/workflows/setupProject.js +0 -48
- package/dist/workflows/stage.d.ts +0 -18
- package/dist/workflows/stage.js +0 -59
- package/dist/workflows/steps/BranchStep.d.ts +0 -13
- package/dist/workflows/steps/BranchStep.js +0 -161
- package/dist/workflows/steps/DownloadStep.d.ts +0 -19
- package/dist/workflows/steps/DownloadStep.js +0 -131
- package/dist/workflows/steps/EnqueueStep.d.ts +0 -15
- package/dist/workflows/steps/EnqueueStep.js +0 -33
- package/dist/workflows/steps/PollJobsStep.d.ts +0 -31
- package/dist/workflows/steps/PollJobsStep.js +0 -288
- package/dist/workflows/steps/SetupStep.d.ts +0 -16
- package/dist/workflows/steps/SetupStep.js +0 -72
- package/dist/workflows/steps/UploadSourcesStep.d.ts +0 -27
- package/dist/workflows/steps/UploadSourcesStep.js +0 -131
- package/dist/workflows/steps/UploadTranslationsStep.d.ts +0 -22
- package/dist/workflows/steps/UploadTranslationsStep.js +0 -71
- package/dist/workflows/steps/UserEditDiffsStep.d.ts +0 -11
- package/dist/workflows/steps/UserEditDiffsStep.js +0 -30
- package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
- package/dist/workflows/steps/WorkflowStep.js +0 -2
- package/dist/workflows/upload.d.ts +0 -15
- package/dist/workflows/upload.js +0 -47
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# gt-react
|
|
2
|
-
|
|
3
|
-
This project is using the `gt-react` internationalization library.
|
|
4
|
-
|
|
5
|
-
## gt-react setup
|
|
6
|
-
|
|
7
|
-
- `GTProvider` must wrap the app in the root layout to provide translation context.
|
|
8
|
-
|
|
9
|
-
## Translating JSX
|
|
10
|
-
|
|
11
|
-
`gt-react` uses the `<T>` component for translation.
|
|
12
|
-
|
|
13
|
-
Pass JSX content as the direct children of `<T>` to translate it. Children of `<T>` must be static — no JS expressions or variables directly inside.
|
|
14
|
-
|
|
15
|
-
```jsx
|
|
16
|
-
import { T } from 'gt-react';
|
|
17
|
-
|
|
18
|
-
<T>
|
|
19
|
-
<h1>Welcome to our store</h1>
|
|
20
|
-
<p>
|
|
21
|
-
Browse our <a href='/products'>latest products</a> and find something you
|
|
22
|
-
love.
|
|
23
|
-
</p>
|
|
24
|
-
</T>;
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
You can also add a `context` prop to `<T>` to give context to the translator. For example:
|
|
28
|
-
|
|
29
|
-
```jsx
|
|
30
|
-
import { T } from 'gt-react';
|
|
31
|
-
|
|
32
|
-
<T context="Cookies as in web cookies">
|
|
33
|
-
View your <a href="/cookies">Cookies</a>
|
|
34
|
-
</T>;
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Translating simple strings
|
|
38
|
-
|
|
39
|
-
Use the `gt` function returned by the `useGT()` hook to translate strings directly.
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
import { useGT } from 'gt-react';
|
|
43
|
-
const gt = useGT();
|
|
44
|
-
gt('Hello, world!'); // returns "Hola, mundo"
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
- Just like with the children of the `<T>` component, all strings passed to `gt()` must be static string literals. No variables or template literals.
|
|
48
|
-
|
|
49
|
-
## Translating shared or out-of-scope strings
|
|
50
|
-
|
|
51
|
-
Use `msg()` to register strings for translation, and `useMessages()` to translate them. `const m = useMessages()` should be used equivalently to `const gt = useGT()`.
|
|
52
|
-
|
|
53
|
-
```js
|
|
54
|
-
import { msg, useMessages } from 'gt-react';
|
|
55
|
-
|
|
56
|
-
const greeting = msg('Hello, world!');
|
|
57
|
-
|
|
58
|
-
export default function Greeting() {
|
|
59
|
-
const m = useMessages();
|
|
60
|
-
return <p>{m(greeting)}</p>;
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
- All strings passed to `msg()` must be static string literals. No variables or template literals.
|
|
65
|
-
- `useMessages()` / `getMessages()` take no arguments.
|
|
66
|
-
|
|
67
|
-
## Dynamic content inside `<T>`
|
|
68
|
-
|
|
69
|
-
Use variable components for dynamic values inside `<T>`:
|
|
70
|
-
|
|
71
|
-
- `<Var>{value}</Var>` — variables (strings, numbers, etc.)
|
|
72
|
-
- `<Num>{value}</Num>` — formatted numbers
|
|
73
|
-
- `<Currency>{value}</Currency>` — formatted currency
|
|
74
|
-
- `<DateTime>{value}</DateTime>` — formatted dates/times
|
|
75
|
-
|
|
76
|
-
```jsx
|
|
77
|
-
import { T, Var, Num } from 'gt-react';
|
|
78
|
-
|
|
79
|
-
<T>
|
|
80
|
-
<Var>{userName}</Var> ordered <Num>{itemCount}</Num> items.
|
|
81
|
-
</T>;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Utility hooks
|
|
85
|
-
|
|
86
|
-
### `useLocale()`
|
|
87
|
-
|
|
88
|
-
`useLocale` returns the user's current language, as a BCP 47 locale tag.
|
|
89
|
-
|
|
90
|
-
```js
|
|
91
|
-
import { useLocale } from 'gt-react'
|
|
92
|
-
|
|
93
|
-
const locale = useLocale(); // "en-US"
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Quickstart
|
|
97
|
-
|
|
98
|
-
See <https://generaltranslation.com/docs/react.md>
|
package/dist/setup/userInput.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { libraryDefaultLocale } from 'generaltranslation/internal';
|
|
2
|
-
import { promptText } from '../console/logging.js';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { gt } from '../utils/gt.js';
|
|
5
|
-
export async function getDesiredLocales() {
|
|
6
|
-
// Ask for the default locale
|
|
7
|
-
const defaultLocale = await promptText({
|
|
8
|
-
message: 'What is the default locale for your project?',
|
|
9
|
-
defaultValue: libraryDefaultLocale,
|
|
10
|
-
});
|
|
11
|
-
// Ask for the locales
|
|
12
|
-
const locales = await promptText({
|
|
13
|
-
message: `Which languages would you like to translate your project into? Enter your response as a list of BCP-47 locale tags. ${chalk.dim('(space-separated list)')}`,
|
|
14
|
-
defaultValue: 'es fr de ja zh',
|
|
15
|
-
validate: (input) => {
|
|
16
|
-
const localeList = input.split(' ');
|
|
17
|
-
if (localeList.length === 0) {
|
|
18
|
-
return 'Please enter at least one locale';
|
|
19
|
-
}
|
|
20
|
-
if (localeList.some((locale) => !locale.trim())) {
|
|
21
|
-
return 'Please enter a valid locale (e.g., es fr de)';
|
|
22
|
-
}
|
|
23
|
-
for (const locale of localeList) {
|
|
24
|
-
if (!gt.isValidLocale(locale)) {
|
|
25
|
-
return 'Please enter a valid locale (e.g., es fr de)';
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
return { defaultLocale, locales: locales.split(' ') };
|
|
32
|
-
}
|
package/dist/setup/wizard.d.ts
DELETED
package/dist/setup/wizard.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { detectFormatter } from '../hooks/postProcess.js';
|
|
2
|
-
import { promptSelect } from '../console/logging.js';
|
|
3
|
-
import { logger } from '../console/logger.js';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { promptConfirm } from '../console/logging.js';
|
|
6
|
-
import findFilepath from '../fs/findFilepath.js';
|
|
7
|
-
import { formatFiles } from '../hooks/postProcess.js';
|
|
8
|
-
import { handleInitGT } from '../next/parse/handleInitGT.js';
|
|
9
|
-
import { getPackageJson, isPackageInstalled } from '../utils/packageJson.js';
|
|
10
|
-
import { wrapContentNext } from '../next/parse/wrapContent.js';
|
|
11
|
-
import { getPackageManager } from '../utils/packageManager.js';
|
|
12
|
-
import { installPackage } from '../utils/installPackage.js';
|
|
13
|
-
import { createOrUpdateConfig } from '../fs/config/setupConfig.js';
|
|
14
|
-
import { loadConfig } from '../fs/config/loadConfig.js';
|
|
15
|
-
import { addVitePlugin } from '../react/parse/addVitePlugin/index.js';
|
|
16
|
-
import { exitSync } from '../console/logging.js';
|
|
17
|
-
import { getFrameworkDisplayName } from './frameworkUtils.js';
|
|
18
|
-
import { Libraries } from '../types/libraries.js';
|
|
19
|
-
export async function handleSetupReactCommand(options, frameworkObject, useDefaults = false) {
|
|
20
|
-
const frameworkDisplayName = getFrameworkDisplayName(frameworkObject);
|
|
21
|
-
// Ask user for confirmation using inquirer
|
|
22
|
-
if (!useDefaults) {
|
|
23
|
-
const answer = await promptConfirm({
|
|
24
|
-
message: chalk.yellow(`This wizard will configure your ${frameworkDisplayName} project for internationalization with GT. If your project is already using a different i18n library, this wizard may cause issues.
|
|
25
|
-
|
|
26
|
-
Make sure you have committed or stashed any changes. Do you want to continue?`),
|
|
27
|
-
defaultValue: true,
|
|
28
|
-
cancelMessage: 'Operation cancelled. You can re-run this wizard with: npx gtx-cli setup',
|
|
29
|
-
});
|
|
30
|
-
if (!answer) {
|
|
31
|
-
logger.info('Operation cancelled. You can re-run this wizard with: npx gtx-cli setup');
|
|
32
|
-
exitSync(0);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const frameworkType = useDefaults && frameworkObject?.name
|
|
36
|
-
? frameworkObject.name
|
|
37
|
-
: await promptSelect({
|
|
38
|
-
message: 'Which framework are you using?',
|
|
39
|
-
options: [
|
|
40
|
-
{ value: 'next-app', label: chalk.blue('Next.js App Router') },
|
|
41
|
-
{ value: 'next-pages', label: chalk.green('Next.js Pages Router') },
|
|
42
|
-
{ value: 'vite', label: chalk.cyan('Vite + React') },
|
|
43
|
-
{ value: 'gatsby', label: chalk.magenta('Gatsby') },
|
|
44
|
-
{ value: 'react', label: chalk.yellow('React') },
|
|
45
|
-
{ value: 'redwood', label: chalk.red('RedwoodJS') },
|
|
46
|
-
{ value: 'other', label: chalk.dim('Other') },
|
|
47
|
-
],
|
|
48
|
-
defaultValue: frameworkObject?.name || 'other',
|
|
49
|
-
});
|
|
50
|
-
if (frameworkType === 'other') {
|
|
51
|
-
logger.error(`Sorry, the wizard doesn't currently support other React frameworks.
|
|
52
|
-
Please let us know what you would like to see added at https://github.com/generaltranslation/gt/issues`);
|
|
53
|
-
exitSync(0);
|
|
54
|
-
}
|
|
55
|
-
// ----- Create a starter gt.config.json file -----
|
|
56
|
-
await createOrUpdateConfig(options.config || 'gt.config.json', {
|
|
57
|
-
framework: frameworkType,
|
|
58
|
-
});
|
|
59
|
-
const packageJson = await getPackageJson();
|
|
60
|
-
if (!packageJson) {
|
|
61
|
-
logger.error(chalk.red('No package.json found in the current directory. Please run this command from the root of your project.'));
|
|
62
|
-
exitSync(1);
|
|
63
|
-
}
|
|
64
|
-
// Check if gt-next or gt-react is installed
|
|
65
|
-
if (frameworkType === 'next-app' &&
|
|
66
|
-
!isPackageInstalled(Libraries.GT_NEXT, packageJson)) {
|
|
67
|
-
const packageManager = await getPackageManager();
|
|
68
|
-
const spinner = logger.createSpinner('timer');
|
|
69
|
-
spinner.start(`Installing ${Libraries.GT_NEXT} with ${packageManager.name}...`);
|
|
70
|
-
await installPackage(Libraries.GT_NEXT, packageManager);
|
|
71
|
-
spinner.stop(chalk.green(`Automatically installed ${Libraries.GT_NEXT}.`));
|
|
72
|
-
}
|
|
73
|
-
else if (['next-pages', 'react', 'redwood', 'vite', 'gatsby'].includes(frameworkType) &&
|
|
74
|
-
!isPackageInstalled(Libraries.GT_REACT, packageJson)) {
|
|
75
|
-
const packageManager = await getPackageManager();
|
|
76
|
-
const spinner = logger.createSpinner('timer');
|
|
77
|
-
spinner.start(`Installing ${Libraries.GT_REACT} with ${packageManager.name}...`);
|
|
78
|
-
await installPackage(Libraries.GT_REACT, packageManager);
|
|
79
|
-
spinner.stop(chalk.green(`Automatically installed ${Libraries.GT_REACT}.`));
|
|
80
|
-
}
|
|
81
|
-
const errors = [];
|
|
82
|
-
const warnings = [];
|
|
83
|
-
let filesUpdated = [];
|
|
84
|
-
// Read tsconfig.json if it exists
|
|
85
|
-
const tsconfigPath = findFilepath(['tsconfig.json']);
|
|
86
|
-
const tsconfigJson = tsconfigPath ? loadConfig(tsconfigPath) : undefined;
|
|
87
|
-
if (frameworkType === 'next-app') {
|
|
88
|
-
// Check if they have a next.config.js file
|
|
89
|
-
const nextConfigPath = findFilepath([
|
|
90
|
-
'./next.config.js',
|
|
91
|
-
'./next.config.ts',
|
|
92
|
-
'./next.config.mjs',
|
|
93
|
-
'./next.config.mts',
|
|
94
|
-
]);
|
|
95
|
-
if (!nextConfigPath) {
|
|
96
|
-
logger.error('No next.config.[js|ts|mjs|mts] file found.');
|
|
97
|
-
exitSync(1);
|
|
98
|
-
}
|
|
99
|
-
const mergeOptions = {
|
|
100
|
-
...options,
|
|
101
|
-
disableIds: true,
|
|
102
|
-
disableFormatting: true,
|
|
103
|
-
skipTs: true,
|
|
104
|
-
addGTProvider: true,
|
|
105
|
-
};
|
|
106
|
-
const spinner = logger.createSpinner();
|
|
107
|
-
spinner.start('Wrapping JSX content with <T> tags...');
|
|
108
|
-
// Wrap all JSX elements in the src directory with a <T> tag, with unique ids
|
|
109
|
-
const { filesUpdated: filesUpdatedNext } = await wrapContentNext(mergeOptions, Libraries.GT_NEXT, errors, warnings);
|
|
110
|
-
filesUpdated = [...filesUpdated, ...filesUpdatedNext];
|
|
111
|
-
spinner.stop(chalk.green(`Success! Updated ${chalk.bold.cyan(filesUpdated.length)} files:\n`) + filesUpdated.map((file) => `${chalk.green('-')} ${file}`).join('\n'));
|
|
112
|
-
// Add the withGTConfig() function to the next.config.js file
|
|
113
|
-
await handleInitGT(nextConfigPath, errors, warnings, filesUpdated, packageJson, tsconfigJson);
|
|
114
|
-
logger.step(chalk.green(`Added withGTConfig() to your ${nextConfigPath} file.`));
|
|
115
|
-
}
|
|
116
|
-
// Add gt compiler plugin
|
|
117
|
-
if (frameworkType === 'vite') {
|
|
118
|
-
await addVitePlugin({
|
|
119
|
-
errors,
|
|
120
|
-
warnings,
|
|
121
|
-
filesUpdated,
|
|
122
|
-
packageJson,
|
|
123
|
-
tsconfigJson,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
if (errors.length > 0) {
|
|
127
|
-
logger.error(chalk.red('Failed to write files:\n') + errors.join('\n'));
|
|
128
|
-
}
|
|
129
|
-
if (warnings.length > 0) {
|
|
130
|
-
logger.warn(chalk.yellow('Warnings encountered:') +
|
|
131
|
-
'\n' +
|
|
132
|
-
warnings.map((warning) => `${chalk.yellow('-')} ${warning}`).join('\n'));
|
|
133
|
-
}
|
|
134
|
-
const formatter = await detectFormatter();
|
|
135
|
-
if (!formatter || filesUpdated.length === 0) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const applyFormatting = useDefaults
|
|
139
|
-
? true
|
|
140
|
-
: await promptConfirm({
|
|
141
|
-
message: `Would you like the wizard to auto-format the modified files? ${chalk.dim(`(${formatter})`)}`,
|
|
142
|
-
defaultValue: true,
|
|
143
|
-
});
|
|
144
|
-
// Format updated files if formatters are available
|
|
145
|
-
if (applyFormatting)
|
|
146
|
-
await formatFiles(filesUpdated, formatter);
|
|
147
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type DownloadMeta = {
|
|
2
|
-
branchId: string;
|
|
3
|
-
fileId: string;
|
|
4
|
-
versionId: string;
|
|
5
|
-
locale: string;
|
|
6
|
-
inputPath?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function recordDownloaded(filePath: string, meta?: DownloadMeta): void;
|
|
9
|
-
export declare function getDownloaded(): Set<string>;
|
|
10
|
-
export declare function getDownloadedMeta(): Map<string, DownloadMeta>;
|
|
11
|
-
export declare function clearDownloaded(): void;
|
|
12
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const recent = new Set();
|
|
2
|
-
const recentMeta = new Map();
|
|
3
|
-
export function recordDownloaded(filePath, meta) {
|
|
4
|
-
recent.add(filePath);
|
|
5
|
-
if (meta) {
|
|
6
|
-
recentMeta.set(filePath, meta);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export function getDownloaded() {
|
|
10
|
-
return recent;
|
|
11
|
-
}
|
|
12
|
-
export function getDownloadedMeta() {
|
|
13
|
-
return recentMeta;
|
|
14
|
-
}
|
|
15
|
-
export function clearDownloaded() {
|
|
16
|
-
recent.clear();
|
|
17
|
-
recentMeta.clear();
|
|
18
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type WarningCategory = 'skipped_file' | 'failed_move' | 'failed_translation' | 'failed_download';
|
|
2
|
-
export type TranslateWarning = {
|
|
3
|
-
category: WarningCategory;
|
|
4
|
-
fileName: string;
|
|
5
|
-
reason: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function recordWarning(category: WarningCategory, fileName: string, reason: string): void;
|
|
8
|
-
export declare function getWarnings(): TranslateWarning[];
|
|
9
|
-
export declare function hasWarnings(): boolean;
|
|
10
|
-
export declare function clearWarnings(): void;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const warnings = [];
|
|
2
|
-
export function recordWarning(category, fileName, reason) {
|
|
3
|
-
warnings.push({ category, fileName, reason });
|
|
4
|
-
}
|
|
5
|
-
export function getWarnings() {
|
|
6
|
-
return warnings;
|
|
7
|
-
}
|
|
8
|
-
export function hasWarnings() {
|
|
9
|
-
return warnings.length > 0;
|
|
10
|
-
}
|
|
11
|
-
export function clearWarnings() {
|
|
12
|
-
warnings.length = 0;
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Updates, TranslateFlags } from '../types/index.js';
|
|
2
|
-
import type { ParsingConfigOptions } from '../types/parsing.js';
|
|
3
|
-
import { InlineLibrary } from '../types/libraries.js';
|
|
4
|
-
/**
|
|
5
|
-
* Searches for gt-react or gt-next dictionary files and creates updates for them,
|
|
6
|
-
* as well as inline updates for <T> tags and useGT()/getGT() calls
|
|
7
|
-
*
|
|
8
|
-
* @param options - The options object
|
|
9
|
-
* @param sourceDictionary - The source dictionary file path
|
|
10
|
-
* @param pkg - The package name
|
|
11
|
-
* @returns An object containing the updates and errors
|
|
12
|
-
*/
|
|
13
|
-
export declare function createUpdates(options: TranslateFlags, src: string[] | undefined, sourceDictionary: string | undefined, pkg: InlineLibrary, validate: boolean, parsingOptions: ParsingConfigOptions): Promise<{
|
|
14
|
-
updates: Updates;
|
|
15
|
-
errors: string[];
|
|
16
|
-
warnings: string[];
|
|
17
|
-
}>;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { logger } from '../console/logger.js';
|
|
3
|
-
import loadJSON from '../fs/loadJSON.js';
|
|
4
|
-
import { createDictionaryUpdates } from '../react/parse/createDictionaryUpdates.js';
|
|
5
|
-
import { createInlineUpdates } from '../react/parse/createInlineUpdates.js';
|
|
6
|
-
import createESBuildConfig from '../react/config/createESBuildConfig.js';
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import { exitSync } from '../console/logging.js';
|
|
9
|
-
/**
|
|
10
|
-
* Searches for gt-react or gt-next dictionary files and creates updates for them,
|
|
11
|
-
* as well as inline updates for <T> tags and useGT()/getGT() calls
|
|
12
|
-
*
|
|
13
|
-
* @param options - The options object
|
|
14
|
-
* @param sourceDictionary - The source dictionary file path
|
|
15
|
-
* @param pkg - The package name
|
|
16
|
-
* @returns An object containing the updates and errors
|
|
17
|
-
*/
|
|
18
|
-
export async function createUpdates(options, src, sourceDictionary, pkg, validate, parsingOptions) {
|
|
19
|
-
let updates = [];
|
|
20
|
-
let errors = [];
|
|
21
|
-
let warnings = [];
|
|
22
|
-
// Parse dictionary with esbuildConfig
|
|
23
|
-
if (sourceDictionary &&
|
|
24
|
-
fs.existsSync(sourceDictionary) &&
|
|
25
|
-
fs.statSync(sourceDictionary).isFile()) {
|
|
26
|
-
if (sourceDictionary.endsWith('.json')) {
|
|
27
|
-
updates = [
|
|
28
|
-
...updates,
|
|
29
|
-
...(await createDictionaryUpdates(sourceDictionary, errors, warnings)),
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
let esbuildConfig;
|
|
34
|
-
if (options.jsconfig) {
|
|
35
|
-
const jsconfig = loadJSON(options.jsconfig);
|
|
36
|
-
if (!jsconfig) {
|
|
37
|
-
logger.error(`Failed to resolve jsconfig.json or tsconfig.json at provided filepath: "${options.jsconfig}"`);
|
|
38
|
-
exitSync(1);
|
|
39
|
-
}
|
|
40
|
-
esbuildConfig = createESBuildConfig(jsconfig);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
esbuildConfig = createESBuildConfig({});
|
|
44
|
-
}
|
|
45
|
-
updates = [
|
|
46
|
-
...updates,
|
|
47
|
-
...(await createDictionaryUpdates(sourceDictionary, errors, warnings, esbuildConfig)),
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Scan through project for <T> tags
|
|
52
|
-
const { updates: newUpdates, errors: newErrors, warnings: newWarnings, } = await createInlineUpdates(pkg, validate, src, parsingOptions);
|
|
53
|
-
errors = [...errors, ...newErrors];
|
|
54
|
-
warnings = [...warnings, ...newWarnings];
|
|
55
|
-
updates = [...updates, ...newUpdates];
|
|
56
|
-
// Metadata addition and validation
|
|
57
|
-
const idHashMap = new Map();
|
|
58
|
-
const duplicateIds = new Set();
|
|
59
|
-
updates = updates.map((update) => {
|
|
60
|
-
if (!update.metadata.id)
|
|
61
|
-
return update;
|
|
62
|
-
const existingHash = idHashMap.get(update.metadata.id);
|
|
63
|
-
if (existingHash) {
|
|
64
|
-
if (existingHash !== update.metadata.hash) {
|
|
65
|
-
errors.push(`Hashes don't match on two components with the same id: ${chalk.blue(update.metadata.id)}. Check your ${chalk.green('<T>')} tags and dictionary entries and make sure you're not accidentally duplicating IDs.`);
|
|
66
|
-
duplicateIds.add(update.metadata.id);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
idHashMap.set(update.metadata.id, update.metadata.hash);
|
|
71
|
-
}
|
|
72
|
-
return update;
|
|
73
|
-
});
|
|
74
|
-
// Filter out updates with duplicate IDs
|
|
75
|
-
updates = updates.filter((update) => !duplicateIds.has(update.metadata.id));
|
|
76
|
-
return { updates, errors, warnings };
|
|
77
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { logErrorAndExit } from '../console/logging.js';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import findFilepath from '../fs/findFilepath.js';
|
|
4
|
-
import { logger } from '../console/logger.js';
|
|
5
|
-
import { createUpdates } from './parse.js';
|
|
6
|
-
export async function aggregateInlineTranslations(options, settings, library) {
|
|
7
|
-
if (!options.dictionary) {
|
|
8
|
-
options.dictionary = findFilepath([
|
|
9
|
-
'./dictionary.js',
|
|
10
|
-
'./src/dictionary.js',
|
|
11
|
-
'./dictionary.json',
|
|
12
|
-
'./src/dictionary.json',
|
|
13
|
-
'./dictionary.ts',
|
|
14
|
-
'./src/dictionary.ts',
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
// ---- CREATING UPDATES ---- //
|
|
18
|
-
const { updates, errors, warnings } = await createUpdates(options, settings.src, options.dictionary, library, false, settings.parsingOptions);
|
|
19
|
-
if (warnings.length > 0) {
|
|
20
|
-
logger.warn(chalk.yellow(`CLI tool encountered ${warnings.length} warnings while scanning for translatable content.\n` +
|
|
21
|
-
warnings
|
|
22
|
-
.map((warning) => chalk.yellow('• Warning: ') + chalk.white(warning))
|
|
23
|
-
.join('\n')));
|
|
24
|
-
}
|
|
25
|
-
if (errors.length > 0) {
|
|
26
|
-
if (options.ignoreErrors) {
|
|
27
|
-
logger.warn(chalk.yellow(`Warning: CLI tool encountered ${errors.length} syntax errors while scanning for translatable content. These components will not be translated.\n` +
|
|
28
|
-
errors
|
|
29
|
-
.map((error) => chalk.yellow('• ') + chalk.white(error) + '\n')
|
|
30
|
-
.join('')));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
logErrorAndExit(chalk.red(`Error: CLI tool encountered ${errors.length} syntax errors while scanning for translatable content. ${chalk.gray('To ignore these errors, re-run with --ignore-errors')}\n` +
|
|
34
|
-
errors
|
|
35
|
-
.map((error) => chalk.red('• ') + chalk.white(error) + '\n')
|
|
36
|
-
.join('')));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (updates.length == 0) {
|
|
40
|
-
logger.error(chalk.red(`No in-line content or dictionaries were found for ${chalk.green(library)}. Are you sure you're running this command in the right directory?`));
|
|
41
|
-
return updates;
|
|
42
|
-
}
|
|
43
|
-
return updates;
|
|
44
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Options, Settings } from '../types/index.js';
|
|
2
|
-
import { InlineLibrary, Libraries } from '../types/libraries.js';
|
|
3
|
-
export type ValidationLevel = 'error' | 'warning';
|
|
4
|
-
export type ValidationMessage = {
|
|
5
|
-
level: ValidationLevel;
|
|
6
|
-
message: string;
|
|
7
|
-
};
|
|
8
|
-
export type ValidationResult = Record<string, ValidationMessage[]>;
|
|
9
|
-
/**
|
|
10
|
-
* Programmatic API for validation - returns structured results instead of logging/exiting.
|
|
11
|
-
* Equivalent to running `gtx-cli validate` but returns data.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getValidateJson(settings: Options & Settings, pkg: `${typeof Libraries.GT_REACT}` | `${typeof Libraries.GT_NEXT}` | `${typeof Libraries.GT_REACT_NATIVE}`, files?: string[]): Promise<ValidationResult>;
|
|
14
|
-
export declare function validateProject(settings: Options & Settings, pkg: InlineLibrary, files?: string[]): Promise<void>;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { logErrorAndExit, stripAnsi } from '../console/logging.js';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import findFilepath from '../fs/findFilepath.js';
|
|
4
|
-
import { logger } from '../console/logger.js';
|
|
5
|
-
import { createUpdates } from './parse.js';
|
|
6
|
-
import { createInlineUpdates } from '../react/parse/createInlineUpdates.js';
|
|
7
|
-
import { Libraries } from '../types/libraries.js';
|
|
8
|
-
/**
|
|
9
|
-
* Shared validation logic - returns raw results from createUpdates/createInlineUpdates
|
|
10
|
-
*/
|
|
11
|
-
async function runValidation(settings, pkg, files) {
|
|
12
|
-
if (files && files.length > 0) {
|
|
13
|
-
return createInlineUpdates(pkg, true, files, settings.parsingOptions);
|
|
14
|
-
}
|
|
15
|
-
// Full project validation
|
|
16
|
-
// Use local variable to avoid mutating caller's settings object
|
|
17
|
-
const dictionary = settings.dictionary ||
|
|
18
|
-
findFilepath([
|
|
19
|
-
'./dictionary.js',
|
|
20
|
-
'./src/dictionary.js',
|
|
21
|
-
'./dictionary.json',
|
|
22
|
-
'./src/dictionary.json',
|
|
23
|
-
'./dictionary.ts',
|
|
24
|
-
'./src/dictionary.ts',
|
|
25
|
-
]);
|
|
26
|
-
return createUpdates(settings, settings.src, dictionary, pkg, true, settings.parsingOptions);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Parse file path from error/warning string in withLocation format: "filepath (line:col): message"
|
|
30
|
-
*/
|
|
31
|
-
function parseFileFromMessage(msg) {
|
|
32
|
-
// First try to match with location format: "filepath (line:col): message"
|
|
33
|
-
// Using [\s\S] instead of . with /s flag for ES5 compatibility
|
|
34
|
-
const withLocation = msg.match(/^(.+)\s+\(\d+:\d+\)\s*:\s*([\s\S]+)$/);
|
|
35
|
-
if (withLocation) {
|
|
36
|
-
return { file: withLocation[1].trim(), message: withLocation[2].trim() };
|
|
37
|
-
}
|
|
38
|
-
// Fallback: find the last ": " pattern (handles Windows paths like C:\...)
|
|
39
|
-
const lastColonSpace = msg.lastIndexOf(': ');
|
|
40
|
-
if (lastColonSpace > 0) {
|
|
41
|
-
return {
|
|
42
|
-
file: msg.substring(0, lastColonSpace).trim(),
|
|
43
|
-
message: msg.substring(lastColonSpace + 2).trim(),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// No file found - use empty string as key for "global" messages
|
|
47
|
-
return { file: '', message: msg };
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Programmatic API for validation - returns structured results instead of logging/exiting.
|
|
51
|
-
* Equivalent to running `gtx-cli validate` but returns data.
|
|
52
|
-
*/
|
|
53
|
-
export async function getValidateJson(settings,
|
|
54
|
-
// TODO: fix compatability more generally so do not have to do this
|
|
55
|
-
pkg, files) {
|
|
56
|
-
const validatedPkg = pkg === Libraries.GT_NEXT
|
|
57
|
-
? Libraries.GT_NEXT
|
|
58
|
-
: pkg === Libraries.GT_REACT_NATIVE
|
|
59
|
-
? Libraries.GT_REACT_NATIVE
|
|
60
|
-
: Libraries.GT_REACT;
|
|
61
|
-
const { errors, warnings } = await runValidation(settings, validatedPkg, files);
|
|
62
|
-
const result = {};
|
|
63
|
-
const addMessage = (file, level, message) => {
|
|
64
|
-
if (!result[file]) {
|
|
65
|
-
result[file] = [];
|
|
66
|
-
}
|
|
67
|
-
result[file].push({ level, message });
|
|
68
|
-
};
|
|
69
|
-
for (const error of errors) {
|
|
70
|
-
const { file, message } = parseFileFromMessage(stripAnsi(error));
|
|
71
|
-
addMessage(file, 'error', message);
|
|
72
|
-
}
|
|
73
|
-
for (const warning of warnings) {
|
|
74
|
-
const { file, message } = parseFileFromMessage(stripAnsi(warning));
|
|
75
|
-
addMessage(file, 'warning', message);
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
export async function validateProject(settings, pkg, files) {
|
|
80
|
-
const { updates, errors, warnings } = await runValidation(settings, pkg, files);
|
|
81
|
-
if (warnings.length > 0) {
|
|
82
|
-
logger.warn(chalk.yellow(`CLI tool encountered ${warnings.length} warnings while scanning for translatable content.`) +
|
|
83
|
-
'\n' +
|
|
84
|
-
warnings
|
|
85
|
-
.map((warning) => chalk.yellow('• ') + chalk.white(warning))
|
|
86
|
-
.join('\n'));
|
|
87
|
-
}
|
|
88
|
-
if (errors.length > 0) {
|
|
89
|
-
logErrorAndExit(chalk.red(`Error: CLI tool encountered ${errors.length} syntax errors while scanning for translatable content.\n` +
|
|
90
|
-
errors
|
|
91
|
-
.map((error) => chalk.red('• ') + chalk.white(error) + '\n')
|
|
92
|
-
.join('')));
|
|
93
|
-
}
|
|
94
|
-
if (updates.length === 0) {
|
|
95
|
-
logger.error(chalk.red(`No in-line content or dictionaries were found for ${chalk.green(pkg)}. Are you sure you're running this command in the right directory?`));
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
logger.success(chalk.green(`Success! Found ${updates.length} translatable entries for ${chalk.green(pkg)}.`));
|
|
99
|
-
}
|
|
100
|
-
}
|
package/dist/types/branch.d.ts
DELETED
package/dist/types/branch.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/data/json.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|