generaltranslation 9.1.11 → 9.1.13
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 +24 -0
- package/dist/{derive-DVQrJM6B.mjs → derive-C3nzgrzy.mjs} +4 -3
- package/dist/derive-C3nzgrzy.mjs.map +1 -0
- package/dist/{derive-DLrMiUyi.cjs → derive-bDBg-KyF.cjs} +4 -3
- package/dist/derive-bDBg-KyF.cjs.map +1 -0
- package/dist/{file-CAUqDla-.mjs → file-Cgk1Xk9d.mjs} +3 -3
- package/dist/file-Cgk1Xk9d.mjs.map +1 -0
- package/dist/{file-BXlTzYxX.cjs → file-D7gKavRj.cjs} +3 -3
- package/dist/file-D7gKavRj.cjs.map +1 -0
- package/dist/id.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/internal.cjs +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.mts +1 -1
- package/dist/internal.mjs +1 -1
- package/dist/runtime.d.cts +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/{types-BJHO0ZvE.d.mts → types-C8sSACgY.d.mts} +2 -2
- package/dist/{types-DifJWFFk.d.cts → types-DO3dc8ST.d.cts} +2 -2
- package/dist/types-dir/api/file.d.ts +1 -1
- package/dist/types-dir/api/file.js +2 -2
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +1 -1
- package/dist/utils/isSupportedFileFormatTransform.js +3 -2
- package/package.json +2 -2
- package/dist/derive-DLrMiUyi.cjs.map +0 -1
- package/dist/derive-DVQrJM6B.mjs.map +0 -1
- package/dist/file-BXlTzYxX.cjs.map +0 -1
- package/dist/file-CAUqDla-.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# generaltranslation
|
|
2
2
|
|
|
3
|
+
## 9.1.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2228](https://github.com/generaltranslation/gt/pull/2228) [`de66e5f`](https://github.com/generaltranslation/gt/commit/de66e5f41e05f22d51661faacae78b4fb3d86035) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Add Android `strings.xml` support to the CLI. Configure an `androidStrings` entry under `files` in `gt.config.json` to upload Android string resources and download the translated per-locale files.
|
|
8
|
+
|
|
9
|
+
Translations are written to the resource directory the platform expects, so `fr-CA` becomes `values-fr-rCA` and `zh-Hans` becomes `values-b+zh+Hans`. Android reads the locale out of the directory name and fails the build on one it cannot parse.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`de66e5f`](https://github.com/generaltranslation/gt/commit/de66e5f41e05f22d51661faacae78b4fb3d86035)]:
|
|
12
|
+
- @generaltranslation/api@0.0.6
|
|
13
|
+
|
|
14
|
+
## 9.1.12
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#2226](https://github.com/generaltranslation/gt/pull/2226) [`44aabc7`](https://github.com/generaltranslation/gt/commit/44aabc734d99fab4fcab7faedc84d20b5772bde3) Thanks [@eoinest](https://github.com/eoinest)! - Rename the `.strings` and `.stringsdict` file formats. The API format names become `DOT_STRINGS` and `DOT_STRINGSDICT`, and the `gt.config.json` keys under `files` become `dotStrings` and `dotStringsdict`.
|
|
19
|
+
|
|
20
|
+
**This is a breaking configuration change.** A `gt.config.json` that still uses `files.strings` or `files.stringsdict` will silently stop matching those files, because the old keys are no longer recognised file types. Rename them to `files.dotStrings` and `files.dotStringsdict`. The file extensions on disk are unchanged, and translated output is still written as `.strings` and `.stringsdict`.
|
|
21
|
+
|
|
22
|
+
The old names identified a vendor rather than a file. Apple ships four string formats — `.strings`, `.stringsdict`, `.xcstrings` and `.plist` — so `APPLE_STRINGS` never said which one it meant. The new names identify the extension itself, the way developers say it out loud.
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`44aabc7`](https://github.com/generaltranslation/gt/commit/44aabc734d99fab4fcab7faedc84d20b5772bde3)]:
|
|
25
|
+
- @generaltranslation/api@0.0.5
|
|
26
|
+
|
|
3
27
|
## 9.1.11
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -15,8 +15,9 @@ const SUPPORTED_TRANSFORMATIONS = {
|
|
|
15
15
|
TWILIO_CONTENT_JSON: ["TWILIO_CONTENT_JSON"],
|
|
16
16
|
LOTTIE: ["LOTTIE"],
|
|
17
17
|
SVG: ["SVG"],
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
DOT_STRINGS: ["DOT_STRINGS"],
|
|
19
|
+
DOT_STRINGSDICT: ["DOT_STRINGSDICT"],
|
|
20
|
+
ANDROID_STRINGS: ["ANDROID_STRINGS"]
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* This function checks if a file format transformation is supported during translation
|
|
@@ -220,4 +221,4 @@ function derive(content) {
|
|
|
220
221
|
//#endregion
|
|
221
222
|
export { isGTUnindexedSelectElement as a, decode as c, isGTIndexedSelectElement as i, encode as l, declareVar as n, VAR_IDENTIFIER as o, decodeVars as r, traverseIcu as s, derive as t, isSupportedFileFormatTransform as u };
|
|
222
223
|
|
|
223
|
-
//# sourceMappingURL=derive-
|
|
224
|
+
//# sourceMappingURL=derive-C3nzgrzy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-C3nzgrzy.mjs","names":[],"sources":["../src/utils/isSupportedFileFormatTransform.ts","../src/utils/base64.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts"],"sourcesContent":["import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n LOTTIE: ['LOTTIE'],\n SVG: ['SVG'],\n DOT_STRINGS: ['DOT_STRINGS'],\n DOT_STRINGSDICT: ['DOT_STRINGSDICT'],\n ANDROID_STRINGS: ['ANDROID_STRINGS'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n","import {\n parse,\n TYPE,\n type MessageFormatElement,\n type ParserOptions,\n} from '@generaltranslation/icu';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport { TYPE, type MessageFormatElement } from '@generaltranslation/icu';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n"],"mappings":";;AAEA,MAAM,4BAA4B;CAChC,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,OAAO;CACd,IAAI,CAAC,KAAK;CAEV,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,qBAAqB,CAAC,sBAAsB;CAC5C,QAAQ,CAAC,SAAS;CAClB,KAAK,CAAC,MAAM;CACZ,aAAa,CAAC,cAAc;CAC5B,iBAAiB,CAAC,kBAAkB;CACpC,iBAAiB,CAAC,kBAAkB;CACrC;;;;;;;AAQD,SAAgB,+BACd,MACA,IACS;AAET,QAD4C,0BAA0B,O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
|
|
21
22
|
/**
|
|
22
23
|
* This function checks if a file format transformation is supported during translation
|
|
@@ -279,4 +280,4 @@ Object.defineProperty(exports, "traverseIcu", {
|
|
|
279
280
|
}
|
|
280
281
|
});
|
|
281
282
|
|
|
282
|
-
//# sourceMappingURL=derive-
|
|
283
|
+
//# sourceMappingURL=derive-bDBg-KyF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-bDBg-KyF.cjs","names":["TYPE","TYPE"],"sources":["../src/utils/isSupportedFileFormatTransform.ts","../src/utils/base64.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts"],"sourcesContent":["import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n LOTTIE: ['LOTTIE'],\n SVG: ['SVG'],\n DOT_STRINGS: ['DOT_STRINGS'],\n DOT_STRINGSDICT: ['DOT_STRINGSDICT'],\n ANDROID_STRINGS: ['ANDROID_STRINGS'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n","import {\n parse,\n TYPE,\n type MessageFormatElement,\n type ParserOptions,\n} from '@generaltranslation/icu';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport { TYPE, type MessageFormatElement } from '@generaltranslation/icu';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n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;;;;;;ACfT,SAAgB,WACd,UACA,SACQ;CAGR,MAAM,kBAAkB,WADE,YAAY,OAAO,YAAY,GAAG,CACR,CAAC;CAGrD,IAAI,cAAc;AAClB,KAAI,SAAS,MAEX,eAAc,IAAI,oBAAoB,IADhB,YAAY,QAAQ,MACa,CAAC;AAI1D,QAAO,IAAI,eAAe,WAAW,kBAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACfrE,SAAgB,OACd,SACG;AACH,QAAO"}
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the
|
|
5
5
|
* bytes reach the API unaltered.
|
|
6
6
|
*
|
|
7
|
-
* LOTTIE qualifies because it is a zip bundle.
|
|
7
|
+
* LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because
|
|
8
8
|
* older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the
|
|
9
9
|
* byte order mark, and a UTF-8 round trip anywhere in between replaces those
|
|
10
10
|
* bytes with U+FFFD.
|
|
11
11
|
*/
|
|
12
|
-
const BINARY_FILE_FORMATS = new Set(["LOTTIE", "
|
|
12
|
+
const BINARY_FILE_FORMATS = new Set(["LOTTIE", "DOT_STRINGS"]);
|
|
13
13
|
/**
|
|
14
14
|
* Whether a file format's content is carried as base64 end-to-end rather than
|
|
15
15
|
* as a UTF-8 text string.
|
|
@@ -20,4 +20,4 @@ function isBinaryFileFormat(fileFormat) {
|
|
|
20
20
|
//#endregion
|
|
21
21
|
export { isBinaryFileFormat as n, BINARY_FILE_FORMATS as t };
|
|
22
22
|
|
|
23
|
-
//# sourceMappingURL=file-
|
|
23
|
+
//# sourceMappingURL=file-Cgk1Xk9d.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-Cgk1Xk9d.mjs","names":[],"sources":["../src/types-dir/api/file.ts"],"sourcesContent":["import type { DataFormat } from '@generaltranslation/format/types';\nimport { Updates } from './enqueueFiles';\nimport type { JsonObject } from './json';\n\nexport type FileFormat = import('@generaltranslation/api').FileFormat;\n\n/**\n * File formats whose content travels through the pipeline already\n * base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the\n * bytes reach the API unaltered.\n *\n * LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because\n * older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the\n * byte order mark, and a UTF-8 round trip anywhere in between replaces those\n * bytes with U+FFFD.\n */\nexport const BINARY_FILE_FORMATS: ReadonlySet<FileFormat> = new Set<FileFormat>(\n ['LOTTIE', 'DOT_STRINGS']\n);\n\n/**\n * Whether a file format's content is carried as base64 end-to-end rather than\n * as a UTF-8 text string.\n */\nexport function isBinaryFileFormat(fileFormat: FileFormat): boolean {\n return BINARY_FILE_FORMATS.has(fileFormat);\n}\n\n/**\n * Metadata for files or entries.\n */\nexport type FormatMetadata = JsonObject | Updates[number]['metadata'];\n\n/**\n * File object structure for uploading files.\n * @see {@link FileReferenceOptionalBranchId}\n * @property {string} content - Content of the file.\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {FormatMetadata} [formatMetadata] - Optional metadata for the file, specific to the format of the file\n * @property {string} [incomingBranchId] - The ID of the incoming branch of the file.\n * @property {string} [checkedOutBranchId] - The ID of the checked-out branch of the file.\n */\nexport type FileToUpload = Omit<FileReference, 'branchId'> & {\n content: string;\n locale: string;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n formatMetadata?: FormatMetadata;\n branchId?: string;\n incomingBranchId?: string;\n checkedOutBranchId?: string;\n};\n\n/**\n * File object structure for referencing files.\n * @property {string} fileId - The ID of the file.\n * @property {string} versionId - The ID of the version of the file\n * @property {string} branchId - The ID of the branch of the file\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {string} fileName - The name of the file.\n * @property {FileFormat} fileFormat - The format of the file (JSON, MDX, MD, etc.).\n * @property {DataFormat} [dataFormat] - Optional format of the data within the file.\n */\nexport type FileReference = {\n fileId: string;\n versionId: string;\n branchId: string;\n fileName: string;\n fileFormat: FileFormat;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n\n/**\n * File reference object structure for referencing files.\n * @see {@link FileReference}\n * @property {string} [branchId] - The ID of the branch of the file\n */\nexport type FileReferenceIds = Omit<\n FileReference,\n 'branchId' | 'fileName' | 'fileFormat' | 'dataFormat'\n> & {\n branchId?: string;\n fileName?: string;\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,sBAA+C,IAAI,IAC9D,CAAC,UAAU,cAAc,CAC1B;;;;;AAMD,SAAgB,mBAAmB,YAAiC;AAClE,QAAO,oBAAoB,IAAI,WAAW"}
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the
|
|
5
5
|
* bytes reach the API unaltered.
|
|
6
6
|
*
|
|
7
|
-
* LOTTIE qualifies because it is a zip bundle.
|
|
7
|
+
* LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because
|
|
8
8
|
* older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the
|
|
9
9
|
* byte order mark, and a UTF-8 round trip anywhere in between replaces those
|
|
10
10
|
* bytes with U+FFFD.
|
|
11
11
|
*/
|
|
12
|
-
const BINARY_FILE_FORMATS = new Set(["LOTTIE", "
|
|
12
|
+
const BINARY_FILE_FORMATS = new Set(["LOTTIE", "DOT_STRINGS"]);
|
|
13
13
|
/**
|
|
14
14
|
* Whether a file format's content is carried as base64 end-to-end rather than
|
|
15
15
|
* as a UTF-8 text string.
|
|
@@ -31,4 +31,4 @@ Object.defineProperty(exports, "isBinaryFileFormat", {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
//# sourceMappingURL=file-
|
|
34
|
+
//# sourceMappingURL=file-D7gKavRj.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-D7gKavRj.cjs","names":[],"sources":["../src/types-dir/api/file.ts"],"sourcesContent":["import type { DataFormat } from '@generaltranslation/format/types';\nimport { Updates } from './enqueueFiles';\nimport type { JsonObject } from './json';\n\nexport type FileFormat = import('@generaltranslation/api').FileFormat;\n\n/**\n * File formats whose content travels through the pipeline already\n * base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the\n * bytes reach the API unaltered.\n *\n * LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because\n * older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the\n * byte order mark, and a UTF-8 round trip anywhere in between replaces those\n * bytes with U+FFFD.\n */\nexport const BINARY_FILE_FORMATS: ReadonlySet<FileFormat> = new Set<FileFormat>(\n ['LOTTIE', 'DOT_STRINGS']\n);\n\n/**\n * Whether a file format's content is carried as base64 end-to-end rather than\n * as a UTF-8 text string.\n */\nexport function isBinaryFileFormat(fileFormat: FileFormat): boolean {\n return BINARY_FILE_FORMATS.has(fileFormat);\n}\n\n/**\n * Metadata for files or entries.\n */\nexport type FormatMetadata = JsonObject | Updates[number]['metadata'];\n\n/**\n * File object structure for uploading files.\n * @see {@link FileReferenceOptionalBranchId}\n * @property {string} content - Content of the file.\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {FormatMetadata} [formatMetadata] - Optional metadata for the file, specific to the format of the file\n * @property {string} [incomingBranchId] - The ID of the incoming branch of the file.\n * @property {string} [checkedOutBranchId] - The ID of the checked-out branch of the file.\n */\nexport type FileToUpload = Omit<FileReference, 'branchId'> & {\n content: string;\n locale: string;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n formatMetadata?: FormatMetadata;\n branchId?: string;\n incomingBranchId?: string;\n checkedOutBranchId?: string;\n};\n\n/**\n * File object structure for referencing files.\n * @property {string} fileId - The ID of the file.\n * @property {string} versionId - The ID of the version of the file\n * @property {string} branchId - The ID of the branch of the file\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {string} fileName - The name of the file.\n * @property {FileFormat} fileFormat - The format of the file (JSON, MDX, MD, etc.).\n * @property {DataFormat} [dataFormat] - Optional format of the data within the file.\n */\nexport type FileReference = {\n fileId: string;\n versionId: string;\n branchId: string;\n fileName: string;\n fileFormat: FileFormat;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n\n/**\n * File reference object structure for referencing files.\n * @see {@link FileReference}\n * @property {string} [branchId] - The ID of the branch of the file\n */\nexport type FileReferenceIds = Omit<\n FileReference,\n 'branchId' | 'fileName' | 'fileFormat' | 'dataFormat'\n> & {\n branchId?: string;\n fileName?: string;\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,sBAA+C,IAAI,IAC9D,CAAC,UAAU,cAAc,CAC1B;;;;;AAMD,SAAgB,mBAAmB,YAAiC;AAClE,QAAO,oBAAoB,IAAI,WAAW"}
|
package/dist/id.d.cts
CHANGED
package/dist/id.d.mts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_api = require("./api-tMgy8sHj.cjs");
|
|
3
3
|
const require_runtime = require("./runtime-DoOLkKJT.cjs");
|
|
4
|
-
const require_derive = require("./derive-
|
|
5
|
-
const require_file = require("./file-
|
|
4
|
+
const require_derive = require("./derive-bDBg-KyF.cjs");
|
|
5
|
+
const require_file = require("./file-D7gKavRj.cjs");
|
|
6
6
|
let _generaltranslation_format = require("@generaltranslation/format");
|
|
7
7
|
//#region src/translate/setupProject.ts
|
|
8
8
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as UploadFilesOptions, A as AwaitJobsOptions, F as MoveMapping, H as FileDataResult, L as ProcessMovesOptions, N as CheckJobStatusResult, Q as FileUpload, R as ProcessMovesResponse, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _t as EnqueueFilesResult, at as CreateTagResult, bt as FileQuery, ct as DownloadFileBatchRequest, et as UploadFilesResponse, it as CreateTagOptions, j as AwaitJobsResult, k as SubmitUserEditDiffsPayload, lt as DownloadFileBatchResult, mt as FileReferenceIds, nt as SetupProjectOptions, ot as EnqueueFilesOptions, rt as SetupProjectResult, st as DownloadFileBatchOptions, tt as SetupProjectFileReference, xt as FileQueryResult, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-
|
|
1
|
+
import { $ as UploadFilesOptions, A as AwaitJobsOptions, F as MoveMapping, H as FileDataResult, L as ProcessMovesOptions, N as CheckJobStatusResult, Q as FileUpload, R as ProcessMovesResponse, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _t as EnqueueFilesResult, at as CreateTagResult, bt as FileQuery, ct as DownloadFileBatchRequest, et as UploadFilesResponse, it as CreateTagOptions, j as AwaitJobsResult, k as SubmitUserEditDiffsPayload, lt as DownloadFileBatchResult, mt as FileReferenceIds, nt as SetupProjectOptions, ot as EnqueueFilesOptions, rt as SetupProjectResult, st as DownloadFileBatchOptions, tt as SetupProjectFileReference, xt as FileQueryResult, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-DO3dc8ST.cjs";
|
|
2
2
|
import { GTConstructorParams, GTRuntime } from "./runtime.cjs";
|
|
3
3
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-DBCCXTmL.cjs";
|
|
4
4
|
import { LocaleConfig, LocaleConfigConstructorParams, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale } from "@generaltranslation/format";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as UploadFilesOptions, A as AwaitJobsOptions, F as MoveMapping, H as FileDataResult, L as ProcessMovesOptions, N as CheckJobStatusResult, Q as FileUpload, R as ProcessMovesResponse, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _t as EnqueueFilesResult, at as CreateTagResult, bt as FileQuery, ct as DownloadFileBatchRequest, et as UploadFilesResponse, it as CreateTagOptions, j as AwaitJobsResult, k as SubmitUserEditDiffsPayload, lt as DownloadFileBatchResult, mt as FileReferenceIds, nt as SetupProjectOptions, ot as EnqueueFilesOptions, rt as SetupProjectResult, st as DownloadFileBatchOptions, tt as SetupProjectFileReference, xt as FileQueryResult, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-
|
|
1
|
+
import { $ as UploadFilesOptions, A as AwaitJobsOptions, F as MoveMapping, H as FileDataResult, L as ProcessMovesOptions, N as CheckJobStatusResult, Q as FileUpload, R as ProcessMovesResponse, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _t as EnqueueFilesResult, at as CreateTagResult, bt as FileQuery, ct as DownloadFileBatchRequest, et as UploadFilesResponse, it as CreateTagOptions, j as AwaitJobsResult, k as SubmitUserEditDiffsPayload, lt as DownloadFileBatchResult, mt as FileReferenceIds, nt as SetupProjectOptions, ot as EnqueueFilesOptions, rt as SetupProjectResult, st as DownloadFileBatchOptions, tt as SetupProjectFileReference, xt as FileQueryResult, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-C8sSACgY.mjs";
|
|
2
2
|
import { GTConstructorParams, GTRuntime } from "./runtime.mjs";
|
|
3
3
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-texIAHzc.mjs";
|
|
4
4
|
import { LocaleConfig, LocaleConfigConstructorParams, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale } from "@generaltranslation/format";
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as defaultTimeout } from "./api-rqq7klYe.mjs";
|
|
2
2
|
import { a as validateResponse, c as noSourceLocaleProvidedError, i as handleFetchError, l as noTargetLocaleProvidedError, n as apiRequest, o as fetchWithTimeout, r as generateRequestHeaders, s as gtInstanceLogger, t as GTRuntime } from "./runtime-hWpzl6v_.mjs";
|
|
3
|
-
import { c as decode, l as encode, n as declareVar, r as decodeVars, t as derive, u as isSupportedFileFormatTransform } from "./derive-
|
|
4
|
-
import { n as isBinaryFileFormat } from "./file-
|
|
3
|
+
import { c as decode, l as encode, n as declareVar, r as decodeVars, t as derive, u as isSupportedFileFormatTransform } from "./derive-C3nzgrzy.mjs";
|
|
4
|
+
import { n as isBinaryFileFormat } from "./file-Cgk1Xk9d.mjs";
|
|
5
5
|
import { LocaleConfig, determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale } from "@generaltranslation/format";
|
|
6
6
|
//#region src/translate/setupProject.ts
|
|
7
7
|
/**
|
package/dist/internal.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_api = require("./api-tMgy8sHj.cjs");
|
|
3
|
-
const require_derive = require("./derive-
|
|
3
|
+
const require_derive = require("./derive-bDBg-KyF.cjs");
|
|
4
4
|
const require_isVariable = require("./isVariable-I3nllgeI.cjs");
|
|
5
5
|
let _generaltranslation_icu = require("@generaltranslation/icu");
|
|
6
6
|
let _generaltranslation_format_internal = require("@generaltranslation/format/internal");
|
package/dist/internal.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as VariableType, D as VariableTransformationSuffix, Mt as RuntimeTranslateManyOptions, S as Variable, ft as FileFormat, g as LocaleProperties, h as JsxElement, m as JsxChildren, p as JsxChild } from "./types-
|
|
1
|
+
import { C as VariableType, D as VariableTransformationSuffix, Mt as RuntimeTranslateManyOptions, S as Variable, ft as FileFormat, g as LocaleProperties, h as JsxElement, m as JsxChildren, p as JsxChild } from "./types-DO3dc8ST.cjs";
|
|
2
2
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-DBCCXTmL.cjs";
|
|
3
3
|
import { IcuMessage } from "@generaltranslation/format/types";
|
|
4
4
|
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as VariableType, D as VariableTransformationSuffix, Mt as RuntimeTranslateManyOptions, S as Variable, ft as FileFormat, g as LocaleProperties, h as JsxElement, m as JsxChildren, p as JsxChild } from "./types-
|
|
1
|
+
import { C as VariableType, D as VariableTransformationSuffix, Mt as RuntimeTranslateManyOptions, S as Variable, ft as FileFormat, g as LocaleProperties, h as JsxElement, m as JsxChildren, p as JsxChild } from "./types-C8sSACgY.mjs";
|
|
2
2
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-texIAHzc.mjs";
|
|
3
3
|
import { IcuMessage } from "@generaltranslation/format/types";
|
|
4
4
|
|
package/dist/internal.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as createDiagnosticMessage, c as libraryDefaultLocale, i as defaultRuntimeApiUrl, n as defaultBaseUrl, o as formatDiagnosticErrorDetails, r as defaultCacheUrl, t as API_VERSION } from "./api-rqq7klYe.mjs";
|
|
2
|
-
import { a as isGTUnindexedSelectElement, c as decode, i as isGTIndexedSelectElement, l as encode, n as declareVar, o as VAR_IDENTIFIER, r as decodeVars, s as traverseIcu, t as derive, u as isSupportedFileFormatTransform } from "./derive-
|
|
2
|
+
import { a as isGTUnindexedSelectElement, c as decode, i as isGTIndexedSelectElement, l as encode, n as declareVar, o as VAR_IDENTIFIER, r as decodeVars, s as traverseIcu, t as derive, u as isSupportedFileFormatTransform } from "./derive-C3nzgrzy.mjs";
|
|
3
3
|
import { t as isVariable } from "./isVariable-8-Wy5FnX.mjs";
|
|
4
4
|
import { TYPE, printAST } from "@generaltranslation/icu";
|
|
5
5
|
import { getCachedPluralRules } from "@generaltranslation/format/internal";
|
package/dist/runtime.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as TranslateManyResult, K as TranslationError, Nt as TranslateManyEntry, Pt as TranslateOptions, q as TranslationResult, x as TranslationRequestConfig } from "./types-
|
|
1
|
+
import { G as TranslateManyResult, K as TranslationError, Nt as TranslateManyEntry, Pt as TranslateOptions, q as TranslationResult, x as TranslationRequestConfig } from "./types-DO3dc8ST.cjs";
|
|
2
2
|
import { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariables, LocaleProperties, StringFormat } from "@generaltranslation/format/types";
|
|
3
3
|
import { LocaleConfig } from "@generaltranslation/format";
|
|
4
4
|
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as TranslateManyResult, K as TranslationError, Nt as TranslateManyEntry, Pt as TranslateOptions, q as TranslationResult, x as TranslationRequestConfig } from "./types-
|
|
1
|
+
import { G as TranslateManyResult, K as TranslationError, Nt as TranslateManyEntry, Pt as TranslateOptions, q as TranslationResult, x as TranslationRequestConfig } from "./types-C8sSACgY.mjs";
|
|
2
2
|
import { LocaleConfig } from "@generaltranslation/format";
|
|
3
3
|
import { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariables, LocaleProperties, StringFormat } from "@generaltranslation/format/types";
|
|
4
4
|
|
|
@@ -229,7 +229,7 @@ type FileFormat = _$_generaltranslation_api0.FileFormat;
|
|
|
229
229
|
* base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the
|
|
230
230
|
* bytes reach the API unaltered.
|
|
231
231
|
*
|
|
232
|
-
* LOTTIE qualifies because it is a zip bundle.
|
|
232
|
+
* LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because
|
|
233
233
|
* older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the
|
|
234
234
|
* byte order mark, and a UTF-8 round trip anywhere in between replaces those
|
|
235
235
|
* bytes with U+FFFD.
|
|
@@ -649,4 +649,4 @@ type TranslationRequestConfig = {
|
|
|
649
649
|
};
|
|
650
650
|
//#endregion
|
|
651
651
|
export { UploadFilesOptions as $, AwaitJobsOptions as A, ActionType as At, OrphanedFile as B, VariableType as C, JsonPrimitive as Ct, VariableTransformationSuffix as D, GTOutputFileConfig as Dt, TransformationPrefix as E, GTFilesConfig as Et, MoveMapping as F, TranslateManyResult as G, FileDataResult as H, MoveResult as I, TranslationResultReference as J, TranslationError as K, ProcessMovesOptions as L, JobResult as M, RuntimeTranslateManyOptions as Mt, CheckJobStatusResult as N, TranslateManyEntry as Nt, SubmitUserEditDiff as O, GTParsingFlags as Ot, JobStatus as P, TranslateOptions as Pt, FileUpload as Q, ProcessMovesResponse as R, Variable as S, JsonObject as St, Transformation as T, GTConfig as Tt, BranchQuery as U, FileDataQuery as V, BranchDataResult as W, PublishFileEntry as X, DownloadFileOptions as Y, PublishFilesResult as Z, Metadata as _, EnqueueFilesResult as _t, DataFormat$1 as a, CreateTagResult as at, StringMessage$1 as b, FileQuery as bt, HTML_CONTENT_PROPS as c, DownloadFileBatchRequest as ct, I18nextMessage$1 as d, BINARY_FILE_FORMATS as dt, UploadFilesResponse as et, IcuMessage$1 as f, FileFormat as ft, LocaleProperties$1 as g, isBinaryFileFormat as gt, JsxElement as h, FileToUpload as ht, CutoffFormatOptions$1 as i, CreateTagOptions as it, AwaitJobsResult as j, EntryMetadata as jt, SubmitUserEditDiffsPayload as k, HashMetadata as kt, HtmlContentPropKeysRecord as l, DownloadFileBatchResult as lt, JsxChildren$1 as m, FileReferenceIds as mt, CustomMapping$1 as n, SetupProjectOptions as nt, FormatVariables$1 as o, EnqueueFilesOptions as ot, JsxChild as p, FileReference as pt, TranslationResult as q, CustomRegionMapping$1 as r, SetupProjectResult as rt, GTProp as s, DownloadFileBatchOptions as st, Content as t, SetupProjectFileReference as tt, HtmlContentPropValuesRecord as u, DownloadedFile as ut, StringContent as v, Updates as vt, InjectionType as w, JsonValue as wt, TranslationRequestConfig as x, FileQueryResult as xt, StringFormat$1 as y, CheckFileTranslationsOptions as yt, GetOrphanedFilesResult as z };
|
|
652
|
-
//# sourceMappingURL=types-
|
|
652
|
+
//# sourceMappingURL=types-C8sSACgY.d.mts.map
|
|
@@ -229,7 +229,7 @@ type FileFormat = _$_generaltranslation_api0.FileFormat;
|
|
|
229
229
|
* base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the
|
|
230
230
|
* bytes reach the API unaltered.
|
|
231
231
|
*
|
|
232
|
-
* LOTTIE qualifies because it is a zip bundle.
|
|
232
|
+
* LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because
|
|
233
233
|
* older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the
|
|
234
234
|
* byte order mark, and a UTF-8 round trip anywhere in between replaces those
|
|
235
235
|
* bytes with U+FFFD.
|
|
@@ -649,4 +649,4 @@ type TranslationRequestConfig = {
|
|
|
649
649
|
};
|
|
650
650
|
//#endregion
|
|
651
651
|
export { UploadFilesOptions as $, AwaitJobsOptions as A, ActionType as At, OrphanedFile as B, VariableType as C, JsonPrimitive as Ct, VariableTransformationSuffix as D, GTOutputFileConfig as Dt, TransformationPrefix as E, GTFilesConfig as Et, MoveMapping as F, TranslateManyResult as G, FileDataResult as H, MoveResult as I, TranslationResultReference as J, TranslationError as K, ProcessMovesOptions as L, JobResult as M, RuntimeTranslateManyOptions as Mt, CheckJobStatusResult as N, TranslateManyEntry as Nt, SubmitUserEditDiff as O, GTParsingFlags as Ot, JobStatus as P, TranslateOptions as Pt, FileUpload as Q, ProcessMovesResponse as R, Variable as S, JsonObject as St, Transformation as T, GTConfig as Tt, BranchQuery as U, FileDataQuery as V, BranchDataResult as W, PublishFileEntry as X, DownloadFileOptions as Y, PublishFilesResult as Z, Metadata as _, EnqueueFilesResult as _t, DataFormat$1 as a, CreateTagResult as at, StringMessage$1 as b, FileQuery as bt, HTML_CONTENT_PROPS as c, DownloadFileBatchRequest as ct, I18nextMessage$1 as d, BINARY_FILE_FORMATS as dt, UploadFilesResponse as et, IcuMessage$1 as f, FileFormat as ft, LocaleProperties$1 as g, isBinaryFileFormat as gt, JsxElement as h, FileToUpload as ht, CutoffFormatOptions$1 as i, CreateTagOptions as it, AwaitJobsResult as j, EntryMetadata as jt, SubmitUserEditDiffsPayload as k, HashMetadata as kt, HtmlContentPropKeysRecord as l, DownloadFileBatchResult as lt, JsxChildren$1 as m, FileReferenceIds as mt, CustomMapping$1 as n, SetupProjectOptions as nt, FormatVariables$1 as o, EnqueueFilesOptions as ot, JsxChild as p, FileReference as pt, TranslationResult as q, CustomRegionMapping$1 as r, SetupProjectResult as rt, GTProp as s, DownloadFileBatchOptions as st, Content as t, SetupProjectFileReference as tt, HtmlContentPropValuesRecord as u, DownloadedFile as ut, StringContent as v, Updates as vt, InjectionType as w, JsonValue as wt, TranslationRequestConfig as x, FileQueryResult as xt, StringFormat$1 as y, CheckFileTranslationsOptions as yt, GetOrphanedFilesResult as z };
|
|
652
|
-
//# sourceMappingURL=types-
|
|
652
|
+
//# sourceMappingURL=types-DO3dc8ST.d.cts.map
|
|
@@ -7,7 +7,7 @@ export type FileFormat = import('@generaltranslation/api').FileFormat;
|
|
|
7
7
|
* base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the
|
|
8
8
|
* bytes reach the API unaltered.
|
|
9
9
|
*
|
|
10
|
-
* LOTTIE qualifies because it is a zip bundle.
|
|
10
|
+
* LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because
|
|
11
11
|
* older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the
|
|
12
12
|
* byte order mark, and a UTF-8 round trip anywhere in between replaces those
|
|
13
13
|
* bytes with U+FFFD.
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the
|
|
4
4
|
* bytes reach the API unaltered.
|
|
5
5
|
*
|
|
6
|
-
* LOTTIE qualifies because it is a zip bundle.
|
|
6
|
+
* LOTTIE qualifies because it is a zip bundle. DOT_STRINGS qualifies because
|
|
7
7
|
* older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the
|
|
8
8
|
* byte order mark, and a UTF-8 round trip anywhere in between replaces those
|
|
9
9
|
* bytes with U+FFFD.
|
|
10
10
|
*/
|
|
11
|
-
export var BINARY_FILE_FORMATS = new Set(['LOTTIE', '
|
|
11
|
+
export var BINARY_FILE_FORMATS = new Set(['LOTTIE', 'DOT_STRINGS']);
|
|
12
12
|
/**
|
|
13
13
|
* Whether a file format's content is carried as base64 end-to-end rather than
|
|
14
14
|
* as a UTF-8 text string.
|
package/dist/types.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_file = require("./file-
|
|
2
|
+
const require_file = require("./file-D7gKavRj.cjs");
|
|
3
3
|
let _generaltranslation_format_types = require("@generaltranslation/format/types");
|
|
4
4
|
exports.BINARY_FILE_FORMATS = require_file.BINARY_FILE_FORMATS;
|
|
5
5
|
Object.defineProperty(exports, "HTML_CONTENT_PROPS", {
|
package/dist/types.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as AwaitJobsOptions, At as ActionType, B as OrphanedFile, C as VariableType, Ct as JsonPrimitive, D as VariableTransformationSuffix, Dt as GTOutputFileConfig, E as TransformationPrefix, Et as GTFilesConfig, F as MoveMapping, G as TranslateManyResult, H as FileDataResult, I as MoveResult, J as TranslationResultReference, K as TranslationError, L as ProcessMovesOptions, M as JobResult, N as CheckJobStatusResult, Nt as TranslateManyEntry, O as SubmitUserEditDiff, Ot as GTParsingFlags, P as JobStatus, Q as FileUpload, R as ProcessMovesResponse, S as Variable, St as JsonObject, T as Transformation, Tt as GTConfig, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _ as Metadata, _t as EnqueueFilesResult, a as DataFormat, at as CreateTagResult, b as StringMessage, c as HTML_CONTENT_PROPS, d as I18nextMessage, dt as BINARY_FILE_FORMATS, f as IcuMessage, ft as FileFormat, g as LocaleProperties, gt as isBinaryFileFormat, h as JsxElement, ht as FileToUpload, i as CutoffFormatOptions, it as CreateTagOptions, j as AwaitJobsResult, jt as EntryMetadata, k as SubmitUserEditDiffsPayload, kt as HashMetadata, l as HtmlContentPropKeysRecord, lt as DownloadFileBatchResult, m as JsxChildren, n as CustomMapping, o as FormatVariables, ot as EnqueueFilesOptions, p as JsxChild, pt as FileReference, q as TranslationResult, r as CustomRegionMapping, s as GTProp, st as DownloadFileBatchOptions, t as Content, tt as SetupProjectFileReference, u as HtmlContentPropValuesRecord, ut as DownloadedFile, v as StringContent, vt as Updates, w as InjectionType, wt as JsonValue, x as TranslationRequestConfig, y as StringFormat, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-
|
|
1
|
+
import { A as AwaitJobsOptions, At as ActionType, B as OrphanedFile, C as VariableType, Ct as JsonPrimitive, D as VariableTransformationSuffix, Dt as GTOutputFileConfig, E as TransformationPrefix, Et as GTFilesConfig, F as MoveMapping, G as TranslateManyResult, H as FileDataResult, I as MoveResult, J as TranslationResultReference, K as TranslationError, L as ProcessMovesOptions, M as JobResult, N as CheckJobStatusResult, Nt as TranslateManyEntry, O as SubmitUserEditDiff, Ot as GTParsingFlags, P as JobStatus, Q as FileUpload, R as ProcessMovesResponse, S as Variable, St as JsonObject, T as Transformation, Tt as GTConfig, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _ as Metadata, _t as EnqueueFilesResult, a as DataFormat, at as CreateTagResult, b as StringMessage, c as HTML_CONTENT_PROPS, d as I18nextMessage, dt as BINARY_FILE_FORMATS, f as IcuMessage, ft as FileFormat, g as LocaleProperties, gt as isBinaryFileFormat, h as JsxElement, ht as FileToUpload, i as CutoffFormatOptions, it as CreateTagOptions, j as AwaitJobsResult, jt as EntryMetadata, k as SubmitUserEditDiffsPayload, kt as HashMetadata, l as HtmlContentPropKeysRecord, lt as DownloadFileBatchResult, m as JsxChildren, n as CustomMapping, o as FormatVariables, ot as EnqueueFilesOptions, p as JsxChild, pt as FileReference, q as TranslationResult, r as CustomRegionMapping, s as GTProp, st as DownloadFileBatchOptions, t as Content, tt as SetupProjectFileReference, u as HtmlContentPropValuesRecord, ut as DownloadedFile, v as StringContent, vt as Updates, w as InjectionType, wt as JsonValue, x as TranslationRequestConfig, y as StringFormat, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-DO3dc8ST.cjs";
|
|
2
2
|
export { AwaitJobsOptions, AwaitJobsResult, BINARY_FILE_FORMATS, BranchDataResult, BranchQuery, CheckFileTranslationsOptions, CheckJobStatusResult, Content, CreateTagOptions, CreateTagResult, CustomMapping, CustomRegionMapping, CutoffFormatOptions, DataFormat, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, DownloadedFile, EnqueueFilesOptions, EnqueueFilesResult, ActionType as EntryActionType, EntryMetadata, FileDataQuery, FileDataResult, FileFormat, FileReference, FileToUpload, FileUpload, FormatVariables, GTConfig, GTFilesConfig, GTOutputFileConfig, GTParsingFlags, GTProp, GetOrphanedFilesResult, HTML_CONTENT_PROPS, HashMetadata, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, InjectionType, JobResult, JobStatus, JsonObject, JsonPrimitive, JsonValue, JsxChild, JsxChildren, JsxElement, LocaleProperties, Metadata, MoveMapping, MoveResult, OrphanedFile, ProcessMovesOptions, ProcessMovesResponse, PublishFileEntry, PublishFilesResult, SetupProjectFileReference, StringContent, StringFormat, StringMessage, SubmitUserEditDiff, SubmitUserEditDiffsPayload, Transformation, TransformationPrefix, TranslateManyEntry, TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslationResultReference, Updates, Variable, VariableTransformationSuffix, VariableType, isBinaryFileFormat };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as AwaitJobsOptions, At as ActionType, B as OrphanedFile, C as VariableType, Ct as JsonPrimitive, D as VariableTransformationSuffix, Dt as GTOutputFileConfig, E as TransformationPrefix, Et as GTFilesConfig, F as MoveMapping, G as TranslateManyResult, H as FileDataResult, I as MoveResult, J as TranslationResultReference, K as TranslationError, L as ProcessMovesOptions, M as JobResult, N as CheckJobStatusResult, Nt as TranslateManyEntry, O as SubmitUserEditDiff, Ot as GTParsingFlags, P as JobStatus, Q as FileUpload, R as ProcessMovesResponse, S as Variable, St as JsonObject, T as Transformation, Tt as GTConfig, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _ as Metadata, _t as EnqueueFilesResult, a as DataFormat, at as CreateTagResult, b as StringMessage, c as HTML_CONTENT_PROPS, d as I18nextMessage, dt as BINARY_FILE_FORMATS, f as IcuMessage, ft as FileFormat, g as LocaleProperties, gt as isBinaryFileFormat, h as JsxElement, ht as FileToUpload, i as CutoffFormatOptions, it as CreateTagOptions, j as AwaitJobsResult, jt as EntryMetadata, k as SubmitUserEditDiffsPayload, kt as HashMetadata, l as HtmlContentPropKeysRecord, lt as DownloadFileBatchResult, m as JsxChildren, n as CustomMapping, o as FormatVariables, ot as EnqueueFilesOptions, p as JsxChild, pt as FileReference, q as TranslationResult, r as CustomRegionMapping, s as GTProp, st as DownloadFileBatchOptions, t as Content, tt as SetupProjectFileReference, u as HtmlContentPropValuesRecord, ut as DownloadedFile, v as StringContent, vt as Updates, w as InjectionType, wt as JsonValue, x as TranslationRequestConfig, y as StringFormat, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-
|
|
1
|
+
import { A as AwaitJobsOptions, At as ActionType, B as OrphanedFile, C as VariableType, Ct as JsonPrimitive, D as VariableTransformationSuffix, Dt as GTOutputFileConfig, E as TransformationPrefix, Et as GTFilesConfig, F as MoveMapping, G as TranslateManyResult, H as FileDataResult, I as MoveResult, J as TranslationResultReference, K as TranslationError, L as ProcessMovesOptions, M as JobResult, N as CheckJobStatusResult, Nt as TranslateManyEntry, O as SubmitUserEditDiff, Ot as GTParsingFlags, P as JobStatus, Q as FileUpload, R as ProcessMovesResponse, S as Variable, St as JsonObject, T as Transformation, Tt as GTConfig, U as BranchQuery, V as FileDataQuery, W as BranchDataResult, X as PublishFileEntry, Y as DownloadFileOptions, Z as PublishFilesResult, _ as Metadata, _t as EnqueueFilesResult, a as DataFormat, at as CreateTagResult, b as StringMessage, c as HTML_CONTENT_PROPS, d as I18nextMessage, dt as BINARY_FILE_FORMATS, f as IcuMessage, ft as FileFormat, g as LocaleProperties, gt as isBinaryFileFormat, h as JsxElement, ht as FileToUpload, i as CutoffFormatOptions, it as CreateTagOptions, j as AwaitJobsResult, jt as EntryMetadata, k as SubmitUserEditDiffsPayload, kt as HashMetadata, l as HtmlContentPropKeysRecord, lt as DownloadFileBatchResult, m as JsxChildren, n as CustomMapping, o as FormatVariables, ot as EnqueueFilesOptions, p as JsxChild, pt as FileReference, q as TranslationResult, r as CustomRegionMapping, s as GTProp, st as DownloadFileBatchOptions, t as Content, tt as SetupProjectFileReference, u as HtmlContentPropValuesRecord, ut as DownloadedFile, v as StringContent, vt as Updates, w as InjectionType, wt as JsonValue, x as TranslationRequestConfig, y as StringFormat, yt as CheckFileTranslationsOptions, z as GetOrphanedFilesResult } from "./types-C8sSACgY.mjs";
|
|
2
2
|
export { AwaitJobsOptions, AwaitJobsResult, BINARY_FILE_FORMATS, BranchDataResult, BranchQuery, CheckFileTranslationsOptions, CheckJobStatusResult, Content, CreateTagOptions, CreateTagResult, CustomMapping, CustomRegionMapping, CutoffFormatOptions, DataFormat, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, DownloadedFile, EnqueueFilesOptions, EnqueueFilesResult, ActionType as EntryActionType, EntryMetadata, FileDataQuery, FileDataResult, FileFormat, FileReference, FileToUpload, FileUpload, FormatVariables, GTConfig, GTFilesConfig, GTOutputFileConfig, GTParsingFlags, GTProp, GetOrphanedFilesResult, HTML_CONTENT_PROPS, HashMetadata, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, InjectionType, JobResult, JobStatus, JsonObject, JsonPrimitive, JsonValue, JsxChild, JsxChildren, JsxElement, LocaleProperties, Metadata, MoveMapping, MoveResult, OrphanedFile, ProcessMovesOptions, ProcessMovesResponse, PublishFileEntry, PublishFilesResult, SetupProjectFileReference, StringContent, StringFormat, StringMessage, SubmitUserEditDiff, SubmitUserEditDiffsPayload, Transformation, TransformationPrefix, TranslateManyEntry, TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslationResultReference, Updates, Variable, VariableTransformationSuffix, VariableType, isBinaryFileFormat };
|
package/dist/types.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as isBinaryFileFormat, t as BINARY_FILE_FORMATS } from "./file-
|
|
1
|
+
import { n as isBinaryFileFormat, t as BINARY_FILE_FORMATS } from "./file-Cgk1Xk9d.mjs";
|
|
2
2
|
import { HTML_CONTENT_PROPS } from "@generaltranslation/format/types";
|
|
3
3
|
export { BINARY_FILE_FORMATS, HTML_CONTENT_PROPS, isBinaryFileFormat };
|
|
@@ -14,8 +14,9 @@ var SUPPORTED_TRANSFORMATIONS = {
|
|
|
14
14
|
TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],
|
|
15
15
|
LOTTIE: ['LOTTIE'],
|
|
16
16
|
SVG: ['SVG'],
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
DOT_STRINGS: ['DOT_STRINGS'],
|
|
18
|
+
DOT_STRINGSDICT: ['DOT_STRINGSDICT'],
|
|
19
|
+
ANDROID_STRINGS: ['ANDROID_STRINGS'],
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
22
|
* This function checks if a file format transformation is supported during translation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generaltranslation",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.13",
|
|
4
4
|
"description": "A language toolkit for AI developers",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@noble/hashes": "^2.2.0",
|
|
43
|
-
"@generaltranslation/api": "0.0.
|
|
43
|
+
"@generaltranslation/api": "0.0.6",
|
|
44
44
|
"@generaltranslation/icu": "0.1.2",
|
|
45
45
|
"@generaltranslation/format": "0.1.8"
|
|
46
46
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"derive-DLrMiUyi.cjs","names":["TYPE","TYPE"],"sources":["../src/utils/isSupportedFileFormatTransform.ts","../src/utils/base64.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts"],"sourcesContent":["import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n LOTTIE: ['LOTTIE'],\n SVG: ['SVG'],\n APPLE_STRINGS: ['APPLE_STRINGS'],\n APPLE_STRINGSDICT: ['APPLE_STRINGSDICT'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n","import {\n parse,\n TYPE,\n type MessageFormatElement,\n type ParserOptions,\n} from '@generaltranslation/icu';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport { TYPE, type MessageFormatElement } from '@generaltranslation/icu';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n"],"mappings":";;AAEA,MAAM,4BAA4B;CAChC,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,OAAO;CACd,IAAI,CAAC,KAAK;CAEV,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,qBAAqB,CAAC,sBAAsB;CAC5C,QAAQ,CAAC,SAAS;CAClB,KAAK,CAAC,MAAM;CACZ,eAAe,CAAC,gBAAgB;CAChC,mBAAmB,CAAC,oBAAoB;CACzC;;;;;;;AAQD,SAAgB,+BACd,MACA,IACS;AAET,QAD4C,0BAA0B,OACpD,SAAS,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AW,KAAK,kBAAkB,GAAG,MAAM;AAC3C,kBAAgB,kBAAkB,GAAG;;AAEvC,KAAI,gBAAgB,UAAU,OAC5B,YAAW,KAAK,UAAU,MAAM,cAAc,CAAC;AAIjD,QAFqB,WAAW,KAAK,GAElB;;;;;;;;;;;;;;;ACnDrB,SAAgB,YAAY,QAAwB;CAElD,IAAI,SAAS,OAAO,QAAQ,MAAM,KAAK;CAGvC,MAAM,eAAe;CACrB,MAAM,oBAAoB,OAAO,OAAO,aAAa;AAErD,KAAI,sBAAsB,GAExB,QAAO;CAIT,IAAI,mBAAmB;AACvB,MAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,IACtC,KAAI,aAAa,KAAK,OAAO,GAAG,EAAE;AAChC,qBAAmB;AACnB;;AAKJ,UACE,OAAO,MAAM,GAAG,kBAAkB,GAClC,MACA,OAAO,MAAM,mBAAmB,mBAAmB,EAAE,GACrD,MACA,OAAO,MAAM,mBAAmB,EAAE;AAEpC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;ACfT,SAAgB,WACd,UACA,SACQ;CAGR,MAAM,kBAAkB,WADE,YAAY,OAAO,YAAY,GAAG,CACR,CAAC;CAGrD,IAAI,cAAc;AAClB,KAAI,SAAS,MAEX,eAAc,IAAI,oBAAoB,IADhB,YAAY,QAAQ,MACa,CAAC;AAI1D,QAAO,IAAI,eAAe,WAAW,kBAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACfrE,SAAgB,OACd,SACG;AACH,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"derive-DVQrJM6B.mjs","names":[],"sources":["../src/utils/isSupportedFileFormatTransform.ts","../src/utils/base64.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts"],"sourcesContent":["import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n LOTTIE: ['LOTTIE'],\n SVG: ['SVG'],\n APPLE_STRINGS: ['APPLE_STRINGS'],\n APPLE_STRINGSDICT: ['APPLE_STRINGSDICT'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n","import {\n parse,\n TYPE,\n type MessageFormatElement,\n type ParserOptions,\n} from '@generaltranslation/icu';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport { TYPE, type MessageFormatElement } from '@generaltranslation/icu';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n"],"mappings":";;AAEA,MAAM,4BAA4B;CAChC,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,OAAO;CACd,IAAI,CAAC,KAAK;CAEV,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,qBAAqB,CAAC,sBAAsB;CAC5C,QAAQ,CAAC,SAAS;CAClB,KAAK,CAAC,MAAM;CACZ,eAAe,CAAC,gBAAgB;CAChC,mBAAmB,CAAC,oBAAoB;CACzC;;;;;;;AAQD,SAAgB,+BACd,MACA,IACS;AAET,QAD4C,0BAA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AG;;AAEvC,KAAI,gBAAgB,UAAU,OAC5B,YAAW,KAAK,UAAU,MAAM,cAAc,CAAC;AAIjD,QAFqB,WAAW,KAAK,GAElB;;;;;;;;;;;;;;;ACnDrB,SAAgB,YAAY,QAAwB;CAElD,IAAI,SAAS,OAAO,QAAQ,MAAM,KAAK;CAGvC,MAAM,eAAe;CACrB,MAAM,oBAAoB,OAAO,OAAO,aAAa;AAErD,KAAI,sBAAsB,GAExB,QAAO;CAIT,IAAI,mBAAmB;AACvB,MAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,IACtC,KAAI,aAAa,KAAK,OAAO,GAAG,EAAE;AAChC,qBAAmB;AACnB;;AAKJ,UACE,OAAO,MAAM,GAAG,kBAAkB,GAClC,MACA,OAAO,MAAM,mBAAmB,mBAAmB,EAAE,GACrD,MACA,OAAO,MAAM,mBAAmB,EAAE;AAEpC,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;ACfT,SAAgB,WACd,UACA,SACQ;CAGR,MAAM,kBAAkB,WADE,YAAY,OAAO,YAAY,GAAG,CACR,CAAC;CAGrD,IAAI,cAAc;AAClB,KAAI,SAAS,MAEX,eAAc,IAAI,oBAAoB,IADhB,YAAY,QAAQ,MACa,CAAC;AAI1D,QAAO,IAAI,eAAe,WAAW,kBAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACfrE,SAAgB,OACd,SACG;AACH,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-BXlTzYxX.cjs","names":[],"sources":["../src/types-dir/api/file.ts"],"sourcesContent":["import type { DataFormat } from '@generaltranslation/format/types';\nimport { Updates } from './enqueueFiles';\nimport type { JsonObject } from './json';\n\nexport type FileFormat = import('@generaltranslation/api').FileFormat;\n\n/**\n * File formats whose content travels through the pipeline already\n * base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the\n * bytes reach the API unaltered.\n *\n * LOTTIE qualifies because it is a zip bundle. APPLE_STRINGS qualifies because\n * older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the\n * byte order mark, and a UTF-8 round trip anywhere in between replaces those\n * bytes with U+FFFD.\n */\nexport const BINARY_FILE_FORMATS: ReadonlySet<FileFormat> = new Set<FileFormat>(\n ['LOTTIE', 'APPLE_STRINGS']\n);\n\n/**\n * Whether a file format's content is carried as base64 end-to-end rather than\n * as a UTF-8 text string.\n */\nexport function isBinaryFileFormat(fileFormat: FileFormat): boolean {\n return BINARY_FILE_FORMATS.has(fileFormat);\n}\n\n/**\n * Metadata for files or entries.\n */\nexport type FormatMetadata = JsonObject | Updates[number]['metadata'];\n\n/**\n * File object structure for uploading files.\n * @see {@link FileReferenceOptionalBranchId}\n * @property {string} content - Content of the file.\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {FormatMetadata} [formatMetadata] - Optional metadata for the file, specific to the format of the file\n * @property {string} [incomingBranchId] - The ID of the incoming branch of the file.\n * @property {string} [checkedOutBranchId] - The ID of the checked-out branch of the file.\n */\nexport type FileToUpload = Omit<FileReference, 'branchId'> & {\n content: string;\n locale: string;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n formatMetadata?: FormatMetadata;\n branchId?: string;\n incomingBranchId?: string;\n checkedOutBranchId?: string;\n};\n\n/**\n * File object structure for referencing files.\n * @property {string} fileId - The ID of the file.\n * @property {string} versionId - The ID of the version of the file\n * @property {string} branchId - The ID of the branch of the file\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {string} fileName - The name of the file.\n * @property {FileFormat} fileFormat - The format of the file (JSON, MDX, MD, etc.).\n * @property {DataFormat} [dataFormat] - Optional format of the data within the file.\n */\nexport type FileReference = {\n fileId: string;\n versionId: string;\n branchId: string;\n fileName: string;\n fileFormat: FileFormat;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n\n/**\n * File reference object structure for referencing files.\n * @see {@link FileReference}\n * @property {string} [branchId] - The ID of the branch of the file\n */\nexport type FileReferenceIds = Omit<\n FileReference,\n 'branchId' | 'fileName' | 'fileFormat' | 'dataFormat'\n> & {\n branchId?: string;\n fileName?: string;\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,sBAA+C,IAAI,IAC9D,CAAC,UAAU,gBAAgB,CAC5B;;;;;AAMD,SAAgB,mBAAmB,YAAiC;AAClE,QAAO,oBAAoB,IAAI,WAAW"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-CAUqDla-.mjs","names":[],"sources":["../src/types-dir/api/file.ts"],"sourcesContent":["import type { DataFormat } from '@generaltranslation/format/types';\nimport { Updates } from './enqueueFiles';\nimport type { JsonObject } from './json';\n\nexport type FileFormat = import('@generaltranslation/api').FileFormat;\n\n/**\n * File formats whose content travels through the pipeline already\n * base64-encoded, so the usual UTF-8 encode/decode steps are skipped and the\n * bytes reach the API unaltered.\n *\n * LOTTIE qualifies because it is a zip bundle. APPLE_STRINGS qualifies because\n * older Xcode wrote `.strings` as UTF-16: the API chooses a decoder from the\n * byte order mark, and a UTF-8 round trip anywhere in between replaces those\n * bytes with U+FFFD.\n */\nexport const BINARY_FILE_FORMATS: ReadonlySet<FileFormat> = new Set<FileFormat>(\n ['LOTTIE', 'APPLE_STRINGS']\n);\n\n/**\n * Whether a file format's content is carried as base64 end-to-end rather than\n * as a UTF-8 text string.\n */\nexport function isBinaryFileFormat(fileFormat: FileFormat): boolean {\n return BINARY_FILE_FORMATS.has(fileFormat);\n}\n\n/**\n * Metadata for files or entries.\n */\nexport type FormatMetadata = JsonObject | Updates[number]['metadata'];\n\n/**\n * File object structure for uploading files.\n * @see {@link FileReferenceOptionalBranchId}\n * @property {string} content - Content of the file.\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {FormatMetadata} [formatMetadata] - Optional metadata for the file, specific to the format of the file\n * @property {string} [incomingBranchId] - The ID of the incoming branch of the file.\n * @property {string} [checkedOutBranchId] - The ID of the checked-out branch of the file.\n */\nexport type FileToUpload = Omit<FileReference, 'branchId'> & {\n content: string;\n locale: string;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n formatMetadata?: FormatMetadata;\n branchId?: string;\n incomingBranchId?: string;\n checkedOutBranchId?: string;\n};\n\n/**\n * File object structure for referencing files.\n * @property {string} fileId - The ID of the file.\n * @property {string} versionId - The ID of the version of the file\n * @property {string} branchId - The ID of the branch of the file\n * @property {string} locale - The locale of the file (e.g. 'en', 'de', 'es', etc.)\n * @property {string} fileName - The name of the file.\n * @property {FileFormat} fileFormat - The format of the file (JSON, MDX, MD, etc.).\n * @property {DataFormat} [dataFormat] - Optional format of the data within the file.\n */\nexport type FileReference = {\n fileId: string;\n versionId: string;\n branchId: string;\n fileName: string;\n fileFormat: FileFormat;\n // Optional output format requested for generated translations.\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n\n/**\n * File reference object structure for referencing files.\n * @see {@link FileReference}\n * @property {string} [branchId] - The ID of the branch of the file\n */\nexport type FileReferenceIds = Omit<\n FileReference,\n 'branchId' | 'fileName' | 'fileFormat' | 'dataFormat'\n> & {\n branchId?: string;\n fileName?: string;\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n dataFormat?: DataFormat;\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,sBAA+C,IAAI,IAC9D,CAAC,UAAU,gBAAgB,CAC5B;;;;;AAMD,SAAgB,mBAAmB,YAAiC;AAClE,QAAO,oBAAoB,IAAI,WAAW"}
|