generaltranslation 9.3.1 → 9.4.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 (59) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/adapter/createGtApi.d.ts +102 -0
  3. package/dist/adapter/createGtApi.js +373 -0
  4. package/dist/{derive-Yxp38Tjn.cjs → derive-2CDqwrvS.cjs} +20 -1
  5. package/dist/derive-2CDqwrvS.cjs.map +1 -0
  6. package/dist/{derive-BEA36WQM.mjs → derive-CTzR56T_.mjs} +9 -2
  7. package/dist/derive-CTzR56T_.mjs.map +1 -0
  8. package/dist/id/hashSource.d.ts +2 -1
  9. package/dist/id/hashSource.js +3 -2
  10. package/dist/id/types.d.ts +2 -0
  11. package/dist/{id-BMOKDfiZ.mjs → id-X2zyx5Jk.mjs} +5 -3
  12. package/dist/id-X2zyx5Jk.mjs.map +1 -0
  13. package/dist/{id-BpSNpXZu.cjs → id-pdr3R1xs.cjs} +5 -3
  14. package/dist/{id-BpSNpXZu.cjs.map → id-pdr3R1xs.cjs.map} +1 -1
  15. package/dist/id.cjs +1 -1
  16. package/dist/id.d.cts +4 -2
  17. package/dist/id.d.mts +4 -2
  18. package/dist/id.mjs +1 -1
  19. package/dist/index.cjs +62 -30
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +1 -1
  22. package/dist/index.d.mts +1 -1
  23. package/dist/index.js +85 -32
  24. package/dist/index.mjs +62 -30
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/internal.cjs +178 -2
  27. package/dist/internal.cjs.map +1 -1
  28. package/dist/internal.d.cts +108 -4
  29. package/dist/internal.d.mts +108 -4
  30. package/dist/internal.d.ts +3 -1
  31. package/dist/internal.js +2 -1
  32. package/dist/internal.mjs +176 -2
  33. package/dist/internal.mjs.map +1 -1
  34. package/dist/openapi.json +4775 -1992
  35. package/dist/{runtime-CqKaoInO.mjs → runtime-Bcp4F2ME.mjs} +33 -14
  36. package/dist/runtime-Bcp4F2ME.mjs.map +1 -0
  37. package/dist/{runtime-DeF1Ef5w.cjs → runtime-C25lwh9m.cjs} +32 -13
  38. package/dist/runtime-C25lwh9m.cjs.map +1 -0
  39. package/dist/runtime.cjs +1 -1
  40. package/dist/runtime.d.cts +9 -1
  41. package/dist/runtime.d.mts +9 -1
  42. package/dist/runtime.d.ts +8 -0
  43. package/dist/runtime.js +44 -14
  44. package/dist/runtime.mjs +1 -1
  45. package/dist/translate/translateMany.js +1 -1
  46. package/dist/{types-BUNfoXph.d.mts → types-Dp1drjxq.d.mts} +7 -3
  47. package/dist/{types-Do446qa9.d.cts → types-bCr8pV1Z.d.cts} +7 -3
  48. package/dist/types-dir/api/entry.d.ts +3 -0
  49. package/dist/types.d.cts +2 -2
  50. package/dist/types.d.mts +2 -2
  51. package/dist/types.d.ts +1 -0
  52. package/dist/utils/base64.d.ts +3 -0
  53. package/dist/utils/base64.js +7 -0
  54. package/package.json +3 -3
  55. package/dist/derive-BEA36WQM.mjs.map +0 -1
  56. package/dist/derive-Yxp38Tjn.cjs.map +0 -1
  57. package/dist/id-BMOKDfiZ.mjs.map +0 -1
  58. package/dist/runtime-CqKaoInO.mjs.map +0 -1
  59. package/dist/runtime-DeF1Ef5w.cjs.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_unwrapApiResult = require("./unwrapApiResult-Dv6Mfw_K.cjs");
