@umituz/web-localization 1.0.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 (42) hide show
  1. package/README.md +71 -0
  2. package/package.json +54 -0
  3. package/src/domain/entities/translation.entity.d.ts +30 -0
  4. package/src/domain/entities/translation.entity.d.ts.map +1 -0
  5. package/src/domain/entities/translation.entity.js +5 -0
  6. package/src/domain/entities/translation.entity.ts +33 -0
  7. package/src/domain/interfaces/translation-service.interface.d.ts +21 -0
  8. package/src/domain/interfaces/translation-service.interface.d.ts.map +1 -0
  9. package/src/domain/interfaces/translation-service.interface.js +1 -0
  10. package/src/domain/interfaces/translation-service.interface.ts +33 -0
  11. package/src/index.d.ts +11 -0
  12. package/src/index.d.ts.map +1 -0
  13. package/src/index.js +10 -0
  14. package/src/index.ts +11 -0
  15. package/src/infrastructure/constants/index.d.ts +11 -0
  16. package/src/infrastructure/constants/index.d.ts.map +1 -0
  17. package/src/infrastructure/constants/index.js +10 -0
  18. package/src/infrastructure/constants/index.ts +13 -0
  19. package/src/infrastructure/services/cli.service.d.ts +11 -0
  20. package/src/infrastructure/services/cli.service.d.ts.map +1 -0
  21. package/src/infrastructure/services/cli.service.js +95 -0
  22. package/src/infrastructure/services/cli.service.ts +129 -0
  23. package/src/infrastructure/services/google-translate.service.d.ts +20 -0
  24. package/src/infrastructure/services/google-translate.service.d.ts.map +1 -0
  25. package/src/infrastructure/services/google-translate.service.js +202 -0
  26. package/src/infrastructure/services/google-translate.service.ts +279 -0
  27. package/src/infrastructure/utils/file.util.d.ts +10 -0
  28. package/src/infrastructure/utils/file.util.d.ts.map +1 -0
  29. package/src/infrastructure/utils/file.util.js +41 -0
  30. package/src/infrastructure/utils/file.util.ts +46 -0
  31. package/src/infrastructure/utils/rate-limit.util.d.ts +11 -0
  32. package/src/infrastructure/utils/rate-limit.util.d.ts.map +1 -0
  33. package/src/infrastructure/utils/rate-limit.util.js +20 -0
  34. package/src/infrastructure/utils/rate-limit.util.ts +25 -0
  35. package/src/infrastructure/utils/text-validator.util.d.ts +16 -0
  36. package/src/infrastructure/utils/text-validator.util.d.ts.map +1 -0
  37. package/src/infrastructure/utils/text-validator.util.js +34 -0
  38. package/src/infrastructure/utils/text-validator.util.ts +31 -0
  39. package/src/scripts/cli.d.ts +6 -0
  40. package/src/scripts/cli.d.ts.map +1 -0
  41. package/src/scripts/cli.js +41 -0
  42. package/src/scripts/cli.ts +46 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Text Validation Utilities
