generaltranslation 7.6.4-alpha.1 → 7.6.4-alpha.2

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 (71) hide show
  1. package/dist/backwards-compatability/dataConversion.d.ts +23 -0
  2. package/dist/backwards-compatability/oldHashJsxChildren.d.ts +23 -0
  3. package/dist/backwards-compatability/oldTypes.d.ts +21 -0
  4. package/dist/backwards-compatability/typeChecking.d.ts +21 -0
  5. package/dist/cache/IntlCache.d.ts +8 -0
  6. package/dist/deprecated/batch/translateBatch.d.ts +1 -0
  7. package/dist/deprecated/icu/translate.d.ts +1 -0
  8. package/dist/deprecated/jsx/translateJsx.d.ts +1 -0
  9. package/dist/deprecated/translate/translate.d.ts +1 -0
  10. package/dist/formatting/format.d.ts +1 -0
  11. package/dist/id/hashSource.d.ts +26 -0
  12. package/dist/id/hashTemplate.d.ts +4 -0
  13. package/dist/locales/customLocaleMapping.d.ts +5 -0
  14. package/dist/locales/determineLocale.d.ts +1 -0
  15. package/dist/locales/getLocaleDirection.d.ts +1 -0
  16. package/dist/locales/getLocaleEmoji.d.ts +2 -0
  17. package/dist/locales/getLocaleName.d.ts +1 -0
  18. package/dist/locales/getLocaleProperties.d.ts +32 -0
  19. package/dist/locales/getPluralForm.d.ts +9 -0
  20. package/dist/locales/getRegionProperties.d.ts +7 -0
  21. package/dist/locales/isSameDialect.d.ts +1 -0
  22. package/dist/locales/isSameLanguage.d.ts +1 -0
  23. package/dist/locales/isSupersetLocale.d.ts +1 -0
  24. package/dist/locales/isValidLocale.d.ts +1 -0
  25. package/dist/locales/requiresTranslation.d.ts +1 -0
  26. package/dist/locales/resolveAliasLocale.d.ts +8 -0
  27. package/dist/logging/errors.d.ts +10 -0
  28. package/dist/logging/logger.d.ts +117 -0
  29. package/dist/logging/warnings.d.ts +2 -0
  30. package/dist/projects/getProjectData.d.ts +1 -0
  31. package/dist/settings/plurals.d.ts +3 -0
  32. package/dist/settings/settings.d.ts +2 -0
  33. package/dist/settings/settingsUrls.d.ts +9 -0
  34. package/dist/translate/checkFileTranslations.d.ts +1 -0
  35. package/dist/translate/checkSetupStatus.d.ts +8 -0
  36. package/dist/translate/checkTranslationStatus.d.ts +1 -0
  37. package/dist/translate/downloadFile.d.ts +1 -0
  38. package/dist/translate/downloadFileBatch.d.ts +1 -0
  39. package/dist/translate/enqueueEntries.d.ts +1 -0
  40. package/dist/translate/enqueueFiles.d.ts +9 -0
  41. package/dist/translate/fetchTranslations.d.ts +1 -0
  42. package/dist/translate/querySourceFile.d.ts +1 -0
  43. package/dist/translate/setupProject.d.ts +4 -0
  44. package/dist/translate/shouldSetupProject.d.ts +3 -0
  45. package/dist/translate/translate.d.ts +1 -0
  46. package/dist/translate/translateMany.d.ts +1 -0
  47. package/dist/translate/uploadSourceFiles.d.ts +1 -0
  48. package/dist/translate/uploadTranslations.d.ts +1 -0
  49. package/dist/translate/utils/fetchWithTimeout.d.ts +1 -0
  50. package/dist/translate/utils/generateRequestHeaders.d.ts +2 -0
  51. package/dist/translate/utils/handleFetchError.d.ts +1 -0
  52. package/dist/translate/utils/validateResponse.d.ts +1 -0
  53. package/dist/types-dir/checkFileTranslations.d.ts +40 -0
  54. package/dist/types-dir/content.d.ts +49 -0
  55. package/dist/types-dir/downloadFile.d.ts +3 -0
  56. package/dist/types-dir/downloadFileBatch.d.ts +22 -0
  57. package/dist/types-dir/enqueueEntries.d.ts +21 -0
  58. package/dist/types-dir/enqueueFiles.d.ts +62 -0
  59. package/dist/types-dir/entry.d.ts +39 -0
  60. package/dist/types-dir/fetchTranslations.d.ts +11 -0
  61. package/dist/types-dir/file.d.ts +23 -0
  62. package/dist/types-dir/project.d.ts +7 -0
  63. package/dist/types-dir/translate.d.ts +34 -0
  64. package/dist/types-dir/translateMany.d.ts +5 -0
  65. package/dist/types-dir/translationStatus.d.ts +9 -0
  66. package/dist/types-dir/uploadFiles.d.ts +38 -0
  67. package/dist/types-dir/variables.d.ts +9 -0
  68. package/dist/utils/base64.d.ts +2 -0
  69. package/dist/utils/isVariable.d.ts +2 -0
  70. package/dist/utils/minify.d.ts +2 -0
  71. package/package.json +2 -2
