gt-sanity 2.1.5 → 3.1.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 (54) hide show
  1. package/README.md +116 -0
  2. package/dist/index.cjs +1170 -1905
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +96 -76
  5. package/dist/index.d.ts +96 -76
  6. package/dist/index.js +1130 -1878
  7. package/dist/index.js.map +1 -1
  8. package/package.json +3 -2
  9. package/src/adapter/core.ts +7 -7
  10. package/src/components/TranslationsProvider.tsx +173 -48
  11. package/src/components/page/ImportAllDialog.tsx +1 -1
  12. package/src/components/page/ImportMissingDialog.tsx +1 -5
  13. package/src/components/page/SaveLocalTranslationsDialog.tsx +60 -0
  14. package/src/components/page/TranslateAllDialog.tsx +63 -16
  15. package/src/components/page/TranslationsTable.tsx +91 -58
  16. package/src/components/page/TranslationsTool.tsx +212 -209
  17. package/src/components/page/UploadExistingDialog.tsx +52 -0
  18. package/src/components/shared/BaseTranslationWrapper.tsx +10 -1
  19. package/src/components/shared/LanguageStatus.tsx +34 -34
  20. package/src/components/shared/LocaleCheckbox.tsx +5 -13
  21. package/src/components/shared/LocaleLabel.tsx +38 -0
  22. package/src/components/shared/ProgressBar.tsx +34 -20
  23. package/src/components/shared/SingleDocumentView.tsx +1 -1
  24. package/src/components/tab/TranslationView.tsx +94 -26
  25. package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +2 -1
  26. package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +2 -1
  27. package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +11 -6
  28. package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +6 -2
  29. package/src/index.ts +94 -30
  30. package/src/sanity-api/resolveRefs.ts +8 -3
  31. package/src/schema/__tests__/fieldLevelConfig.test.ts +115 -0
  32. package/src/schema/__tests__/schemaOptions.test.ts +17 -0
  33. package/src/schema/fieldLevelConfig.ts +126 -0
  34. package/src/schema/schemaOptions.ts +32 -0
  35. package/src/serialization/__tests__/BaseDocumentSerializer/optionsExclusion.test.ts +294 -0
  36. package/src/serialization/internationalizedArray/__tests__/internationalizedArray.test.ts +9 -17
  37. package/src/serialization/internationalizedArray/__tests__/serializeRoundTrip.test.ts +26 -6
  38. package/src/serialization/internationalizedArray/detect.ts +27 -18
  39. package/src/serialization/serialize/fieldFilters.ts +82 -11
  40. package/src/serialization/serialize/index.ts +140 -38
  41. package/src/translation/__tests__/captureExistingTranslations.test.ts +167 -0
  42. package/src/translation/__tests__/collectExistingTranslations.test.ts +231 -0
  43. package/src/translation/__tests__/initProject.test.ts +109 -0
  44. package/src/translation/captureExistingTranslations.ts +111 -0
  45. package/src/translation/collectExistingTranslations.ts +199 -0
  46. package/src/translation/createJobs.ts +7 -1
  47. package/src/translation/initProject.ts +18 -35
  48. package/src/translation/uploadTranslations.ts +54 -0
  49. package/src/utils/localeDisplay.ts +78 -0
  50. package/src/utils/translationMetadata.ts +38 -0
  51. package/src/schema/InternationalizedArrayInput.tsx +0 -278
  52. package/src/schema/__tests__/createInternationalizedArrayTypes.test.ts +0 -169
  53. package/src/schema/createInternationalizedArrayTypes.ts +0 -209
  54. package/src/schema/types.ts +0 -84
package/README.md CHANGED
@@ -41,3 +41,119 @@ 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.
128
+
129
+ ## Preserving Edits to Translations
130
+
131
+ Translated content often gets touched up in the Studio after it comes back from
132
+ General Translation, and a later translation run would normally regenerate it.
133
+ The **Save local edits** toggle in the Translations tool changes that:
134
+ with it on, the translations currently in Sanity are uploaded to General
135
+ Translation before a translation run, so content whose source text has not
136
+ changed is reused from the Sanity version instead of being regenerated.
137
+
138
+ This is **off by default**; turning it on shows an explanation of the trade-off
139
+ first, and the choice lasts for the Studio session. Turning it on means local
140
+ content overwrites whatever General Translation holds for that source version —
141
+ including a completed translation that has not been imported into Sanity yet.
142
+ Import pending translations before enabling it if that matters to you.
143
+
144
+ Set the initial state of the toggle from plugin config:
145
+
146
+ ```ts
147
+ gtPlugin({
148
+ // ...
149
+ preserveExistingTranslations: true,
150
+ });
151
+ ```
152
+
153
+ To upload the translations already in Sanity without starting a translation run
154
+ — useful when adopting the plugin on a project that was translated elsewhere —
155
+ use **Save Local Edits**. It uploads the source files it needs, but does not
156
+ enqueue any translation.
157
+
158
+ To regenerate translations and deliberately discard existing ones for a single
159
+ run, use **Retranslate from scratch** in the Translate All dialog.