gt-sanity 2.1.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +84 -0
  2. package/dist/index.cjs +627 -1807
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +95 -76
  5. package/dist/index.d.ts +95 -76
  6. package/dist/index.js +582 -1775
  7. package/dist/index.js.map +1 -1
  8. package/package.json +3 -2
  9. package/src/adapter/core.ts +2 -10
  10. package/src/components/TranslationsProvider.tsx +2 -2
  11. package/src/components/page/ImportAllDialog.tsx +1 -1
  12. package/src/components/page/ImportMissingDialog.tsx +1 -5
  13. package/src/components/page/TranslateAllDialog.tsx +1 -5
  14. package/src/components/page/TranslationsTable.tsx +91 -58
  15. package/src/components/page/TranslationsTool.tsx +156 -209
  16. package/src/components/shared/BaseTranslationWrapper.tsx +10 -1
  17. package/src/components/shared/LanguageStatus.tsx +34 -34
  18. package/src/components/shared/LocaleCheckbox.tsx +5 -13
  19. package/src/components/shared/LocaleLabel.tsx +38 -0
  20. package/src/components/shared/ProgressBar.tsx +34 -20
  21. package/src/components/shared/SingleDocumentView.tsx +1 -1
  22. package/src/components/tab/TranslationView.tsx +45 -26
  23. package/src/index.ts +86 -31
  24. package/src/schema/__tests__/fieldLevelConfig.test.ts +115 -0
  25. package/src/schema/__tests__/schemaOptions.test.ts +17 -0
  26. package/src/schema/fieldLevelConfig.ts +126 -0
  27. package/src/schema/schemaOptions.ts +32 -0
  28. package/src/serialization/__tests__/BaseDocumentSerializer/optionsExclusion.test.ts +294 -0
  29. package/src/serialization/internationalizedArray/__tests__/internationalizedArray.test.ts +9 -17
  30. package/src/serialization/internationalizedArray/__tests__/serializeRoundTrip.test.ts +26 -6
  31. package/src/serialization/internationalizedArray/detect.ts +6 -18
  32. package/src/serialization/serialize/fieldFilters.ts +82 -11
  33. package/src/serialization/serialize/index.ts +140 -38
  34. package/src/utils/localeDisplay.ts +78 -0
  35. package/src/schema/InternationalizedArrayInput.tsx +0 -278
  36. package/src/schema/__tests__/createInternationalizedArrayTypes.test.ts +0 -169
  37. package/src/schema/createInternationalizedArrayTypes.ts +0 -209
  38. package/src/schema/types.ts +0 -84
package/README.md CHANGED
@@ -41,3 +41,87 @@ export default defineConfig({
41
41
  ```
42
42
 
43
43
  See the [full documentation](https://generaltranslation.com/docs/sanity) for guides and API reference.
44
+
45
+ ## Field-Level Localization
46
+
47
+ Field-level localization is powered by
48
+ [`sanity-plugin-internationalized-array`](https://github.com/sanity-io/sanity-plugin-internationalized-array) —
49
+ the reference Sanity plugin. `gtPlugin` configures it for you from your
50
+ locales; gt-sanity does not ship its own field-level UI, so Studio behavior
51
+ always matches the native plugin.
52
+
53
+ ```ts
54
+ gtPlugin({
55
+ sourceLocale: 'en',
56
+ locales: ['es', 'fr'],
57
+ translateDocuments: ['post'],
58
+ // Documents matched above are localized in place with
59
+ // internationalized arrays instead of per-locale documents.
60
+ translationLevel: 'internationalizedArray',
61
+ fieldLevelLocalization: {
62
+ enabled: true,
63
+ fieldTypes: ['string', 'text'],
64
+ },
65
+ });
66
+ ```
67
+
68
+ Then use the generated types in your schemas
69
+ (`type: 'internationalizedArrayString'`, etc.).
70
+
71
+ ### Bringing your own plugin instance
72
+
73
+ Already registering `sanity-plugin-internationalized-array` yourself? Keep
74
+ your setup — GT translation only reads and writes the stored
75
+ `{ _key, _type, language, value }` data, regardless of who registered the
76
+ schema types. Leave `fieldLevelLocalization` disabled so the types are only
77
+ registered once, and just opt the documents into field-level translation:
78
+
79
+ ```ts
80
+ plugins: [
81
+ internationalizedArray({
82
+ languages: [
83
+ { id: 'en', title: 'English' },
84
+ { id: 'es', title: 'Spanish' },
85
+ ],
86
+ fieldTypes: ['string'],
87
+ }),
88
+ gtPlugin({
89
+ sourceLocale: 'en',
90
+ locales: ['es'],
91
+ translateDocuments: ['post'],
92
+ translationLevel: 'internationalizedArray',
93
+ // No fieldLevelLocalization — your plugin instance owns the types.
94
+ }),
95
+ ],
96
+ ```
97
+
98
+ To verify: open a document of a matched type, run Translate from the
99
+ document actions menu (or the Translations tool), and confirm each localized
100
+ field gains items for the target locales while the Studio UI (per-language
101
+ add buttons, language labels) stays exactly as your plugin configures it.
102
+
103
+ ## Excluding Fields from Translation
104
+
105
+ Mark fields in your schema instead of maintaining a list in the plugin
106
+ config. gt-sanity honors its own `options.gt.exclude` plus the exclusion
107
+ options of the standard Sanity localization plugins:
108
+
109
+ ```ts
110
+ defineField({
111
+ name: 'internalNotes',
112
+ type: 'string',
113
+ options: {
114
+ gt: { exclude: true }, // excluded from GT translation
115
+ // Also honored:
116
+ // documentInternationalization: { exclude: true }, // @sanity/document-internationalization
117
+ // aiAssist: { exclude: true }, // @sanity/assist
118
+ },
119
+ });
120
+ ```
121
+
122
+ Exclusion applies at any depth, including fields of nested object types, and
123
+ can also be set on a custom type definition's `options` to exclude every
124
+ occurrence of that type (matching the native plugins' "field or type"
125
+ semantics). The legacy `localize: false` field property is still supported. For id-based or
126
+ cross-document rules (e.g. slug deduplication), the plugin-level
127
+ `ignoreFields` / `skipFields` / `dedupeFields` options remain available.