@sanity/document-internationalization 1.0.0-v3-studio.7 → 1.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.
- package/LICENSE +18 -4
- package/README.md +50 -75
- package/lib/cjs/index.js +437 -3269
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +436 -3266
- package/lib/esm/index.js.map +1 -1
- package/lib/types/index.d.ts +6 -130
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +42 -93
- package/src/LanguageManage.tsx +25 -0
- package/src/LanguageOption.tsx +158 -0
- package/src/LanguagePatch.tsx +61 -0
- package/src/MenuButton.tsx +101 -0
- package/src/badges/index.tsx +23 -0
- package/src/constants.ts +1 -0
- package/src/hooks/useLanguageMetadata.tsx +21 -0
- package/src/hooks/useOpenInNewPane.tsx +27 -0
- package/src/index.ts +1 -0
- package/src/plugin.tsx +104 -0
- package/src/schema/translation/metadata.ts +42 -0
- package/src/types.ts +24 -0
- package/v2-incompatible.js +1 -1
- package/src/actions/DeleteWithi18nAction.tsx +0 -118
- package/src/actions/DuplicateWithi18nAction.tsx +0 -71
- package/src/actions/PublishWithi18nAction.ts +0 -124
- package/src/actions/index.ts +0 -43
- package/src/badges/LanguageBadge.tsx +0 -22
- package/src/constants/I18nDelimiter.ts +0 -1
- package/src/constants/I18nPrefix.ts +0 -1
- package/src/constants/IdStructure.ts +0 -4
- package/src/constants/LanguageCultures.ts +0 -902
- package/src/constants/ReferenceBehavior.ts +0 -5
- package/src/constants/SupportedEmojiFlagCodes.ts +0 -251
- package/src/constants/UiMessages.ts +0 -49
- package/src/constants/index.ts +0 -7
- package/src/documentI18n.tsx +0 -31
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useConfig.ts +0 -22
- package/src/hooks/useDelayedFlag.ts +0 -31
- package/src/index.tsx +0 -6
- package/src/language-select/components/LanguageSelect/LanguageConfigContext.tsx +0 -4
- package/src/language-select/components/LanguageSelect/LanguageSelect.tsx +0 -188
- package/src/language-select/components/LanguageSelect/LanguageSelectContext.ts +0 -16
- package/src/language-select/components/LanguageSelect/LanguageSelectLabel.tsx +0 -12
- package/src/language-select/components/LanguageSelect/LanguageSelectList.tsx +0 -84
- package/src/language-select/components/LanguageSelect/LanguageSelectListItem.tsx +0 -251
- package/src/language-select/components/LanguageSelect/index.tsx +0 -26
- package/src/language-select/components/SingleFlag/SingleFlag.tsx +0 -44
- package/src/language-select/components/SingleFlag/allEmojiFlagCodes.ts +0 -251
- package/src/language-select/components/SingleFlag/index.ts +0 -1
- package/src/language-select/components/SplitPaneIcon/SplitPaneIcon.tsx +0 -25
- package/src/language-select/components/SplitPaneIcon/index.ts +0 -1
- package/src/language-select/components/index.ts +0 -2
- package/src/language-select/hooks/index.ts +0 -1
- package/src/language-select/hooks/useLanguages.ts +0 -37
- package/src/language-select/hooks/useListeningQuery.ts +0 -66
- package/src/structure/IDefaultDocumentNodeStructureProps.ts +0 -4
- package/src/structure/components/MaintenanceTab/MaintenanceTab.tsx +0 -13
- package/src/structure/components/MaintenanceTab/MaintenanceTabContent.tsx +0 -168
- package/src/structure/components/MaintenanceTab/index.ts +0 -1
- package/src/structure/components/MaintenanceTabResult/MaintenanceTabResult.tsx +0 -40
- package/src/structure/components/MaintenanceTabResult/index.ts +0 -1
- package/src/structure/components/MaintenanceTabTypeSelector/MaintenanceTabTypeSelector.tsx +0 -57
- package/src/structure/components/MaintenanceTabTypeSelector/index.ts +0 -1
- package/src/structure/hooks/index.ts +0 -1
- package/src/structure/hooks/useDocumentsInformation.ts +0 -117
- package/src/structure/index.tsx +0 -120
- package/src/structure/utils/fixBaseDocumentRefs.ts +0 -29
- package/src/structure/utils/fixBaseLanguageMismatch.ts +0 -22
- package/src/structure/utils/fixIdStructureMismatchDocuments.ts +0 -73
- package/src/structure/utils/fixLanguageFields.ts +0 -32
- package/src/structure/utils/fixOrphanedDocuments.ts +0 -15
- package/src/structure/utils/fixTranslationRefs.ts +0 -49
- package/src/structure/utils/index.ts +0 -6
- package/src/types/IEditState.ts +0 -6
- package/src/types/IExtendedLanguageObject.ts +0 -6
- package/src/types/ILanguageObject.ts +0 -4
- package/src/types/ILanguageQuery.ts +0 -13
- package/src/types/IResolverProps.ts +0 -10
- package/src/types/ITranslationRef.ts +0 -6
- package/src/types/IType.ts +0 -40
- package/src/types/IUseDocumentOperationResult.ts +0 -11
- package/src/types/TFieldNamesConfig.ts +0 -5
- package/src/types/TLanguage.ts +0 -3
- package/src/types/TLanguagesOption.ts +0 -4
- package/src/types/TSchema.ts +0 -6
- package/src/types/Ti18nConfig.ts +0 -33
- package/src/types/Ti18nDocument.ts +0 -14
- package/src/types/Ti18nSchema.ts +0 -6
- package/src/types/index.ts +0 -15
- package/src/utils/applyConfig.ts +0 -43
- package/src/utils/baseToTop.ts +0 -5
- package/src/utils/batch.ts +0 -11
- package/src/utils/buildDocId.ts +0 -8
- package/src/utils/createSanityReference.ts +0 -11
- package/src/utils/getBaseIdFromId.ts +0 -20
- package/src/utils/getBaseLanguage.ts +0 -6
- package/src/utils/getFlag.ts +0 -38
- package/src/utils/getLanguageFromDocument.ts +0 -9
- package/src/utils/getLanguageFromId.ts +0 -13
- package/src/utils/getLanguagesFromOption.ts +0 -40
- package/src/utils/getTranslationsForId.ts +0 -39
- package/src/utils/index.ts +0 -15
- package/src/utils/makeObjectKey.ts +0 -3
- package/src/utils/normalizeLanguageList.ts +0 -26
- package/src/utils/serializePath.ts +0 -11
- package/src/utils/updateIntlFieldsForDocument.ts +0 -79
- package/src/utils/useSanityClient.ts +0 -8
- package/src/validators/index.ts +0 -1
- package/src/validators/isSlugUnique.ts +0 -56
- package/src/withDocumentI18nPlugin.ts +0 -24
package/LICENSE
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2022 Simeon Griggs
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,91 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sanity/document-internationalization
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
>
|
|
5
|
-
> This is the **Sanity Studio v3 version** of Document Internationalization Plugin.
|
|
6
|
-
>
|
|
7
|
-
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/document-internationalization).
|
|
3
|
+
This is a complete rewrite of the original v0 Document Internationalization plugin, exclusively for Sanity Studio v3. The major differences include:
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
There are two popular methods of internationalization in Sanity Studio:
|
|
16
|
-
|
|
17
|
-
- **Document-level translation**
|
|
18
|
-
- A unique document version for every language
|
|
19
|
-
- Joined together by references and/or a predictable `_id`
|
|
20
|
-
- Best for documents that have unique, language-specific fields and no common content across languages
|
|
21
|
-
- Best for translating content using Portable Text
|
|
22
|
-
- **Field-level translation**
|
|
23
|
-
- A single document with many languages of content
|
|
24
|
-
- Achieved by mapping over languages on each field, to create an object
|
|
25
|
-
- Best for documents that have a mix of language-specific and common fields
|
|
26
|
-
- Not recommended for Portable Text
|
|
27
|
-
|
|
28
|
-
This plugin adds features to the Studio to improve handling **document-level translations**.
|
|
29
|
-
|
|
30
|
-
- A Language Selector to create and browse language-specific versions of each Document
|
|
31
|
-
- Document Actions to update base and translated documents to ensure references stay in tact
|
|
32
|
-
- Document Badges to highlight the language version of a document
|
|
33
|
-
|
|
34
|
-
For **field-level translations** you should use the [@sanity/language-filter plugin](https://www.npmjs.com/package/@sanity/language-filter).
|
|
35
|
-
|
|
36
|
-
*Studio V3 note*: language-filter is not available for V3 yet.
|
|
37
|
-
|
|
38
|
-
### Many projects use both!
|
|
39
|
-
|
|
40
|
-
*Studio V3 note*: language-filter is not available for V3 yet.
|
|
41
|
-
|
|
42
|
-
An example of document-level translation could be a `lesson` schema, the `title`, `slug` and `content` fields would be unique in every language.
|
|
43
|
-
|
|
44
|
-
A good use of field-level translation could be a `person` schema. It could have the same `name` and `image` in every language, but only the `biography` would need translating.
|
|
45
|
-
|
|
46
|
-
## Studio V3 known issues
|
|
47
|
-
|
|
48
|
-
Studio V3 does not implement language-filter yet. This means that the language button has moved into the document editor flow for the time being.
|
|
49
|
-
We will be looking to restore the button placement during Studio V3 dev-preview.
|
|
5
|
+
- Start new documents in any language and create references later
|
|
6
|
+
- Storing translation references in a separate "meta" document
|
|
7
|
+
- Updates to one document no longer effect the change history of other translations
|
|
8
|
+
- No use of Document Actions
|
|
9
|
+
- Configurable "language" field on documents
|
|
50
10
|
|
|
51
11
|
## Installation
|
|
52
12
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
```sh
|
|
56
|
-
npm install --save @sanity/document-internationalization@studio-v3
|
|
13
|
+
```
|
|
14
|
+
npm install --save @sanity/document-internationalization
|
|
57
15
|
```
|
|
58
16
|
|
|
59
17
|
or
|
|
60
18
|
|
|
61
|
-
```
|
|
62
|
-
yarn add @sanity/document-internationalization
|
|
19
|
+
```
|
|
20
|
+
yarn add @sanity/document-internationalization
|
|
63
21
|
```
|
|
64
22
|
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Add it as a plugin in sanity.config.ts (or .js):
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import {createConfig} from 'sanity'
|
|
29
|
+
import {documentInternationalization} from '@sanity/document-internationalization'
|
|
30
|
+
|
|
31
|
+
export const createConfig({
|
|
32
|
+
// ...
|
|
33
|
+
plugins: [
|
|
34
|
+
documentInternationalization({
|
|
35
|
+
// Required
|
|
36
|
+
supportedLanguages: [
|
|
37
|
+
{id: 'nb', title: 'Norwegian (Bokmål)'},
|
|
38
|
+
{id: 'nn', title: 'Norwegian (Nynorsk)'},
|
|
39
|
+
{id: 'en', title: 'English'}
|
|
40
|
+
],
|
|
41
|
+
schemaTypes: ['product', 'post'],
|
|
42
|
+
// Optional
|
|
43
|
+
languageField: `language` // defauts to "language"
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
})
|
|
47
|
+
```
|
|
65
48
|
|
|
66
|
-
The
|
|
67
|
-
|
|
68
|
-
## Setup next steps
|
|
69
|
-
1. [Enabling and configuring the plugin](docs/enabling-and-configuring.md)
|
|
70
|
-
To declare available Languages and other settings
|
|
71
|
-
2. [Activating internationalization on schema](docs/activating-internationalization-on-schema.md)
|
|
72
|
-
To enable all the above features on schema
|
|
73
|
-
3. [Customise Desk Structure](docs/desk-structure.md)
|
|
74
|
-
To filter documents down to the base language version
|
|
75
|
-
|
|
76
|
-
## Other documentation
|
|
49
|
+
The schema types that use document internationalization should also have a string field with the same name configured in the `languageField` setting. You can hide this field since the plugin will handle writing patches to it.
|
|
77
50
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
3. [Translation Maintenance](docs/translation-maintenance.md)
|
|
81
|
-
4. [GraphQL support](docs/graphql-intl-doc.md)
|
|
82
|
-
5. [Advanced languages](docs/advanced-languages.md)
|
|
83
|
-
6. [Usage with custom publish action](docs/usage-with-custom-publish.md)
|
|
84
|
-
7. [If you don't see the plugin document actions](docs/usage-with-custom-publish.md#add-additional-actions)
|
|
85
|
-
8. [GROQ query examples](/docs/groq-query-examples.md)
|
|
51
|
+
```ts
|
|
52
|
+
// ./schema/product.ts
|
|
86
53
|
|
|
87
|
-
|
|
54
|
+
// ...all other settings
|
|
55
|
+
defineField({
|
|
56
|
+
name: 'language',
|
|
57
|
+
type: 'string',
|
|
58
|
+
readOnly: true,
|
|
59
|
+
hidden: true,
|
|
60
|
+
})
|
|
61
|
+
```
|
|
88
62
|
|
|
89
|
-
|
|
63
|
+
## License
|
|
90
64
|
|
|
91
|
-
|
|
65
|
+
MIT © Simeon Griggs
|
|
66
|
+
See LICENSE
|