@translated/lara-cli 0.2.1

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.
Files changed (68) hide show
  1. package/README.md +212 -0
  2. package/build/cli/cmd/glossary/glossary.js +55 -0
  3. package/build/cli/cmd/glossary/glossary.js.map +1 -0
  4. package/build/cli/cmd/init/init.input.js +177 -0
  5. package/build/cli/cmd/init/init.input.js.map +1 -0
  6. package/build/cli/cmd/init/init.js +158 -0
  7. package/build/cli/cmd/init/init.js.map +1 -0
  8. package/build/cli/cmd/init/init.types.js +2 -0
  9. package/build/cli/cmd/init/init.types.js.map +1 -0
  10. package/build/cli/cmd/init/init.utils.js +99 -0
  11. package/build/cli/cmd/init/init.utils.js.map +1 -0
  12. package/build/cli/cmd/memory/memory.js +55 -0
  13. package/build/cli/cmd/memory/memory.js.map +1 -0
  14. package/build/cli/cmd/translate/translate.js +149 -0
  15. package/build/cli/cmd/translate/translate.js.map +1 -0
  16. package/build/index.js +25 -0
  17. package/build/index.js.map +1 -0
  18. package/build/interface/parser.js +2 -0
  19. package/build/interface/parser.js.map +1 -0
  20. package/build/messages/messages.js +120 -0
  21. package/build/messages/messages.js.map +1 -0
  22. package/build/modules/common/common.const.js +424 -0
  23. package/build/modules/common/common.const.js.map +1 -0
  24. package/build/modules/common/common.types.js +15 -0
  25. package/build/modules/common/common.types.js.map +1 -0
  26. package/build/modules/config/config.provider.js +47 -0
  27. package/build/modules/config/config.provider.js.map +1 -0
  28. package/build/modules/config/config.types.js +95 -0
  29. package/build/modules/config/config.types.js.map +1 -0
  30. package/build/modules/translation/translation.engine.js +165 -0
  31. package/build/modules/translation/translation.engine.js.map +1 -0
  32. package/build/modules/translation/translation.service.js +45 -0
  33. package/build/modules/translation/translation.service.js.map +1 -0
  34. package/build/parsers/android-xml.parser.js +308 -0
  35. package/build/parsers/android-xml.parser.js.map +1 -0
  36. package/build/parsers/json.parser.js +18 -0
  37. package/build/parsers/json.parser.js.map +1 -0
  38. package/build/parsers/markdown.parser.js +74 -0
  39. package/build/parsers/markdown.parser.js.map +1 -0
  40. package/build/parsers/parser.factory.js +52 -0
  41. package/build/parsers/parser.factory.js.map +1 -0
  42. package/build/parsers/parser.types.js +2 -0
  43. package/build/parsers/parser.types.js.map +1 -0
  44. package/build/parsers/po.parser.js +175 -0
  45. package/build/parsers/po.parser.js.map +1 -0
  46. package/build/parsers/ts.parser.js +176 -0
  47. package/build/parsers/ts.parser.js.map +1 -0
  48. package/build/parsers/vue.parser.js +156 -0
  49. package/build/parsers/vue.parser.js.map +1 -0
  50. package/build/utils/checksum.js +80 -0
  51. package/build/utils/checksum.js.map +1 -0
  52. package/build/utils/cli.js +4 -0
  53. package/build/utils/cli.js.map +1 -0
  54. package/build/utils/display.js +60 -0
  55. package/build/utils/display.js.map +1 -0
  56. package/build/utils/error.js +18 -0
  57. package/build/utils/error.js.map +1 -0
  58. package/build/utils/locale.js +108 -0
  59. package/build/utils/locale.js.map +1 -0
  60. package/build/utils/parser.js +25 -0
  61. package/build/utils/parser.js.map +1 -0
  62. package/build/utils/path.js +173 -0
  63. package/build/utils/path.js.map +1 -0
  64. package/build/utils/progressWithOra.js +72 -0
  65. package/build/utils/progressWithOra.js.map +1 -0
  66. package/build/utils/prompt.js +205 -0
  67. package/build/utils/prompt.js.map +1 -0
  68. package/package.json +89 -0