3
- const require_runtime = require("./runtime-DeF1Ef5w.cjs");
4
- const require_derive = require("./derive-Yxp38Tjn.cjs");
3
+ const require_runtime = require("./runtime-C25lwh9m.cjs");
4
+ const require_derive = require("./derive-2CDqwrvS.cjs");
5
5
  const require_file = require("./file-B37WkCqM.cjs");
6
6
  let _generaltranslation_format = require("@generaltranslation/format");
7
7
  let _generaltranslation_api = require("@generaltranslation/api");
@@ -774,7 +774,7 @@ var GT = class extends require_runtime.GTRuntime {
774
774
  this._validateAuth("setupProject");
775
775
  options = {
776
776
  ...options,
777
- locales: options?.locales?.map((locale) => this.resolveCanonicalLocale(locale))
777
+ locales: options?.locales?.map((locale) => this.resolveServiceLocale(locale))
778
778
  };
779
779
  return await _setupProject(files, this._getTranslationConfig(), options);
780
780
  }
@@ -839,11 +839,16 @@ var GT = class extends require_runtime.GTRuntime {
839
839
  require_runtime.gtInstanceLogger.error(error);
840
840
  throw new Error(error);
841
841
  }
842
+ const targetLocaleIdentities = [...mergedOptions.targetLocales];
842
843
  mergedOptions = {
843
844
  ...mergedOptions,
844
- targetLocales: mergedOptions.targetLocales.map((locale) => this.resolveCanonicalLocale(locale))
845
+ sourceLocale: this.resolveServiceLocale(mergedOptions.sourceLocale),
846
+ targetLocales: mergedOptions.targetLocales.map((locale) => this.resolveServiceLocale(locale))
847
+ };
848
+ return {
849
+ ...await _enqueueFiles(files, mergedOptions, this._getTranslationConfig()),
850
+ locales: targetLocaleIdentities
845
851
  };
846
- return await _enqueueFiles(files, mergedOptions, this._getTranslationConfig());
847
852
  }
848
853
  /**
849
854
  * Creates or upserts a file tag, associating a set of source files
@@ -864,7 +869,10 @@ var GT = class extends require_runtime.GTRuntime {
864
869
  */
865
870
  async publishFiles(files) {
866
871
  this._validateAuth("publishFiles");
867
- return await _publishFiles(files, this._getTranslationConfig());
872
+ return { results: (await _publishFiles(files, this._getTranslationConfig())).results.map((item) => ({
873
+ ...item,
874
+ ...item.locale && { locale: this.resolveServiceResponseLocale(item.locale) }
875
+ })) };
868
876
  }
869
877
  /**
870
878
  * Submits user edit diffs for existing translations so future generations preserve user intent.
@@ -878,7 +886,7 @@ var GT = class extends require_runtime.GTRuntime {
878
886
  ...payload,
879
887
  diffs: (payload.diffs || []).map((d) => ({
880
888
  ...d,
881
- locale: this.resolveCanonicalLocale(d.locale)
889
+ locale: this.resolveServiceLocale(d.locale)
882
890
  }))
883
891
  }, this._getTranslationConfig());
884
892
  }
@@ -910,23 +918,28 @@ var GT = class extends require_runtime.GTRuntime {
910
918
  */
911
919
  async getProjectInfo(options = {}) {
912
920
  this._validateAuth("getProjectInfo");
913
- return await _getProjectInfo(options, this._getTranslationConfig());
921
+ const result = await _getProjectInfo(options, this._getTranslationConfig());
922
+ return {
923
+ ...result,
924
+ defaultLocale: this.resolveServiceResponseLocale(result.defaultLocale),
925
+ currentLocales: result.currentLocales.map((locale) => this.resolveServiceResponseLocale(locale))
926
+ };
914
927
  }
