gt 2.13.1 → 2.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.13.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1147](https://github.com/generaltranslation/gt/pull/1147) [`d7d9b99`](https://github.com/generaltranslation/gt/commit/d7d9b9952f3a96dde2b89f206d47c491d503727f) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - chore: add support for multiple format types
8
+
9
+ - Updated dependencies [[`d7d9b99`](https://github.com/generaltranslation/gt/commit/d7d9b9952f3a96dde2b89f206d47c491d503727f)]:
10
+ - generaltranslation@8.1.23
11
+ - @generaltranslation/python-extractor@0.2.3
12
+
3
13
  ## 2.13.1
4
14
 
5
15
  ### Patch Changes
@@ -7,6 +7,7 @@ export declare const warnFailedToConstructJsxTreeSync: (file: string, code: stri
7
7
  export declare const warnNestedTComponent: (file: string, location?: string) => string;
8
8
  export declare const warnNonStaticExpressionSync: (file: string, attrName: string, value: string, location?: string) => string;
9
9
  export declare const warnInvalidMaxCharsSync: (file: string, value: string, location?: string) => string;
10
+ export declare const warnInvalidFormatSync: (file: string, value: string, location?: string) => string;
10
11
  export declare const warnInvalidIcuSync: (file: string, value: string, error: string, location?: string) => string;
11
12
  export declare const warnTemplateLiteralSync: (file: string, value: string, location?: string) => string;
12
13
  export declare const warnNonStringSync: (file: string, value: string, location?: string) => string;
@@ -16,6 +16,7 @@ export const warnFailedToConstructJsxTreeSync = (file, code, location) => withLo
16
16
  export const warnNestedTComponent = (file, location) => withLocation(file, `Found nested <T> component. <T> components cannot be directly nested.`, location);
17
17
  export const warnNonStaticExpressionSync = (file, attrName, value, location) => withLocation(file, `Found non-static expression for attribute ${colorizeIdString(attrName)}: ${colorizeContent(value)}. Change "${colorizeIdString(attrName)}" to ensure this content is translated.`, location);
18
18
  export const warnInvalidMaxCharsSync = (file, value, location) => withLocation(file, `Found invalid maxChars value: ${colorizeContent(value)}. Change the value to a valid number to ensure this content is translated.`, location);
19
+ export const warnInvalidFormatSync = (file, value, location) => withLocation(file, `Found invalid $format value: ${colorizeContent(value)}. Must be one of: 'ICU', 'STRING', 'I18NEXT'.`, location);
19
20
  export const warnInvalidIcuSync = (file, value, error, location) => withWillErrorInNextVersion(withLocation(file, `Found invalid ICU string: ${colorizeContent(value)}. Change the value to a valid ICU to ensure this content is translated. Error message: ${error}.`, location));
20
21
  export const warnTemplateLiteralSync = (file, value, location) => withLocation(file, `Found template literal with quasis (${colorizeContent(value)}). Change the template literal to a string to ensure this content is translated.`, location);
21
22
  export const warnNonStringSync = (file, value, location) => withLocation(file, `Found non-string literal (${colorizeContent(value)}). Change the value to a string literal to ensure this content is translated.`, location);
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.13.1";
1
+ export declare const PACKAGE_VERSION = "2.13.2";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.13.1';
2
+ export const PACKAGE_VERSION = '2.13.2';
@@ -22,7 +22,7 @@ export declare const GT_TRANSLATION_FUNCS: string[];
22
22
  export declare const STRING_REGISTRATION_FUNCS: readonly ["msg", "t"];
23
23
  export declare const GT_DERIVE_STRING_FUNCTIONS: string[];
24
24
  export declare const VARIABLE_COMPONENTS: string[];
25
- export declare const GT_ATTRIBUTES_WITH_SUGAR: readonly ["$id", "$context", "$maxChars"];
26
- export declare const GT_ATTRIBUTES: readonly ["id", "context", "maxChars", "$id", "$context", "$maxChars"];
25
+ export declare const GT_ATTRIBUTES_WITH_SUGAR: readonly ["$id", "$context", "$maxChars", "$format"];
26
+ export declare const GT_ATTRIBUTES: readonly ["id", "context", "maxChars", "$id", "$context", "$maxChars", "$format"];
27
27
  export declare const DATA_ATTR_PREFIX: "data-";
28
28
  export declare const T_GLOBAL_REGISTRATION_FUNCTION_MARKER = "_gt_internal_t_global_registration_marker";
@@ -62,6 +62,7 @@ export const GT_ATTRIBUTES_WITH_SUGAR = [
62
62
  '$id',
63
63
  '$context',
64
64
  '$maxChars',
65
+ '$format',
65
66
  ];
66
67
  export const GT_ATTRIBUTES = [
67
68
  'id',
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Type logic implementation
3
3
  */
4
- type MapAttributeName<T extends string> = T extends '$id' ? 'id' : T extends '$context' ? 'context' : T extends '$maxChars' ? 'maxChars' : T;
4
+ type MapAttributeName<T extends string> = T extends '$id' ? 'id' : T extends '$context' ? 'context' : T extends '$maxChars' ? 'maxChars' : T extends '$format' ? 'format' : T;
5
5
  /**
6
6
  * Map the attribute name to the corresponding attribute name in the metadata
7
7
  * @param attrName - The attribute name to map
@@ -6,6 +6,8 @@ export function mapAttributeName(attrName) {
6
6
  return 'context';
7
7
  case '$maxChars':
8
8
  return 'maxChars';
9
+ case '$format':
10
+ return 'format';
9
11
  default:
10
12
  return attrName;
11
13
  }
@@ -52,7 +52,7 @@ export function deriveExpression({ tPath, expr, metadata, config, output, index,
52
52
  const temporaryDeriveId = `derive-temp-id-${randomUUID()}`;
53
53
  for (const string of strings) {
54
54
  output.updates.push({
55
- dataFormat: 'ICU',
55
+ dataFormat: (metadata.format || 'ICU'),
56
56
  source: string,
57
57
  metadata: {
58
58
  ...metadata,
@@ -10,6 +10,7 @@ export type InlineMetadata = {
10
10
  context?: string;
11
11
  id?: string;
12
12
  hash?: string;
13
+ format?: string;
13
14
  filePaths?: string[];
14
15
  sourceCode?: Record<string, SourceCode[]>;
15
16
  };
@@ -1,6 +1,7 @@
1
1
  import * as t from '@babel/types';
2
2
  import { isStaticExpression } from '../../../evaluateJsx.js';
3
3
  import { warnInvalidMaxCharsSync } from '../../../../../console/index.js';
4
+ import { warnInvalidFormatSync } from '../../../../../console/index.js';
4
5
  import { warnNonStaticExpressionSync } from '../../../../../console/index.js';
5
6
  import { GT_ATTRIBUTES_WITH_SUGAR } from '../../constants.js';
6
7
  import generateModule from '@babel/generator';
@@ -85,6 +86,17 @@ function extractInlineMetadata({ options, output, config, }) {
85
86
  metadata[mappedKey] = Math.abs(Number(result.value));
86
87
  }
87
88
  }
89
+ else if (mappedKey === 'format') {
90
+ // Handle format attribute - validate allowed values
91
+ const validFormats = ['ICU', 'STRING', 'I18NEXT'];
92
+ if (typeof result.value === 'string' &&
93
+ validFormats.includes(result.value)) {
94
+ metadata[mappedKey] = result.value;
95
+ }
96
+ else {
97
+ output.warnings.add(warnInvalidFormatSync(config.file, String(result.value), `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
98
+ }
99
+ }
88
100
  else {
89
101
  // Add the $context or $id or other attributes value to the metadata
90
102
  // TODO: why are we including everything? arent we only interested in relevant inline metadata?
@@ -11,8 +11,9 @@ import { warnInvalidIcuSync } from '../../../../../console/index.js';
11
11
  export function handleLiteralTranslationCall({ arg, metadata, config, output, index, }) {
12
12
  // ignore dynamic content flag is triggered, check strings are valid ICU
13
13
  const source = arg.type === 'StringLiteral' ? arg.value : arg.quasis[0].value.raw;
14
- // Validate is ICU
15
- if (!config.ignoreInvalidIcu) {
14
+ // Validate is ICU — skip for non-ICU formats
15
+ if (!config.ignoreInvalidIcu &&
16
+ (!metadata.format || metadata.format === 'ICU')) {
16
17
  const { isValid, error } = isValidIcu(source);
17
18
  if (!isValid) {
18
19
  output.warnings.add(warnInvalidIcuSync(config.file, source, error ?? 'Unknown error', `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
@@ -20,7 +21,7 @@ export function handleLiteralTranslationCall({ arg, metadata, config, output, in
20
21
  }
21
22
  }
22
23
  output.updates.push({
23
- dataFormat: 'ICU',
24
+ dataFormat: (metadata.format || 'ICU'),
24
25
  source,
25
26
  metadata: {
26
27
  ...metadata,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt",
3
- "version": "2.13.1",
3
+ "version": "2.13.2",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -110,8 +110,8 @@
110
110
  "unified": "^11.0.5",
111
111
  "unist-util-visit": "^5.0.0",
112
112
  "yaml": "^2.8.0",
113
- "@generaltranslation/python-extractor": "0.2.2",
114
- "generaltranslation": "8.1.22",
113
+ "@generaltranslation/python-extractor": "0.2.3",
114
+ "generaltranslation": "8.1.23",
115
115
  "gt-remark": "1.0.6"
116
116
  },
117
117
  "devDependencies": {