@@ -0,0 +1,99 @@
1
+ import { input } from '@inquirer/prompts';
2
+ import Ora from 'ora';
3
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
4
+ import { ConfigProvider } from '#modules/config/config.provider.js';
5
+ import { Messages } from '#messages/messages.js';
6
+ export function resolveProjectInstruction(cliInstruction) {
7
+ if (cliInstruction) {
8
+ return cliInstruction;
9
+ }
10
+ const configProvider = ConfigProvider.getInstance();
11
+ if (configProvider.doesConfigExists()) {
12
+ const config = configProvider.getConfig();
13
+ return config.project?.instruction;
14
+ }
15
+ return undefined;
16
+ }
17
+ function validateCredential(credential, name) {
18
+ const sanitized = credential.trim().replace(/[\r\n]+/g, '');
19
+ if (sanitized.length < 8 || sanitized.length > 128) {
20
+ throw new Error(Messages.errors.credentialValidation(name));
21
+ }
22
+ return sanitized;
23
+ }
24
+ export async function setCredentials() {
25
+ const apiKeyRaw = await input({ message: Messages.prompts.apiKey });
26
+ const apiSecretRaw = await input({ message: Messages.prompts.apiSecret });
27
+ let apiKey, apiSecret;
28
+ try {
29
+ apiKey = validateCredential(apiKeyRaw, 'API Key');
30
+ apiSecret = validateCredential(apiSecretRaw, 'API Secret');
31
+ }
32
+ catch (err) {
33
+ if (err instanceof Error) {
34
+ Ora({ text: err.message, color: 'red' }).fail();
35
+ }
36
+ else {
37
+ Ora({ text: Messages.errors.unknownError, color: 'red' }).fail();
38
+ }
39
+ throw err;
40
+ }
41
+ const envPath = '.env';
42
+ if (!existsSync(envPath)) {
43
+ Ora({ text: Messages.info.noEnvFile, color: 'yellow' }).warn();
44
+ writeFileSync(envPath, '');
45
+ }
46
+ let envContent = '';
47
+ try {
48
+ envContent = readFileSync(envPath, 'utf-8');
49
+ }
50
+ catch (err) {
51
+ const errorMessage = err instanceof Error ? err.message : Messages.errors.unknownErrorFallback;
52
+ Ora({
53
+ text: Messages.errors.envReadFailed(errorMessage),
54
+ color: 'red',
55
+ }).fail();
56
+ throw err;
57
+ }
58
+ if (/^LARA_ACCESS_KEY_ID=/m.test(envContent)) {
59
+ envContent = envContent.replace(/^LARA_ACCESS_KEY_ID=.*$/m, `LARA_ACCESS_KEY_ID=${apiKey}`);
60
+ }
61
+ else {
62
+ envContent += `\n# Lara API credentials\nLARA_ACCESS_KEY_ID=${apiKey}`;
63
+ }
64
+ if (/^LARA_ACCESS_KEY_SECRET=/m.test(envContent)) {
65
+ envContent = envContent.replace(/^LARA_ACCESS_KEY_SECRET=.*$/m, `LARA_ACCESS_KEY_SECRET=${apiSecret}`);
66
+ }
67
+ else {
68
+ envContent += `\nLARA_ACCESS_KEY_SECRET=${apiSecret}`;
69
+ }
70
+ writeFileSync(envPath, envContent);
71
+ Ora({ text: Messages.success.apiCredentialsSet, color: 'green' }).succeed();
72
+ }
73
+ export function getExistingMemories(force) {
74
+ const configProvider = ConfigProvider.getInstance();
75
+ if (!configProvider.doesConfigExists() || force) {
76
+ return [];
77
+ }
78
+ try {
79
+ const config = configProvider.getConfig();
80
+ return config.memories || [];
81
+ }
82
+ catch {
83
+ return [];
84
+ }
85
+ }
86
+ export function getExistingGlossaries(force) {
87
+ const configProvider = ConfigProvider.getInstance();
88
+ if (!configProvider.doesConfigExists() || force) {
89
+ return [];
90
+ }
91
+ try {
92
+ const config = configProvider.getConfig();
93
+ return config.glossaries || [];
94
+ }
95
+ catch {
96
+ return [];
97
+ }
98
+ }
99
+ //# sourceMappingURL=init.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.utils.js","sourceRoot":"/","sources":["cli/cmd/init/init.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AASjD,MAAM,UAAU,yBAAyB,CAAC,cAAuB;IAE/D,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IAGD,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IACpD,IAAI,cAAc,CAAC,gBAAgB,EAAE,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC;IACrC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAYD,SAAS,kBAAkB,CAAC,UAAkB,EAAE,IAAY;IA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AAQ,CAAC,OAAO,CAAC,iBAAiB,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAC9E,CAAC;AASD,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAEpD,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE,IAAI,KAAK,EAAE,CAAC;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AASD,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAEpD,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE,IAAI,KAAK,EAAE,CAAC;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { Command } from 'commander';
2
+ import Ora from 'ora';
3
+ import { TranslationService } from '#modules/translation/translation.service.js';
4
+ import { LARA_WEB_URL } from '#modules/common/common.const.js';
5
+ import { handleLaraApiError } from '#utils/error.js';
6
+ import { LaraApiError } from '@translated/lara';
7
+ import { Messages } from '#messages/messages.js';
8
+ export default new Command()
9
+ .command('memory')
10
+ .description('Manage translation memories')
11
+ .helpOption('-h, --help', 'Show help')
12
+ .action(async () => {
13
+ if (!process.env.LARA_ACCESS_KEY_ID || !process.env.LARA_ACCESS_KEY_SECRET) {
14
+ Ora({
15
+ text: Messages.errors.noApiCredentials,
16
+ color: 'red',
17
+ }).fail();
18
+ process.exit(1);
19
+ }
20
+ await handleMemory();
21
+ });
22
+ async function handleMemory() {
23
+ try {
24
+ await listMemories();
25
+ }
26
+ catch (error) {
27
+ const message = error instanceof Error ? error.message : String(error);
28
+ Ora({ text: message, color: 'red' }).fail();
29
+ process.exit(1);
30
+ }
31
+ }
32
+ async function listMemories() {
33
+ const spinner = Ora().start(Messages.info.fetchingMemories);
34
+ try {
35
+ const translationService = TranslationService.getInstance();
36
+ const clientTranslationMemories = await translationService.getTranslationMemories();
37
+ if (clientTranslationMemories.length === 0) {
38
+ spinner.warn(Messages.warnings.noMemoriesLinked(LARA_WEB_URL));
39
+ return;
40
+ }
41
+ spinner.succeed(Messages.success.foundMemories(clientTranslationMemories.length));
42
+ for (const memory of clientTranslationMemories) {
43
+ console.log(Messages.ui.itemId(memory.id));
44
+ console.log(Messages.ui.itemName(memory.name) + '\n');
45
+ }
46
+ }
47
+ catch (error) {
48
+ if (error instanceof LaraApiError) {
49
+ handleLaraApiError(error, Messages.errors.gettingMemories, spinner);
50
+ return;
51
+ }
52
+ throw error;
53
+ }
54
+ }
55
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"/","sources":["cli/cmd/memory/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;A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AM,KAAK,CAAC,EAAE,CAAC;YAC3C,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC;YAC/D,OAAO;QACT,CAAC;QAED,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;QAElF,KAAK,MAAM,MAAM,IAAI,yBAAyB,EAAE,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAClC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACpE,OAAO;QACT,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,149 @@
1
+ import { Command, Option } from 'commander';
2
+ import Ora from 'ora';
3
+ import { COMMA_AND_SPACE_REGEX } from '#modules/common/common.const.js';
4
+ import { LocalesEnum } from '#modules/common/common.types.js';
5
+ import { ConfigProvider } from '#modules/config/config.provider.js';
6
+ import { TranslationEngine } from '#modules/translation/translation.engine.js';
7
+ import { searchLocalePathsByPattern } from '#utils/path.js';
8
+ import picomatch from 'picomatch';
9
+ import { handleLaraApiError } from '#utils/error.js';
10
+ import { LaraApiError } from '@translated/lara';
11
+ import { progressWithOra } from '#utils/progressWithOra.js';
12
+ import { Messages } from '#messages/messages.js';
13
+ import { displaySummaryBox } from '#utils/display.js';
14
+ export default new Command()
15
+ .command('translate')
16
+ .description('Translate all files specified in the config file')
17
+ .addOption(new Option('-t, --target <locales>', 'The locale to translate to (separated by a comma, a space or a combination of both)')
18
+ .argParser((value) => {
19
+ const locales = value.split(COMMA_AND_SPACE_REGEX);
20
+ for (const locale of locales) {
21
+ const parsed = LocalesEnum.safeParse(locale);
22
+ if (!parsed.success) {
23
+ Ora({ text: Messages.errors.invalidLocale(locale), color: 'red' }).fail();
24
+ process.exit(1);
25
+ }
26
+ }
27
+ return locales.map((locale) => LocalesEnum.parse(locale));
28
+ })
29
+ .default(''))
30
+ .addOption(new Option('-p, --paths <paths>', 'Specific file paths to translate (separated by a comma, a space or a combination of both). Must include [locale] placeholder.')
31
+ .argParser((value) => {
32
+ return value.split(COMMA_AND_SPACE_REGEX).map((path) => path.trim());
33
+ })
34
+ .default([]))
35
+ .addOption(new Option('-f, --force', 'Force translation even if the files have not changed').default(false))
36
+ .action(async (options) => {
37
+ try {
38
+ const config = ConfigProvider.getInstance().getConfig();
39
+ if (options.target.includes(config.locales.source)) {
40
+ throw new Error(Messages.errors.sourceLocaleInTarget);
41
+ }
42
+ const spinner = Ora({ text: Messages.info.calculatingWork, color: 'yellow' }).start();
43
+ const { totalElements } = await calculateTotalWork(options, config);
44
+ spinner.succeed(Messages.success.foundFileCombinations(totalElements));
45
+ progressWithOra.start({ message: Messages.info.translatingFiles, total: totalElements });
46
+ let hasErrors = false;
47
+ for (const fileType of Object.keys(config.files)) {
48
+ hasErrors = hasErrors || await handleFileType(fileType, options, config);
49
+ }
50
+ if (hasErrors) {
51
+ process.exit(1);
52
+ }
53
+ const totalTargetLocales = getTargetLocales(options, config).length;
54
+ progressWithOra.stop();
55
+ displaySummaryBox({
56
+ title: Messages.summary.title,
57
+ items: [
58
+ [Messages.summary.filesLabel, Messages.summary.filesLocalized(totalElements)],
59
+ [Messages.summary.targetLocalesLabel, Messages.summary.targetLocales(totalTargetLocales)],
60
+ ],
61
+ footer: Messages.summary.allDone,
62
+ });
63
+ }
64
+ catch (error) {
65
+ const message = error instanceof Error ? error.message : String(error);
66
+ Ora({ text: message, color: 'red' }).fail();
67
+ process.exit(1);
68
+ }
69
+ });
70
+ async function handleFileType(fileType, options, config) {
71
+ const fileConfig = config.files[fileType];
72
+ const sourceLocale = config.locales.source;
73
+ const targetLocales = getTargetLocales(options, config);
74
+ const inputPathsArray = await getInputPaths(fileType, config, options.input);
75
+ let hasErrors = false;
76
+ for (const inputPath of inputPathsArray) {
77
+ const fileInstructionConfig = fileConfig.fileInstructions.find((fc) => fc.path === inputPath);
78
+ const translationEngine = new TranslationEngine({
79
+ sourceLocale,
80
+ targetLocales,
81
+ inputPath,
82
+ forceTranslation: options.force,
83
+ lockedKeys: fileConfig.lockedKeys,
84
+ ignoredKeys: fileConfig.ignoredKeys,
85
+ projectInstruction: config.project?.instruction,
86
+ fileInstruction: fileInstructionConfig?.instruction,
87
+ fileKeyInstructions: fileInstructionConfig?.keyInstructions || [],
88
+ globalKeyInstructions: fileConfig.keyInstructions,
89
+ translationMemoryIds: config.memories,
90
+ glossaryIds: config.glossaries,
91
+ });
92
+ try {
93
+ await translationEngine.translate();
94
+ }
95
+ catch (error) {
96
+ if (error instanceof LaraApiError) {
97
+ handleLaraApiError(error, Messages.errors.errorTranslatingFile(inputPath), progressWithOra.spinner);
98
+ if (error.statusCode !== 401 && error.statusCode < 500) {
99
+ hasErrors = true;
100
+ }
101
+ continue;
102
+ }
103
+ const message = error instanceof Error ? error.message : String(error);
104
+ const errorMessage = Messages.errors.translatingFile(inputPath, message);
105
+ console.error(errorMessage);
106
+ progressWithOra.stop(errorMessage, 'fail');
107
+ hasErrors = true;
108
+ continue;
109
+ }
110
+ }
111
+ return hasErrors;
112
+ }
113
+ function getTargetLocales(options, config) {
114
+ const targetLocales = options.target.length > 0 ? options.target : config.locales.target;
115
+ if (targetLocales.length === 0) {
116
+ throw new Error(Messages.errors.noTargetLocales);
117
+ }
118
+ return targetLocales;
119
+ }
120
+ async function getInputPaths(fileType, config, customPaths) {
121
+ const fileConfig = config.files[fileType];
122
+ const excludePatterns = fileConfig.exclude.map((key) => picomatch(key));
123
+ const inputPaths = new Set();
124
+ const pathsToProcess = customPaths && customPaths.length > 0 ? customPaths : fileConfig.include;
125
+ for (const includePath of pathsToProcess) {
126
+ if (!includePath.includes('*')) {
127
+ inputPaths.add(includePath);
128
+ continue;
129
+ }
130
+ const files = await searchLocalePathsByPattern(includePath);
131
+ files.forEach((file) => {
132
+ if (excludePatterns.some((pattern) => pattern(file))) {
133
+ return;
134
+ }
135
+ inputPaths.add(file);
136
+ });
137
+ }
138
+ return Array.from(inputPaths);
139
+ }
140
+ async function calculateTotalWork(options, config) {
141
+ const targetLocales = getTargetLocales(options, config);
142
+ let totalElements = 0;
143
+ for (const fileType of Object.keys(config.files)) {
144
+ const inputPaths = await getInputPaths(fileType, config, options.input);
145
+ totalElements += inputPaths.length * targetLocales.length;
146
+ }
147
+ return { totalElements };
148
+ }
149
+ //# sourceMappingURL=translate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.js","sourceRoot":"/","sources":["cli/cmd/translate/translate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B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C5B,SAAS;QACX,CAAC;QAGD,MAAM,KAAK,GAAG,MAAM,0BAA0B,CAAC,WAAW,CAAC,CAAC;QAE5D,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;gBACrD,OAAO;YACT,CAAC;YAED,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AAED,KAAK,UAAU,kBAAkB,CAC/B,OAAyB,EACzB,MAAkB;IAElB,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QACxE,aAAa,IAAI,UAAU,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;IAC5D,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from 'node:module';
3
+ import { Command, Option } from 'commander';
4
+ import dotenv from 'dotenv';
5
+ dotenv.config({ debug: false, quiet: true });
6
+ import initCommand from './cli/cmd/init/init.js';
7
+ import translateCommand from './cli/cmd/translate/translate.js';
8
+ import memoryCommand from './cli/cmd/memory/memory.js';
9
+ import glossaryCommand from './cli/cmd/glossary/glossary.js';
10
+ const require = createRequire(import.meta.url);
11
+ const packageJson = require('../package.json');
12
+ const version = packageJson.version;
13
+ const program = new Command()
14
+ .name('lara-cli')
15
+ .description('Lara CLI')
16
+ .helpOption('-h, --help', 'Show help')
17
+ .version(version)
18
+ .addOption(new Option('-y --non-interactive', 'Run in non-interactive mode').default(false))
19
+ .addCommand(initCommand)
20
+ .addCommand(translateCommand)
21
+ .addCommand(memoryCommand)
22
+ .addCommand(glossaryCommand);
23
+ program.parse();
24
+ export default program;
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE7C,OAAO,WAAW,MAAM,wBAAwB,CAAC;AACjD,OAAO,gBAAgB,MAAM,kCAAkC,CAAC;AAChE,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,eAAe,MAAM,gCAAgC,CAAC;AAE7D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AACtE,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;AAEpC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;KAC1B,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,UAAU,CAAC;KACvB,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC;KACrC,OAAO,CAAC,OAAO,CAAC;KAChB,SAAS,CAAC,IAAI,MAAM,CAAC,sBAAsB,EAAE,6BAA6B,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAC3F,UAAU,CAAC,WAAW,CAAC;KACvB,UAAU,CAAC,gBAAgB,CAAC;KAC5B,UAAU,CAAC,aAAa,CAAC;KACzB,UAAU,CAAC,eAAe,CAAC,CAAC;AAG/B,OAAO,CAAC,KAAK,EAAE,CAAC;AAEhB,eAAe,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"/","sources":["interface/parser.ts"],"names":[],"mappings":""}
@@ -0,0 +1,120 @@
1
+ export const Messages = {
2
+ errors: {
3
+ invalidLocale: (locale) => `Invalid locale: ${locale}`,
4
+ noLocalesFound: 'No locales found in the project',
5
+ noLocalesFoundHint: 'Please ensure your project contains locale files (e.g., src/i18n/[locale].json or src/i18n/[locale]/...)',
6
+ sourceLocaleInTarget: 'Source locale cannot be included in the target locales',
7
+ noTargetLocales: 'No target locales specified. Please add target locales in config or use -t option.',
8
+ configNotFound: 'Config file not found. Please run `lara-cli init` to create a config file.',
9
+ invalidConfig: (issues) => `Invalid configuration file. Issues found:\n${issues}`,
10
+ noApiCredentials: 'No API credentials found. Please run `lara-cli init` to set the API credentials.',
11
+ apiAuthFailed: (context) => `${context}: Authentication failed. Your API credentials are invalid or expired. Run 'lara-cli init --reset-credentials' to update them.`,
12
+ serviceUnavailable: (context, statusCode) => `${context}: Service unavailable (${statusCode}). Please try again later.`,
13
+ translationFailed: (context, message) => `${context}: Translation failed: ${message || 'Unknown error'}`,
14
+ translatingFile: (filePath, message) => `Error translating ${filePath}: ${message}`,
15
+ sourceLocaleRequired: 'Source locale selection is required',
16
+ configOverwriteDeclined: 'Configuration file already exists. Initialization cancelled.',
17
+ credentialValidation: (name) => `${name} must be 8-128 characters.`,
18
+ envReadFailed: (message) => `Failed to read .env file: ${message}. Please check file permissions.`,
19
+ unknownError: 'An unknown error occurred',
20
+ noSupportedFileTypes: 'No supported file types configured',
21
+ emptyTranslationResult: (value) => `Translation service returned empty result for: ${value}`,
22
+ maxRetriesExceeded: 'Maximum retry attempts exceeded. Please try again later.',
23
+ envVarsNotSet: 'LARA_ACCESS_KEY_ID and LARA_ACCESS_KEY_SECRET must be set',
24
+ gettingMemories: 'Error getting Translation Memories',
25
+ gettingGlossaries: 'Error getting Glossaries',
26
+ errorTranslatingFile: (filePath) => `Error translating ${filePath}`,
27
+ invalidPath: 'Invalid path',
28
+ selectAtLeastOneLocale: 'Please select at least one locale',
29
+ selectAtLeastOnePath: 'Please select at least one path',
30
+ progressTotalInvalid: 'Progress total must be greater than 0',
31
+ processing: 'Processing...',
32
+ selectionRequired: 'At least one choice must be selected',
33
+ unknownErrorFallback: 'Unknown error',
34
+ translationCompletedWithErrors: 'Translation completed with errors',
35
+ localizationFailed: 'Localization failed due to errors',
36
+ },
37
+ success: {
38
+ configCreated: 'Config file created successfully! You can run `lara-cli translate` to start translating your files.',
39
+ apiCredentialsSet: 'API credentials set successfully',
40
+ localizationCompleted: 'Localization completed! Happy coding!',
41
+ allFilesTranslated: 'All files translated successfully!',
42
+ completed: 'Completed!',
43
+ foundLocales: (count) => `Found ${count} ${count === 1 ? 'locale' : 'locales'} in project`,
44
+ foundTargetLocales: (count, locales) => locales
45
+ ? `Found ${count} target ${count === 1 ? 'locale' : 'locales'}: ${locales}`
46
+ : `Found ${count} target ${count === 1 ? 'locale' : 'locales'}`,
47
+ foundFileCombinations: (count) => count > 1 ? `Found ${count} files to localize` : `Found ${count} file to localize`,
48
+ pathsFound: 'Paths found successfully',
49
+ foundMemories: (count) => `Found ${count} Translation ${count === 1 ? 'Memory' : 'Memories'}:\n`,
50
+ foundGlossaries: (count) => `Found ${count} ${count === 1 ? 'Glossary' : 'Glossaries'}:\n`,
51
+ targetLocalesSelected: (locales, summary) => `Target locales selected: ${locales}${summary || ''}`,
52
+ totalTargetLocalesSelected: (count, summary) => `Total ${count} target ${count === 1 ? 'locale' : 'locales'} selected${summary || ''}`,
53
+ },
54
+ summary: {
55
+ title: '📦 Localization Summary',
56
+ filesLocalized: (count) => `${count} ${count === 1 ? 'file' : 'files'}`,
57
+ targetLocales: (count) => `${count} ${count === 1 ? 'locale' : 'locales'}`,
58
+ allDone: '✓ All done! Happy coding!',
59
+ filesLabel: 'Files localized',
60
+ targetLocalesLabel: 'Target locales',
61
+ },
62
+ info: {
63
+ searchingLocales: 'Searching for locales in project...',
64
+ searchingTargetLocales: 'Searching for target locales...',
65
+ searchingPaths: 'Searching for paths...',
66
+ calculatingWork: 'Calculating total work...',
67
+ translatingFiles: 'Translating files...',
68
+ translatingFileProgress: (inputPath, targetLocale, keysCount) => `Translating ${inputPath} → ${targetLocale} (${keysCount} keys)...`,
69
+ creatingConfig: 'Creating config file...',
70
+ fetchingMemories: 'Fetching Translation Memories...',
71
+ fetchingGlossaries: 'Fetching Glossaries...',
72
+ autoDetectionSkipped: 'Automatic detection of target locales was skipped.',
73
+ noTargetLocalesFound: 'No target locales were found. You can add them manually.',
74
+ noPathsFound: 'No paths found',
75
+ noEnvFile: 'No .env file found. Creating one...',
76
+ alreadyAdded: (locales) => `Already added: ${locales}`,
77
+ localesAlreadyAdded: (count) => `${count} ${count === 1 ? 'locale' : 'locales'} already added`,
78
+ autoDetected: (count) => `${count} auto-detected`,
79
+ manuallyAdded: (count) => `${count} manually added`,
80
+ },
81
+ warnings: {
82
+ noApiCredentials: `No API credentials found on machine. Without API credentials, Lara CLI will not be able to translate your files. You can insert them anytime later by modifying your system environment variables or your .env file. You can find more info at https://support.laratranslate.com/en/about-lara`,
83
+ noMemoriesLinked: (url) => `No Translation Memories linked. Visit ${url} to learn more.`,
84
+ noGlossariesLinked: (url) => `No Glossaries linked. Visit ${url} to learn more.`,
85
+ },
86
+ ui: {
87
+ disabled: '(disabled)',
88
+ typeToSearch: 'Type to search...',
89
+ searchLabel: (query) => `Search: ${query}`,
90
+ navigate: '↑/↓',
91
+ space: 'Space',
92
+ enter: 'Enter',
93
+ ctrlA: 'Ctrl+A',
94
+ helpMultiSelect: (navigate, space, ctrlA) => `(Type to search, ${navigate} navigate, ${space} select, ${ctrlA} toggle all)`,
95
+ helpSingleSelect: (navigate, spaceEnter) => `(Type to search, ${navigate} navigate, ${spaceEnter} to select)`,
96
+ itemId: (id) => ` ID: ${id}`,
97
+ itemName: (name) => ` Name: ${name}`,
98
+ },
99
+ prompts: {
100
+ sourceLocale: 'What is the source locale?',
101
+ autoDetectTarget: 'Automatically detect and add target locales?',
102
+ selectPaths: 'Select the paths to watch',
103
+ addMoreTargetLocales: (alreadyAdded) => `Do you want to add more target locales? (${alreadyAdded})`,
104
+ selectTargetLocales: 'What are the target locales?',
105
+ selectAdditionalTargetLocales: 'Select additional target locales',
106
+ enterPaths: 'No paths found, enter the paths to watch (separated by a comma, a space or a combination of both)',
107
+ resetCredentials: 'Do you want to reset the API credentials?',
108
+ overwriteConfig: 'Config file already exists, do you want to overwrite it?',
109
+ insertCredentials: 'No API credentials found on machine, do you want to insert them now in a .env file?',
110
+ apiKey: 'Insert your API Key:',
111
+ apiSecret: 'Insert your API Secret:',
112
+ selectMemories: 'Select the memories Lara will use to personalize your translations',
113
+ selectGlossaries: 'Select the glossaries Lara will use to personalize your translations',
114
+ updateMemories: 'Do you want to update the selected Translation Memories?',
115
+ useMemories: 'Do you want to use Translation Memories?',
116
+ updateGlossaries: 'Do you want to update the selected Glossaries?',
117
+ useGlossaries: 'Do you want to use Glossaries?',
118
+ },
119
+ };
120
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"/","sources":["messages/messages.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,MAAM,EAAE;QACN,aAAa,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,mBAAmB,MAAM,EAAE;QAC9D,cAAc,EAAE,iCAAiC;QACjD,kBAAkB,EAChB,0GAA0G;QAC5G,oBAAoB,EAAE,wDAAwD;QAC9E,eAAe,EACb,oFAAoF;QACtF,cAAc,EAA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