915
928
  async queryFileData(data, options = {}) {
916
929
  this._validateAuth("queryFileData");
917
930
  data.translatedFiles = data.translatedFiles?.map((item) => ({
918
931
  ...item,
919
- locale: this.resolveCanonicalLocale(item.locale)
932
+ locale: this.resolveServiceLocale(item.locale)
920
933
  }));
921
934
  const result = await _queryFileData(data, options, this._getTranslationConfig());
922
935
  result.translatedFiles = result.translatedFiles?.map((item) => ({
923
936
  ...item,
924
- ...item.locale && { locale: this.resolveAliasLocale(item.locale) }
937
+ ...item.locale && { locale: this.resolveServiceResponseLocale(item.locale) }
925
938
  }));
926
939
  result.sourceFiles = result.sourceFiles?.map((item) => ({
927
940
  ...item,
928
- ...item.sourceLocale && { sourceLocale: this.resolveAliasLocale(item.sourceLocale) },
929
- locales: item.locales.map((locale) => this.resolveAliasLocale(locale))
941
+ ...item.sourceLocale && { sourceLocale: this.resolveServiceResponseLocale(item.sourceLocale) },
942
+ locales: item.locales.map((locale) => this.resolveServiceResponseLocale(locale))
930
943
  }));
931
944
  return result;
932
945
  }
@@ -949,10 +962,10 @@ var GT = class extends require_runtime.GTRuntime {
949
962
  const result = await _querySourceFile(data, options, this._getTranslationConfig());
950
963
  result.translations = result.translations.map((item) => ({
951
964
  ...item,
952
- ...item.locale && { locale: this.resolveAliasLocale(item.locale) }
965
+ ...item.locale && { locale: this.resolveServiceResponseLocale(item.locale) }
953
966
  }));
954
- result.sourceFile.locales = result.sourceFile.locales.map((locale) => this.resolveAliasLocale(locale));
955
- if (result.sourceFile.sourceLocale) result.sourceFile.sourceLocale = this.resolveAliasLocale(result.sourceFile.sourceLocale);
967
+ result.sourceFile.locales = result.sourceFile.locales.map((locale) => this.resolveServiceResponseLocale(locale));
968
+ if (result.sourceFile.sourceLocale) result.sourceFile.sourceLocale = this.resolveServiceResponseLocale(result.sourceFile.sourceLocale);
956
969
  return result;
957
970
  }
958
971
  /**
@@ -970,8 +983,8 @@ var GT = class extends require_runtime.GTRuntime {
970
983
  async getProjectData(projectId, options = {}) {
971
984
  this._validateAuth("getProjectData");
972
985
  const result = await _getProjectData(projectId, options, this._getTranslationConfig());
973
- result.currentLocales = result.currentLocales.map((item) => this.resolveAliasLocale(item));
974
- result.defaultLocale = this.resolveAliasLocale(result.defaultLocale);
986
+ result.currentLocales = result.currentLocales.map((item) => this.resolveServiceResponseLocale(item));
987
+ result.defaultLocale = this.resolveServiceResponseLocale(result.defaultLocale);
975
988
  return result;
976
989
  }
977
990
  /**
@@ -1000,7 +1013,7 @@ var GT = class extends require_runtime.GTRuntime {
1000
1013
  return (await _downloadFileBatch([{
1001
1014
  fileId: file.fileId,
1002
1015
  branchId: file.branchId,
1003
- locale: file.locale ? this.resolveCanonicalLocale(file.locale) : void 0,
1016
+ locale: file.locale ? this.resolveServiceLocale(file.locale) : void 0,
1004
1017
  versionId: file.versionId,
1005
1018
  useLatestAvailableVersion: file.useLatestAvailableVersion
1006
1019
  }], options, this._getTranslationConfig())).data?.[0]?.data ?? "";
@@ -1023,16 +1036,31 @@ var GT = class extends require_runtime.GTRuntime {
1023
1036
  */
