gt-sanity 3.1.2 → 3.1.4
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/README.md +87 -1
- package/dist/index.cjs +553 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +555 -170
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter/core.ts +31 -7
- package/src/adapter/types.ts +23 -1
- package/src/components/TranslationsProvider.tsx +149 -65
- package/src/components/page/DebugInfoDialog.tsx +142 -0
- package/src/components/page/TranslationsTable.tsx +7 -2
- package/src/components/page/TranslationsTool.tsx +29 -8
- package/src/components/shared/LanguageStatus.tsx +34 -15
- package/src/components/shared/SingleDocumentView.tsx +7 -2
- package/src/components/tab/TranslationView.tsx +88 -41
- package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.test.ts +84 -0
- package/src/index.ts +40 -3
- package/src/sanity-api/resolveRefs.ts +39 -0
- package/src/structure/__tests__/localizedStructure.test.ts +149 -0
- package/src/structure/localizedStructure.ts +156 -0
- package/src/utils/__tests__/debugInfo.test.ts +114 -0
- package/src/utils/__tests__/languageStatusState.test.ts +61 -0
- package/src/utils/__tests__/translationPreferences.test.ts +102 -0
- package/src/utils/__tests__/translationSummary.test.ts +88 -0
- package/src/utils/debugInfo.ts +116 -0
- package/src/utils/importUtils.ts +15 -6
- package/src/utils/languageStatusState.ts +25 -0
- package/src/utils/translationPreferences.ts +54 -0
- package/src/utils/translationSummary.ts +140 -0
- package/src/components/shared/ProgressBar.tsx +0 -54
package/README.md
CHANGED
|
@@ -136,7 +136,7 @@ Translation before a translation run, so content whose source text has not
|
|
|
136
136
|
changed is reused from the Sanity version instead of being regenerated.
|
|
137
137
|
|
|
138
138
|
This is **off by default**; turning it on shows an explanation of the trade-off
|
|
139
|
-
first, and the choice
|
|
139
|
+
first, and the choice is remembered for that project and dataset. Turning it on means local
|
|
140
140
|
content overwrites whatever General Translation holds for that source version —
|
|
141
141
|
including a completed translation that has not been imported into Sanity yet.
|
|
142
142
|
Import pending translations before enabling it if that matters to you.
|
|
@@ -157,3 +157,89 @@ enqueue any translation.
|
|
|
157
157
|
|
|
158
158
|
To regenerate translations and deliberately discard existing ones for a single
|
|
159
159
|
run, use **Retranslate from scratch** in the Translate All dialog.
|
|
160
|
+
|
|
161
|
+
## Automatic Actions
|
|
162
|
+
|
|
163
|
+
The Translate dialog on a document can refresh status, import a translation as
|
|
164
|
+
soon as it lands, repoint references, and publish the result. Each is a switch
|
|
165
|
+
in that dialog, and each has a plugin-level default:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
gtPlugin({
|
|
169
|
+
// ...
|
|
170
|
+
autoRefresh: true, // poll for completed translations
|
|
171
|
+
autoImport: true, // import a translation as soon as it completes
|
|
172
|
+
autoPatchReferences: false, // repoint references after import
|
|
173
|
+
autoPublish: false, // publish translated documents after import
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The defaults turn on what only reads or writes drafts, and leave off anything
|
|
178
|
+
that can reach readers:
|
|
179
|
+
|
|
180
|
+
- `autoRefresh` only polls for status, and auto-import depends on it.
|
|
181
|
+
- `autoImport` writes drafts, which are cheap to discard.
|
|
182
|
+
- `autoPatchReferences` usually writes a draft too, but when a translated
|
|
183
|
+
document is already published and has no draft, the reference rewrite is
|
|
184
|
+
applied to a draft seeded from it rather than to the published document.
|
|
185
|
+
Still opt-in, because it edits documents you may consider finished.
|
|
186
|
+
- `autoPublish` publishes, and turning the switch back off unpublishes nothing.
|
|
187
|
+
|
|
188
|
+
These are starting points, not locks. Whatever the user sets in the Studio is
|
|
189
|
+
remembered in `localStorage` for that project and dataset, and is preferred
|
|
190
|
+
over the config on their next visit. The **Save local edits** toggle
|
|
191
|
+
(`preserveExistingTranslations`) is remembered the same way; enabling it still
|
|
192
|
+
shows its explanation first.
|
|
193
|
+
|
|
194
|
+
Translated documents are always created as **drafts**. With `autoPublish` off
|
|
195
|
+
they stay that way until someone publishes them — so if a translation seems
|
|
196
|
+
missing after a run, check the Drafts perspective before assuming it wasn't
|
|
197
|
+
created.
|
|
198
|
+
|
|
199
|
+
## Browsing Translations by Locale
|
|
200
|
+
|
|
201
|
+
By default a translated document sits in the same list as its source, so a
|
|
202
|
+
type's list grows by one entry per locale. `gtStructureItems` groups them
|
|
203
|
+
instead: each translatable type expands into a pane per locale.
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { structureTool } from 'sanity/structure';
|
|
207
|
+
import { gtStructureItems } from 'gt-sanity';
|
|
208
|
+
|
|
209
|
+
structureTool({
|
|
210
|
+
structure: (S, context) =>
|
|
211
|
+
S.list()
|
|
212
|
+
.title('Content')
|
|
213
|
+
.items([
|
|
214
|
+
...gtStructureItems(S, context),
|
|
215
|
+
S.divider(),
|
|
216
|
+
...S.documentTypeListItems(),
|
|
217
|
+
]),
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
This is opt-in: the structure tool's layout belongs to `structureTool()` in
|
|
222
|
+
your Studio config, so a plugin cannot set it for you. Use `gtStructure()` for
|
|
223
|
+
the whole structure when you have no other list items:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { gtStructure } from 'gt-sanity';
|
|
227
|
+
|
|
228
|
+
structureTool({ structure: gtStructure() });
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
The source pane includes documents whose language field is unset, since content
|
|
232
|
+
that predates the plugin has no language. Types localized in place with
|
|
233
|
+
internationalized arrays are skipped — their translations live inside the source
|
|
234
|
+
document, so there is nothing to group. Pass `types` to override which types are
|
|
235
|
+
grouped, and `sourceTitle` / `localeTitle` to change the pane titles.
|
|
236
|
+
|
|
237
|
+
## Debug Info
|
|
238
|
+
|
|
239
|
+
The Translations tool footer shows the installed plugin version and a **Debug
|
|
240
|
+
info** button. It opens the plugin's effective configuration — resolved source
|
|
241
|
+
and target locales, `translationLevel`, which documents are matched, field
|
|
242
|
+
rules, the active preferences, and whether the secrets document was found — with
|
|
243
|
+
a button to copy it for a support request.
|
|
244
|
+
|
|
245
|
+
The API key is never included, only whether one is set.
|