3
+ */
4
+ /**
5
+ * Validates if the text is suitable for translation
6
+ */
7
+ export function isValidText(text) {
8
+ if (typeof text !== "string")
9
+ return false;
10
+ if (text.trim().length === 0)
11
+ return false;
12
+ if (/^\d+$/.test(text))
13
+ return false; // Don't translate pure numbers
14
+ return true;
15
+ }
16
+ /**
17
+ * Checks if a word should be skipped (e.g., proper nouns, symbols)
18
+ */
19
+ export function shouldSkipWord(text) {
20
+ const skiplist = ["@umituz"];
21
+ return skiplist.some(word => text.includes(word));
22
+ }
23
+ /**
24
+ * Determines if a key needs translation
25
+ */
26
+ export function needsTranslation(targetValue, sourceValue) {
27
+ if (typeof targetValue !== "string")
28
+ return true;
29
+ if (targetValue.trim().length === 0)
30
+ return true;
31
+ if (targetValue === sourceValue && !/^\d+$/.test(sourceValue))
32
+ return true;
33
+ return false;
34
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Text Validation Utilities
3
+ */
4
+
5
+ /**
6
+ * Validates if the text is suitable for translation
7
+ */
8
+ export function isValidText(text: unknown): text is string {
9
+ if (typeof text !== "string") return false;
10
+ if (text.trim().length === 0) return false;
11
+ if (/^\d+$/.test(text)) return false; // Don't translate pure numbers
12
+ return true;
13
+ }
14
+
15
+ /**
16
+ * Checks if a word should be skipped (e.g., proper nouns, symbols)
17
+ */
18
+ export function shouldSkipWord(text: string): boolean {
19
+ const skiplist = ["@umituz"];
20
+ return skiplist.some(word => text.includes(word));
21
+ }
22
+
23
+ /**
24
+ * Determines if a key needs translation
25
+ */
26
+ export function needsTranslation(targetValue: unknown, sourceValue: string): boolean {
27
+ if (typeof targetValue !== "string") return true;
28
+ if (targetValue.trim().length === 0) return true;
29
+ if (targetValue === sourceValue && !/^\d+$/.test(sourceValue)) return true;
30
+ return false;
31
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI Tool for @umituz/web-localization
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["cli.ts"],"names":[],"mappings":";AAEA;;GAEG"}
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI Tool for @umituz/web-localization
4
+ */
5
+ import { Command } from "commander";
6
+ import { cliService } from "../infrastructure/services/cli.service";
7
+ import chalk from "chalk";
8
+ const program = new Command();
9
+ program
10
+ .name("web-loc")
11
+ .description("Localization CLI tool for web applications")
12
+ .version("1.0.0");
13
+ program
14
+ .command("sync")
15
+ .description("Synchronize missing keys from base language to other languages")
16
+ .option("-d, --locales-dir <dir>", "Directory containing locale files", "src/locales")
17
+ .option("-b, --base-lang <lang>", "Base language code", "en-US")
18
+ .action(async (options) => {
19
+ try {
20
+ await cliService.sync(options);
21
+ }
22
+ catch (error) {
23
+ console.error(chalk.red("❌ Sync failed:"), error instanceof Error ? error.message : error);
24
+ process.exit(1);
25
+ }
26
+ });
27
+ program
28
+ .command("translate")
29
+ .description("Automatically translate missing strings using Google Translate")
30
+ .option("-d, --locales-dir <dir>", "Directory containing locale files", "src/locales")
31
+ .option("-b, --base-lang <lang>", "Base language code", "en-US")
32
+ .action(async (options) => {
33
+ try {
34
+ await cliService.translate(options);
35
+ }
36
+ catch (error) {
37
+ console.error(chalk.red("❌ Translation failed:"), error instanceof Error ? error.message : error);
38
+ process.exit(1);
39
+ }
40
+ });
41
+ program.parse();
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI Tool for @umituz/web-localization
5
+ */
6
+
7
+ import { Command } from "commander";
8
+ import { cliService } from "../infrastructure/services/cli.service";
9
+ import chalk from "chalk";
10
+
11
+ const program = new Command();
12
+
13
+ program
14
+ .name("web-loc")
15
+ .description("Localization CLI tool for web applications")
16
+ .version("1.0.0");
17
+
18
+ program
19
+ .command("sync")
20
+ .description("Synchronize missing keys from base language to other languages")
21
+ .option("-d, --locales-dir <dir>", "Directory containing locale files", "src/locales")
22
+ .option("-b, --base-lang <lang>", "Base language code", "en-US")
23
+ .action(async (options) => {
24
+ try {
25
+ await cliService.sync(options);
26
+ } catch (error) {
27
+ console.error(chalk.red("❌ Sync failed:"), error instanceof Error ? error.message : error);
28
+ process.exit(1);
29
+ }
30
+ });
31
+
32
+ program
33
+ .command("translate")
34
+ .description("Automatically translate missing strings using Google Translate")
35
+ .option("-d, --locales-dir <dir>", "Directory containing locale files", "src/locales")
36
+ .option("-b, --base-lang <lang>", "Base language code", "en-US")
37
+ .action(async (options) => {
38
+ try {
39
+ await cliService.translate(options);
40
+ } catch (error) {
41
+ console.error(chalk.red("❌ Translation failed:"), error instanceof Error ? error.message : error);
42
+ process.exit(1);
43
+ }
44
+ });
45
+
46
+ program.parse();