1024
1037
  async downloadFileBatch(requests, options = {}) {
1025
1038
  this._validateAuth("downloadFileBatch");
1026
- requests = requests.map((request) => ({
1027
- ...request,
1028
- locale: request.locale ? this.resolveCanonicalLocale(request.locale) : void 0
1029
- }));
1039
+ const requestedFiles = /* @__PURE__ */ new Map();
1040
+ requests = requests.map((request) => {
1041
+ const locale = request.locale ? this.resolveServiceLocale(request.locale) : void 0;
1042
+ if (locale) {
1043
+ const key = JSON.stringify([request.fileId, locale]);
1044
+ const group = requestedFiles.get(key) ?? [];
1045
+ group.push(request);
1046
+ requestedFiles.set(key, group);
1047
+ }
1048
+ return {
1049
+ ...request,
1050
+ locale
1051
+ };
1052
+ });
1030
1053
  const result = await _downloadFileBatch(requests, options, this._getTranslationConfig());
1031
1054
  return {
1032
- files: result.data.map((file) => ({
1033
- ...file,
1034
- ...file.locale && { locale: this.resolveAliasLocale(file.locale) }
1035
- })),
1055
+ files: result.data.map((file) => {
1056
+ if (!file.locale) return file;
1057
+ const serviceLocale = this.standardizeLocale(file.locale);
1058
+ const matchingRequests = (requestedFiles.get(JSON.stringify([file.fileId, serviceLocale])) ?? []).filter((request) => (!request.branchId || request.branchId === file.branchId) && (!request.versionId || request.versionId === file.versionId));
1059
+ return {
1060
+ ...file,
1061
+ locale: matchingRequests.length === 1 ? matchingRequests[0].locale : this.resolveServiceResponseLocale(file.locale)
1062
+ };
1063
+ }),
1036
1064
  count: result.count
1037
1065
  };
1038
1066
  }
@@ -1052,13 +1080,13 @@ var GT = class extends require_runtime.GTRuntime {
1052
1080
  this._validateAuth("uploadSourceFiles");
1053
1081
  const mergedOptions = {
1054
1082
  ...options,
1055
- sourceLocale: this.resolveCanonicalLocale(options.sourceLocale ?? this.sourceLocale ?? "en")
1083
+ sourceLocale: this.resolveServiceLocale(options.sourceLocale ?? this.sourceLocale ?? "en")
1056
1084
  };
1057
1085
  files = files.map((f) => ({
1058
1086
  ...f,
1059
1087
  source: {
1060
1088
  ...f.source,
1061
- locale: this.resolveCanonicalLocale(f.source.locale)
1089
+ locale: this.resolveServiceLocale(f.source.locale)
1062
1090
  }
1063
1091
  }));
1064
1092
  const result = await _uploadSourceFiles(files, mergedOptions, this._getTranslationConfig());
@@ -1109,12 +1137,16 @@ var GT = class extends require_runtime.GTRuntime {
1109
1137
  require_runtime.gtInstanceLogger.error(error);
1110
1138
  throw new Error(error);
1111
1139
  }
1112
- mergedOptions.sourceLocale = this.resolveCanonicalLocale(mergedOptions.sourceLocale);
1140
+ mergedOptions.sourceLocale = this.resolveServiceLocale(mergedOptions.sourceLocale);
1113
1141
  const result = await _uploadTranslations(files.map((f) => ({
1114
1142
  ...f,
1143
+ source: {
1144
+ ...f.source,
1145
+ locale: this.resolveServiceLocale(f.source.locale)
1146
+ },
1115
1147
  translations: f.translations.map((t) => ({
1116
1148
  ...t,
1117
- locale: this.resolveCanonicalLocale(t.locale)
1149
+ locale: this.resolveServiceLocale(t.locale)
1118
1150
  }))
1119
1151
  })), mergedOptions, this._getTranslationConfig());
1120
1152
  return {