@@ -0,0 +1,23 @@
1
+ import { Variable as VariableObject, VariableType } from '../types';
2
+ import { OldBranchType, OldGTProp, OldJsxChild, OldJsxChildren, OldJsxElement, OldVariableObject, OldVariableType } from './oldTypes.js';
3
+ import { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';
4
+ /**
5
+ * Convert request data from old format to new format
6
+ */
7
+ export declare function getNewJsxChild(child: OldJsxChild): JsxChild;
8
+ export declare function getNewJsxChildren(children: OldJsxChildren): JsxChildren;
9
+ export declare function getNewJsxElement(element: OldJsxElement): JsxElement;
10
+ export declare function getNewBranchType(branch: OldBranchType): 'b' | 'p';
11
+ export declare function getNewVariableType(variable: OldVariableType): VariableType;
12
+ export declare function getNewVariableObject(variable: OldVariableObject): VariableObject;
13
+ export declare function getNewGTProp(dataGT: OldGTProp): GTProp;
14
+ /**
15
+ * Convert response data from old format to new format
16
+ */
17
+ export declare function getOldJsxChild(child: JsxChild): OldJsxChild;
18
+ export declare function getOldJsxChildren(children: JsxChildren | OldJsxChildren): OldJsxChildren;
19
+ export declare function getOldJsxElement(element: JsxElement): OldJsxElement;
20
+ export declare function getOldBranchType(branch: 'b' | 'p'): OldBranchType;
21
+ export declare function getOldVariableType(variable: VariableType): OldVariableType;
22
+ export declare function getOldVariableObject(variable: VariableObject): OldVariableObject;
23
+ export declare function getOldGTProp(dataGT: GTProp, i: number): OldGTProp;
@@ -0,0 +1,23 @@
1
+ import { OldJsxChildren } from './oldTypes';
2
+ /**
3
+ * Calculates a unique hash for a given string using sha256.
4
+ *
5
+ * @param {string} string - The string to be hashed.
6
+ * @returns {string} - The resulting hash as a hexadecimal string.
7
+ */
8
+ export declare function oldHashString(string: string): string;
9
+ /**
10
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
11
+ *
12
+ * @param {any} childrenAsObjects - The children objects to be hashed.
13
+ * @param {string} context - The context for the children
14
+ * @param {string} id - The id for the JSX Children object
15
+ * @param {function} hashFunction custom hash function
16
+ * @returns {string} - The unique has of the children.
17
+ */
18
+ export declare function oldHashJsxChildren({ source, context, id, dataFormat, }: {
19
+ source: OldJsxChildren;
20
+ context?: string;
21
+ id?: string;
22
+ dataFormat: string;
23
+ }, hashFunction?: (string: string) => string): string;
@@ -0,0 +1,21 @@
1
+ export type OldBranchType = 'branch' | 'plural';
2
+ export type OldGTProp = {
3
+ id: number;
4
+ transformation?: OldBranchType;
5
+ branches?: Record<string, OldJsxChildren>;
6
+ };
7
+ export type OldJsxElement = {
8
+ type: string;
9
+ props: {
10
+ children?: OldJsxChildren;
11
+ 'data-_gt': OldGTProp;
12
+ };
13
+ };
14
+ export type OldVariableType = 'number' | 'variable' | 'datetime' | 'currency';
15
+ export type OldVariableObject = {
16
+ variable?: OldVariableType;
17
+ key: string;
18
+ id?: number;
19
+ };
20
+ export type OldJsxChild = OldJsxElement | OldVariableObject | string;
21
+ export type OldJsxChildren = OldJsxChild | OldJsxChild[];
@@ -0,0 +1,21 @@
1
+ import { JsxChild, JsxChildren } from '../types';
2
+ import { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes.js';
3
+ import { Variable as VariableObject } from '../types';
4
+ /**
5
+ * Checks if a JSX child is an old variable object format
6
+ * @param child - The JSX child to check
7
+ * @returns True if the child is an old variable object (has 'key' property)
8
+ */
9
+ export declare function isOldVariableObject(child: OldJsxChild | JsxChild): child is OldVariableObject;
10
+ /**
11
+ * Checks if a JSX child is a new variable object format
12
+ * @param child - The JSX child to check
13
+ * @returns True if the child is a new variable object (has 'k' property)
14
+ */
15
+ export declare function isNewVariableObject(child: OldJsxChild | JsxChild): child is VariableObject;
16
+ /**
17
+ * Checks if JSX children follow the old format
18
+ * @param children - The JSX children to check (can be string, array, or single child)
19
+ * @returns True if all children are in the old format
20
+ */
21
+ export declare function isOldJsxChildren(children: OldJsxChildren | JsxChildren): children is OldJsxChildren;
@@ -0,0 +1,8 @@
1
+ declare class IntlCache {
2
+ private cache;
3
+ constructor();
4
+ private _generateKey;
5
+ get<K extends keyof typeof Intl>(constructor: K, locales: string | string[], options?: {}): InstanceType<(typeof Intl)[K]>;
6
+ }
7
+ export declare const intlCache: IntlCache;
8
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { DataFormat, JsxChildren } from '../types';
2
+ /**
3
+ * Calculates a unique hash for a given string using sha256.
4
+ *
5
+ * First 16 characters of hash, hex encoded.
6
+ *
7
+ * @param {string} string - The string to be hashed.
8
+ * @returns {string} - The resulting hash as a hexadecimal string.
9
+ */
10
+ export declare function hashString(string: string): string;
11
+ /**
12
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
13
+ *
14
+ * @param {any} childrenAsObjects - The children objects to be hashed.
15
+ * @param {string} context - The context for the children
16
+ * @param {string} id - The id for the JSX Children object
17
+ * @param {string} dataFormat - The data format of the sources
18
+ * @param {function} hashFunction custom hash function
19
+ * @returns {string} - The unique has of the children.
20
+ */
21
+ export declare function hashSource({ source, context, id, dataFormat, }: {
22
+ source: JsxChildren | string;
23
+ context?: string;
24
+ id?: string;
25
+ dataFormat: DataFormat;
26
+ }, hashFunction?: (string: string) => string): string;
@@ -0,0 +1,4 @@
1
+ import { hashString } from './hashSource';
2
+ export default function hashTemplate(template: {
3
+ [key: string]: string;
4
+ }, hashFunction?: typeof hashString): string;
@@ -0,0 +1,5 @@
1
+ import { LocaleProperties } from './getLocaleProperties';
2
+ export type FullCustomMapping = Record<string, LocaleProperties>;
3
+ export type CustomMapping = Record<string, string | Partial<LocaleProperties>>;
4
+ export declare const getCustomProperty: (customMapping: CustomMapping, locale: string, property: keyof LocaleProperties) => string | undefined;
5
+ export declare const shouldUseCanonicalLocale: (locale: string, customMapping: CustomMapping) => boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const defaultEmoji = "\uD83C\uDF0D";
2
+ export declare const emojis: Record<string, string>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import { CustomMapping } from './customLocaleMapping';
2
+ export type LocaleProperties = {
3
+ code: string;
4
+ name: string;
5
+ nativeName: string;
6
+ languageCode: string;
7
+ languageName: string;
8
+ nativeLanguageName: string;
9
+ nameWithRegionCode: string;
10
+ nativeNameWithRegionCode: string;
11
+ regionCode: string;
12
+ regionName: string;
13
+ nativeRegionName: string;
14
+ scriptCode: string;
15
+ scriptName: string;
16
+ nativeScriptName: string;
17
+ maximizedCode: string;
18
+ maximizedName: string;
19
+ nativeMaximizedName: string;
20
+ minimizedCode: string;
21
+ minimizedName: string;
22
+ nativeMinimizedName: string;
23
+ emoji: string;
24
+ };
25
+ /**
26
+ * Creates a set of custom locale properties from a custom mapping.
27
+ *
28
+ * @param lArray - An array of locale codes to search for in the custom mapping.
29
+ * @param customMapping - Optional custom mapping of locale codes to names.
30
+ * @returns A partial set of locale properties, or undefined if no custom mapping is provided.
31
+ */
32
+ export declare function createCustomLocaleProperties(lArray: string[], customMapping?: CustomMapping): Partial<LocaleProperties> | undefined;
@@ -0,0 +1,9 @@
1
+ import { PluralType } from '../settings/plurals';
2
+ /**
3
+ * Given a number and a list of allowed plural forms, return the plural form that best fits the number.
4
+ *
5
+ * @param {number} n - The number to determine the plural form for.
6
+ * @param {locales[]} forms - The allowed plural forms.
7
+ * @returns {PluralType} The determined plural form, or an empty string if none fit.
8
+ */
9
+ export default function _getPluralForm(n: number, forms?: PluralType[], locales?: string[]): PluralType | '';
@@ -0,0 +1,7 @@
1
+ export type CustomRegionMapping = {
2
+ [region: string]: {
3
+ name?: string;
4
+ emoji?: string;
5
+ locale?: string;
6
+ };
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { CustomMapping } from './customLocaleMapping';
2
+ /**
3
+ * Resolves the alias locale for a given locale.
4
+ * @param locale - The locale to resolve the alias locale for
5
+ * @param customMapping - The custom mapping to use for resolving the alias locale
6
+ * @returns The alias locale
7
+ */
8
+ export declare function _resolveAliasLocale(locale: string, customMapping?: CustomMapping): string;
@@ -0,0 +1,10 @@
1
+ export declare const translationTimeoutError: (timeout: number) => string;
2
+ export declare const translationRequestFailedError: (error: string) => string;
3
+ export declare const apiError: (status: number, statusText: string, error: string) => string;
4
+ export declare const invalidAuthError = "GT Error: Invalid authentication.";
5
+ export declare const noTargetLocaleProvidedError: (functionName: string) => string;
6
+ export declare const noSourceLocaleProvidedError: (functionName: string) => string;
7
+ export declare const noProjectIdProvidedError: (functionName: string) => string;
8
+ export declare const noApiKeyProvidedError: (functionName: string) => string;
9
+ export declare const invalidLocaleError: (locale: string) => string;
10
+ export declare const invalidLocalesError: (locales: string[]) => string;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Comprehensive logging system for the General Translation library
3
+ * Provides structured logging with multiple levels and configurable output
4
+ */
5
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off';
6
+ export interface LogEntry {
7
+ level: LogLevel;
8
+ message: string;
9
+ timestamp: Date;
10
+ context?: string;
11
+ metadata?: Record<string, any>;
12
+ }
13
+ export interface LoggerConfig {
14
+ /** Minimum log level to output */
15
+ level: LogLevel;
16
+ /** Whether to include timestamps in log output */
17
+ includeTimestamp: boolean;
18
+ /** Whether to include context information */
19
+ includeContext: boolean;
20
+ /** Custom prefix for all log messages */
21
+ prefix?: string;
22
+ /** Whether to output to console (default: true) */
23
+ enableConsole: boolean;
24
+ /** Custom log handlers */
25
+ handlers?: LogHandler[];
26
+ }
27
+ export interface LogHandler {
28
+ handle(entry: LogEntry): void;
29
+ }
30
+ /**
31
+ * Console log handler that outputs formatted messages to console
32
+ */
33
+ export declare class ConsoleLogHandler implements LogHandler {
34
+ private config;
35
+ constructor(config: LoggerConfig);
36
+ handle(entry: LogEntry): void;
37
+ }
38
+ /**
39
+ * Main Logger class providing structured logging capabilities
40
+ */
41
+ export declare class Logger {
42
+ private config;
43
+ private handlers;
44
+ constructor(config?: Partial<LoggerConfig>);
45
+ /**
46
+ * Add a custom log handler
47
+ */
48
+ addHandler(handler: LogHandler): void;
49
+ /**
50
+ * Remove a log handler
51
+ */
52
+ removeHandler(handler: LogHandler): void;
53
+ /**
54
+ * Update logger configuration
55
+ */
56
+ configure(config: Partial<LoggerConfig>): void;
57
+ /**
58
+ * Check if a log level should be output based on current configuration
59
+ */
60
+ private shouldLog;
61
+ /**
62
+ * Internal logging method that creates log entries and passes them to handlers
63
+ */
64
+ private log;
65
+ /**
66
+ * Log a debug message
67
+ * Used for detailed diagnostic information, typically of interest only when diagnosing problems
68
+ */
69
+ debug(message: string, context?: string, metadata?: Record<string, any>): void;
70
+ /**
71
+ * Log an info message
72
+ * Used for general information about application operation
73
+ */
74
+ info(message: string, context?: string, metadata?: Record<string, any>): void;
75
+ /**
76
+ * Log a warning message
77
+ * Used for potentially problematic situations that don't prevent operation
78
+ */
79
+ warn(message: string, context?: string, metadata?: Record<string, any>): void;
80
+ /**
81
+ * Log an error message
82
+ * Used for error events that might still allow the application to continue
83
+ */
84
+ error(message: string, context?: string, metadata?: Record<string, any>): void;
85
+ /**
86
+ * Create a child logger with a specific context
87
+ */
88
+ child(context: string): ContextLogger;
89
+ /**
90
+ * Get current logger configuration
91
+ */
92
+ getConfig(): LoggerConfig;
93
+ }
94
+ /**
95
+ * Context logger that automatically includes context information
96
+ */
97
+ export declare class ContextLogger {
98
+ private logger;
99
+ private context;
100
+ constructor(logger: Logger, context: string);
101
+ debug(message: string, metadata?: Record<string, any>): void;
102
+ info(message: string, metadata?: Record<string, any>): void;
103
+ warn(message: string, metadata?: Record<string, any>): void;
104
+ error(message: string, metadata?: Record<string, any>): void;
105
+ child(childContext: string): ContextLogger;
106
+ }
107
+ export declare const defaultLogger: Logger;
108
+ export declare const debug: (message: string, context?: string, metadata?: Record<string, any>) => void;
109
+ export declare const info: (message: string, context?: string, metadata?: Record<string, any>) => void;
110
+ export declare const warn: (message: string, context?: string, metadata?: Record<string, any>) => void;
111
+ export declare const error: (message: string, context?: string, metadata?: Record<string, any>) => void;
112
+ export declare const fetchLogger: ContextLogger;
113
+ export declare const validationLogger: ContextLogger;
114
+ export declare const formattingLogger: ContextLogger;
115
+ export declare const localeLogger: ContextLogger;
116
+ export declare const gtInstanceLogger: ContextLogger;
117
+ export { Logger as GTLogger };
@@ -0,0 +1,2 @@
1
+ export declare const formatI18nextWarning = "Warning: formatI18next is not currently supported but will be implemented in a future version. Use _formatMessage for current ICU message format support.";
2
+ export declare const formatJsxWarning = "Warning: formatJsx is not currently supported but will be implemented in a future version. Use _formatMessage for current ICU message format support.";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const pluralForms: readonly ["singular", "plural", "dual", "zero", "one", "two", "few", "many", "other"];
2
+ export type PluralType = (typeof pluralForms)[number];
3
+ export declare function isAcceptedPluralForm(form: string): form is PluralType;
@@ -0,0 +1,2 @@
1
+ export declare const libraryDefaultLocale: "en";
2
+ export declare const maxTimeout = 60000;
@@ -0,0 +1,9 @@
1
+ export declare const defaultCacheUrl: "https://cdn.gtx.dev";
2
+ export declare const defaultBaseUrl: "https://api2.gtx.dev";
3
+ export declare const defaultRuntimeApiUrl: "https://runtime2.gtx.dev";
4
+ export declare const translateBatchUrl: "/v1/translate/batch";
5
+ export declare const translateJsxUrl: "/v1/translate/react";
6
+ export declare const translateContentUrl: "/v1/translate/content";
7
+ export declare const translateIcuUrl: "/v1/translate/icu";
8
+ export declare const updateProjectTranslationsUrl: "/v1/project/translations/update";
9
+ export declare const getProjectLocalesUrl: "/v1/project/locales";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export type SetupJobStatus = 'queued' | 'processing' | 'completed' | 'failed';
2
+ export type CheckSetupStatusResult = {
3
+ jobId: string;
4
+ status: SetupJobStatus;
5
+ error?: {
6
+ message: string;
7
+ };
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export type EnqueueOptions = {
2
+ sourceLocale: string;
3
+ targetLocales: string[];
4
+ publish?: boolean;
5
+ requireApproval?: boolean;
6
+ modelProvider?: string;
7
+ force?: boolean;
8
+ timeout?: number;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export type SetupProjectResult = {
2
+ setupJobId: string;
3
+ status: 'queued';
4
+ };
@@ -0,0 +1,3 @@
1
+ export type ShouldSetupProjectResult = {
2
+ shouldSetupProject: boolean;
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { TranslationRequestConfig } from '../../types';
2
+ export default function generateRequestHeaders(config: TranslationRequestConfig, excludeContentType?: boolean): Record<string, string>;
@@ -0,0 +1 @@
1
+ export default function handleFetchError(error: unknown, timeout: number): never;
@@ -0,0 +1 @@
1
+ export default function validateResponse(response: Response): Promise<void>;
@@ -0,0 +1,40 @@
1
+ import { CompletedFileTranslationData } from './file';
2
+ export type FileTranslationQuery = {
3
+ versionId: string;
4
+ fileName?: string;
5
+ fileId?: string;
6
+ locale: string;
7
+ };
8
+ export type CheckFileTranslationsOptions = {
9
+ timeout?: number;
10
+ };
11
+ export type CheckFileTranslationsResult = {
12
+ translations: CompletedFileTranslationData[];
13
+ };
14
+ export type FileQuery = {
15
+ fileId: string;
16
+ versionId?: string;
17
+ };
18
+ export type FileQueryResult = {
19
+ sourceFile: {
20
+ id: string;
21
+ fileId: string;
22
+ versionId: string;
23
+ sourceLocale: string;
24
+ fileName: string;
25
+ fileFormat: string;
26
+ dataFormat: string | null;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ approvalRequiredAt: string | null;
30
+ locales: string[];
31
+ };
32
+ translations: {
33
+ locale: string;
34
+ completedAt: string | null;
35
+ approvedAt: string | null;
36
+ publishedAt: string | null;
37
+ createdAt: string | null;
38
+ updatedAt: string | null;
39
+ }[];
40
+ };
@@ -0,0 +1,49 @@
1
+ import { Variable } from './variables';
2
+ /**
3
+ * Map of data-_gt properties to their corresponding React props
4
+ */
5
+ export declare const HTML_CONTENT_PROPS: {
6
+ readonly pl: "placeholder";
7
+ readonly ti: "title";
8
+ readonly alt: "alt";
9
+ readonly arl: "aria-label";
10
+ readonly arb: "aria-labelledby";
11
+ readonly ard: "aria-describedby";
12
+ };
13
+ export type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>;
14
+ export type HtmlContentPropValuesRecord = Partial<Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>>;
15
+ /**
16
+ * GTProp is an internal property used to contain data for translating and rendering elements.
17
+ * note, transformations are only read on the server side if they are 'plural' or 'branch'
18
+ */
19
+ export type GTProp = {
20
+ b?: Record<string, JsxChildren>;
21
+ t?: 'p' | 'b';
22
+ } & HtmlContentPropKeysRecord;
23
+ export type JsxElement = {
24
+ t?: string;
25
+ i?: number;
26
+ d?: GTProp;
27
+ c?: JsxChildren;
28
+ };
29
+ export type JsxChild = string | JsxElement | Variable;
30
+ /**
31
+ * The format of the content
32
+ */
33
+ export type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';
34
+ /**
35
+ * A content type representing JSX, ICU, and I18next messages
36
+ */
37
+ export type Content = JsxChildren | IcuMessage | I18nextMessage;
38
+ /**
39
+ * A content type representing JSX elements
40
+ */
41
+ export type JsxChildren = JsxChild | JsxChild[];
42
+ /**
43
+ * A content type representing ICU messages
44
+ */
45
+ export type IcuMessage = string;
46
+ /**
47
+ * A content type representing I18next messages
48
+ */
49
+ export type I18nextMessage = string;
@@ -0,0 +1,3 @@
1
+ export type DownloadFileOptions = {
2
+ timeout?: number;
3
+ };
@@ -0,0 +1,22 @@
1
+ export type DownloadFileBatchOptions = {
2
+ timeout?: number;
3
+ };
4
+ export type BatchDownloadResult = {
5
+ translationId: string;
6
+ fileName?: string;
7
+ success: boolean;
8
+ content?: string;
9
+ contentType?: string;
10
+ error?: string;
11
+ };
12
+ type File = {
13
+ id: string;
14
+ fileName: string;
15
+ data: string;
16
+ metadata: any;
17
+ };
18
+ export type DownloadFileBatchResult = {
19
+ files: File[];
20
+ count: number;
21
+ };
22
+ export {};
@@ -0,0 +1,21 @@
1
+ import { DataFormat } from './content';
2
+ export type { Updates } from './enqueueFiles';
3
+ export type EnqueueEntriesOptions = {
4
+ timeout?: number;
5
+ sourceLocale?: string;
6
+ targetLocales?: string[];
7
+ dataFormat?: DataFormat;
8
+ version?: string;
9
+ description?: string;
10
+ requireApproval?: boolean;
11
+ modelProvider?: string;
12
+ };
13
+ export type EnqueueEntriesResult = {
14
+ versionId: string;
15
+ locales: string[];
16
+ message: string;
17
+ projectSettings: {
18
+ cdnEnabled: boolean;
19
+ requireApproval: boolean;
20
+ };
21
+ };
@@ -0,0 +1,62 @@
1
+ import { DataFormat, JsxChildren } from './content';
2
+ import { CompletedFileTranslationData, FileFormat } from './file';
3
+ export type Updates = ({
4
+ metadata: Record<string, any>;
5
+ } & ({
6
+ dataFormat: 'JSX';
7
+ source: JsxChildren;
8
+ } | {
9
+ dataFormat: 'ICU';
10
+ source: string;
11
+ } | {
12
+ dataFormat: 'I18NEXT';
13
+ source: string;
14
+ }))[];
15
+ /**
16
+ * File object structure for enqueueing files
17
+ * @param content - Content of the file
18
+ * @param fileName - Unique identifier for the file (such as the file path + file name)
19
+ * @param fileFormat - The format of the file (JSON, MDX, MD, etc.)
20
+ * @param formatMetadata - Optional metadata for the file, specific to the format of the file
21
+ * @param dataFormat - Optional format of the data within the file
22
+ */
23
+ export type FileToTranslate = {
24
+ content: string;
25
+ fileName: string;
26
+ fileFormat: FileFormat;
27
+ formatMetadata?: Record<string, any>;
28
+ dataFormat?: DataFormat;
29
+ };
30
+ /**
31
+ * Options for enqueueing files
32
+ * @param publish - Whether to publish the files
33
+ * @param requireApproval - Whether to require approval for the files
34
+ * @param description - Optional description for the project
35
+ * @param sourceLocale - The project's source locale
36
+ * @param targetLocales - The locales to translate the files to
37
+ * @param version - Optional custom version ID to specify
38
+ * @param timeout - Optional timeout for the request
39
+ * @param modelProvider - Optional model provider to use
40
+ */
41
+ export type EnqueueFilesOptions = {
42
+ publish?: boolean;
43
+ requireApproval?: boolean;
44
+ description?: string;
45
+ sourceLocale?: string;
46
+ targetLocales: string[];
47
+ version?: string;
48
+ _versionId?: string;
49
+ timeout?: number;
50
+ modelProvider?: string;
51
+ force?: boolean;
52
+ };
53
+ export type RequiredEnqueueFilesOptions = EnqueueFilesOptions & Required<Pick<EnqueueFilesOptions, 'sourceLocale'>>;
54
+ export type EnqueueFilesResult = {
55
+ translations: CompletedFileTranslationData[];
56
+ data: Record<string, {
57
+ fileName: string;
58
+ versionId: string;
59
+ }>;
60
+ locales: string[];
61
+ message: string;
62
+ };
@@ -0,0 +1,39 @@
1
+ import { Content, DataFormat } from '../types';
2
+ /**
3
+ * ActionType is the type of action to perform on the request.
4
+ *
5
+ * @param standard - The standard action type (standard model).
6
+ * @param fast - The fast action type (mini model).
7
+ * @param string - Other model
8
+ */
9
+ export type ActionType = 'standard' | 'fast' | string;
10
+ /**
11
+ * EntryMetadata is the metadata for a GTRequest.
12
+ *
13
+ * @param context - The context of the request.
14
+ * @param id - The id of the request.
15
+ * @param hash - The hash of the request.
16
+ */
17
+ export type EntryMetadata = {
18
+ context?: string;
19
+ id?: string;
20
+ hash?: string;
21
+ dataFormat?: DataFormat;
22
+ sourceLocale?: string;
23
+ actionType?: ActionType;
24
+ timeout?: number;
25
+ regionCode?: string;
26
+ scriptCode?: string;
27
+ };
28
+ /**
29
+ * GTRequest is a translation request object for {@link JsxChildren} | {@link IcuMessage} | {@link I18nextMessage}
30
+ *
31
+ * @param source - The source content to translate.
32
+ * @param targetLocale - The target locale to translate to.
33
+ * @param metadata - The metadata for the request.
34
+ */
35
+ export type Entry = {
36
+ source: Content;
37
+ targetLocale?: string;
38
+ metadata?: EntryMetadata;
39
+ };
@@ -0,0 +1,11 @@
1
+ export type FetchTranslationsOptions = {
2
+ timeout?: number;
3
+ };
4
+ export type RetrievedTranslation = {
5
+ locale: string;
6
+ translation: any;
7
+ };
8
+ export type RetrievedTranslations = RetrievedTranslation[];
9
+ export type FetchTranslationsResult = {
10
+ translations: RetrievedTranslations;
11
+ };
@@ -0,0 +1,23 @@
1
+ import { Entry } from './entry';
2
+ export type FileFormat = 'GTJSON' | 'JSON' | 'YAML' | 'MDX' | 'MD' | 'TS' | 'JS' | 'HTML';
3
+ export type FileMetadata = {
4
+ filePath: string;
5
+ fileFormat: FileFormat;
6
+ context?: string;
7
+ sourceLocale?: string;
8
+ hash?: string;
9
+ };
10
+ export type File = {
11
+ source: Entry[] | string;
12
+ fileMetadata: FileMetadata;
13
+ };
14
+ export type CompletedFileTranslationData = {
15
+ locale: string;
16
+ metadata: any;
17
+ fileId: string;
18
+ fileName: string;
19
+ versionId: string;
20
+ id: string;
21
+ isReady: boolean;
22
+ downloadUrl: string;
23
+ };
@@ -0,0 +1,7 @@
1
+ export type ProjectData = {
2
+ id: string;
3
+ name: string;
4
+ orgId: string;
5
+ defaultLocale: string;
6
+ currentLocales: string[];
7
+ };
@@ -0,0 +1,34 @@
1
+ import { I18nextMessage, IcuMessage, JsxChildren } from './content';
2
+ /**
3
+ * TranslationResultReference is used to store the reference for a translation result.
4
+ */
5
+ export type TranslationResultReference = {
6
+ id?: string;
7
+ hash: string;
8
+ };
9
+ /**
10
+ * TypedResult is a union type that represents the different types of translations that can be returned.
11
+ */
12
+ export type TypedResult = {
13
+ translation: JsxChildren;
14
+ dataFormat: 'JSX';
15
+ } | {
16
+ translation: I18nextMessage | IcuMessage;
17
+ dataFormat: 'ICU' | 'I18NEXT';
18
+ };
19
+ /**
20
+ * RequestError is a type that represents an error that occurred during a translation request.
21
+ */
22
+ export type TranslationError = {
23
+ error: string;
24
+ code: number;
25
+ reference?: TranslationResultReference;
26
+ };
27
+ /**
28
+ * RequestSuccess is a type that represents a successful translation request.
29
+ */
30
+ export type RequestSuccess = TypedResult & {
31
+ locale: string;
32
+ reference: TranslationResultReference;
33
+ };
34
+ export type TranslationResult = RequestSuccess | TranslationError;
@@ -0,0 +1,5 @@
1
+ import { TranslationResult } from './translate';
2
+ /**
3
+ * BatchTranslationResult is the result of a batch translation request.
4
+ */
5
+ export type TranslateManyResult = Array<TranslationResult>;
@@ -0,0 +1,9 @@
1
+ export type TranslationStatusResult = {
2
+ count: number;
3
+ availableLocales: string[];
4
+ locales: string[];
5
+ localesWaitingForApproval: any[];
6
+ };
7
+ export type CheckTranslationStatusOptions = {
8
+ timeout?: number;
9
+ };
@@ -0,0 +1,38 @@
1
+ import { DataFormat } from './content';
2
+ import { FileFormat } from './file';
3
+ export type FileUpload = {
4
+ content: string;
5
+ fileName: string;
6
+ fileFormat: FileFormat;
7
+ dataFormat?: DataFormat;
8
+ locale: string;
9
+ versionId?: string;
10
+ fileId?: string;
11
+ };
12
+ export type FileUploadRef = {
13
+ fileId: string;
14
+ versionId: string;
15
+ fileName: string;
16
+ fileFormat: FileFormat;
17
+ dataFormat?: DataFormat;
18
+ locale?: string;
19
+ };
20
+ export type UploadData = {
21
+ data: {
22
+ source: FileUpload;
23
+ translations: FileUpload[];
24
+ }[];
25
+ sourceLocale: string;
26
+ modelProvider?: string;
27
+ };
28
+ export type UploadFilesOptions = {
29
+ sourceLocale: string;
30
+ modelProvider?: string;
31
+ timeout?: number;
32
+ };
33
+ export type UploadFilesResponse = {
34
+ uploadedFiles: FileUploadRef[];
35
+ count: number;
36
+ message: string;
37
+ };
38
+ export type RequiredUploadFilesOptions = UploadFilesOptions & Required<Pick<UploadFilesOptions, 'sourceLocale'>>;
@@ -0,0 +1,9 @@
1
+ export type VariableType = 'v' | 'n' | 'd' | 'c';
2
+ /**
3
+ * Variables are used to store the variable name and type.
4
+ */
5
+ export type Variable = {
6
+ k: string;
7
+ i?: number;
8
+ v?: VariableType;
9
+ };
@@ -0,0 +1,2 @@
1
+ export declare function encode(data: string): string;
2
+ export declare function decode(base64: string): string;
@@ -0,0 +1,2 @@
1
+ import { Variable } from '../types';
2
+ export default function isVariable(obj: unknown): obj is Variable;
@@ -0,0 +1,2 @@
1
+ import { VariableTransformationSuffix, VariableType } from '../types';
2
+ export declare function minifyVariableType(variableType: VariableTransformationSuffix): VariableType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "7.6.4-alpha.1",
3
+ "version": "7.6.4-alpha.2",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.cjs.min.cjs",
6
6
  "module": "dist/index.esm.min.mjs",
@@ -100,7 +100,7 @@
100
100
  },
101
101
  "scripts": {
102
102
  "build:release": "pnpm run build:clean",
103
- "build:clean": "rm -rf dist; pnpm run build",
103
+ "build:clean": "rm -rf dist && rm tsconfig.tsbuildinfo && pnpm run build",
104
104
  "build": "rollup -c",
105
105
  "lint": "eslint \"src/**/*.{js,ts}\" \"./**/__tests__/**/*.{js,ts}\"",
106
106
  "lint:fix": "eslint \"src/**/*.{js,ts}\" \"./**/__tests__/**/*.{js,ts}\" --fix",