@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.
Files changed (111) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +50 -75
  3. package/lib/cjs/index.js +437 -3269
  4. package/lib/cjs/index.js.map +1 -1
  5. package/lib/esm/index.js +436 -3266
  6. package/lib/esm/index.js.map +1 -1
  7. package/lib/types/index.d.ts +6 -130
  8. package/lib/types/index.d.ts.map +1 -1
  9. package/package.json +42 -93
  10. package/src/LanguageManage.tsx +25 -0
  11. package/src/LanguageOption.tsx +158 -0
  12. package/src/LanguagePatch.tsx +61 -0
  13. package/src/MenuButton.tsx +101 -0
  14. package/src/badges/index.tsx +23 -0
  15. package/src/constants.ts +1 -0
  16. package/src/hooks/useLanguageMetadata.tsx +21 -0
  17. package/src/hooks/useOpenInNewPane.tsx +27 -0
  18. package/src/index.ts +1 -0
  19. package/src/plugin.tsx +104 -0
  20. package/src/schema/translation/metadata.ts +42 -0
  21. package/src/types.ts +24 -0
  22. package/v2-incompatible.js +1 -1
  23. package/src/actions/DeleteWithi18nAction.tsx +0 -118
  24. package/src/actions/DuplicateWithi18nAction.tsx +0 -71
  25. package/src/actions/PublishWithi18nAction.ts +0 -124
  26. package/src/actions/index.ts +0 -43
  27. package/src/badges/LanguageBadge.tsx +0 -22
  28. package/src/constants/I18nDelimiter.ts +0 -1
  29. package/src/constants/I18nPrefix.ts +0 -1
  30. package/src/constants/IdStructure.ts +0 -4
  31. package/src/constants/LanguageCultures.ts +0 -902
  32. package/src/constants/ReferenceBehavior.ts +0 -5
  33. package/src/constants/SupportedEmojiFlagCodes.ts +0 -251
  34. package/src/constants/UiMessages.ts +0 -49
  35. package/src/constants/index.ts +0 -7
  36. package/src/documentI18n.tsx +0 -31
  37. package/src/hooks/index.ts +0 -2
  38. package/src/hooks/useConfig.ts +0 -22
  39. package/src/hooks/useDelayedFlag.ts +0 -31
  40. package/src/index.tsx +0 -6
  41. package/src/language-select/components/LanguageSelect/LanguageConfigContext.tsx +0 -4
  42. package/src/language-select/components/LanguageSelect/LanguageSelect.tsx +0 -188
  43. package/src/language-select/components/LanguageSelect/LanguageSelectContext.ts +0 -16
  44. package/src/language-select/components/LanguageSelect/LanguageSelectLabel.tsx +0 -12
  45. package/src/language-select/components/LanguageSelect/LanguageSelectList.tsx +0 -84
  46. package/src/language-select/components/LanguageSelect/LanguageSelectListItem.tsx +0 -251
  47. package/src/language-select/components/LanguageSelect/index.tsx +0 -26
  48. package/src/language-select/components/SingleFlag/SingleFlag.tsx +0 -44
  49. package/src/language-select/components/SingleFlag/allEmojiFlagCodes.ts +0 -251
  50. package/src/language-select/components/SingleFlag/index.ts +0 -1
  51. package/src/language-select/components/SplitPaneIcon/SplitPaneIcon.tsx +0 -25
  52. package/src/language-select/components/SplitPaneIcon/index.ts +0 -1
  53. package/src/language-select/components/index.ts +0 -2
  54. package/src/language-select/hooks/index.ts +0 -1
  55. package/src/language-select/hooks/useLanguages.ts +0 -37
  56. package/src/language-select/hooks/useListeningQuery.ts +0 -66
  57. package/src/structure/IDefaultDocumentNodeStructureProps.ts +0 -4
  58. package/src/structure/components/MaintenanceTab/MaintenanceTab.tsx +0 -13
  59. package/src/structure/components/MaintenanceTab/MaintenanceTabContent.tsx +0 -168
  60. package/src/structure/components/MaintenanceTab/index.ts +0 -1
  61. package/src/structure/components/MaintenanceTabResult/MaintenanceTabResult.tsx +0 -40
  62. package/src/structure/components/MaintenanceTabResult/index.ts +0 -1
  63. package/src/structure/components/MaintenanceTabTypeSelector/MaintenanceTabTypeSelector.tsx +0 -57
  64. package/src/structure/components/MaintenanceTabTypeSelector/index.ts +0 -1
  65. package/src/structure/hooks/index.ts +0 -1
  66. package/src/structure/hooks/useDocumentsInformation.ts +0 -117
  67. package/src/structure/index.tsx +0 -120
  68. package/src/structure/utils/fixBaseDocumentRefs.ts +0 -29
  69. package/src/structure/utils/fixBaseLanguageMismatch.ts +0 -22
  70. package/src/structure/utils/fixIdStructureMismatchDocuments.ts +0 -73
  71. package/src/structure/utils/fixLanguageFields.ts +0 -32
  72. package/src/structure/utils/fixOrphanedDocuments.ts +0 -15
  73. package/src/structure/utils/fixTranslationRefs.ts +0 -49
  74. package/src/structure/utils/index.ts +0 -6
  75. package/src/types/IEditState.ts +0 -6
  76. package/src/types/IExtendedLanguageObject.ts +0 -6
  77. package/src/types/ILanguageObject.ts +0 -4
  78. package/src/types/ILanguageQuery.ts +0 -13
  79. package/src/types/IResolverProps.ts +0 -10
  80. package/src/types/ITranslationRef.ts +0 -6
  81. package/src/types/IType.ts +0 -40
  82. package/src/types/IUseDocumentOperationResult.ts +0 -11
  83. package/src/types/TFieldNamesConfig.ts +0 -5
  84. package/src/types/TLanguage.ts +0 -3
  85. package/src/types/TLanguagesOption.ts +0 -4
  86. package/src/types/TSchema.ts +0 -6
  87. package/src/types/Ti18nConfig.ts +0 -33
  88. package/src/types/Ti18nDocument.ts +0 -14
  89. package/src/types/Ti18nSchema.ts +0 -6
  90. package/src/types/index.ts +0 -15
  91. package/src/utils/applyConfig.ts +0 -43
  92. package/src/utils/baseToTop.ts +0 -5
  93. package/src/utils/batch.ts +0 -11
  94. package/src/utils/buildDocId.ts +0 -8
  95. package/src/utils/createSanityReference.ts +0 -11
  96. package/src/utils/getBaseIdFromId.ts +0 -20
  97. package/src/utils/getBaseLanguage.ts +0 -6
  98. package/src/utils/getFlag.ts +0 -38
  99. package/src/utils/getLanguageFromDocument.ts +0 -9
  100. package/src/utils/getLanguageFromId.ts +0 -13
  101. package/src/utils/getLanguagesFromOption.ts +0 -40
  102. package/src/utils/getTranslationsForId.ts +0 -39
  103. package/src/utils/index.ts +0 -15
  104. package/src/utils/makeObjectKey.ts +0 -3
  105. package/src/utils/normalizeLanguageList.ts +0 -26
  106. package/src/utils/serializePath.ts +0 -11
  107. package/src/utils/updateIntlFieldsForDocument.ts +0 -79
  108. package/src/utils/useSanityClient.ts +0 -8
  109. package/src/validators/index.ts +0 -1
  110. package/src/validators/isSlugUnique.ts +0 -56
  111. package/src/withDocumentI18nPlugin.ts +0 -24
package/LICENSE CHANGED
@@ -1,7 +1,21 @@
1
- Copyright © 2020 Liam Martens
1
+ MIT License
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Copyright (c) 2022 Simeon Griggs
4
4
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
- # Document Internationalization Plugin for Sanity.io
1
+ # @sanity/document-internationalization
2
2
 
3
- > **NOTE**
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
- [![npm version](https://img.shields.io/npm/v/@sanity/document-internationalization.svg?style=flat)](https://www.npmjs.com/package/@sanity/document-internationalization)
10
-
11
- ![Document Level Internationalization UI](docs/img/document-level-translation.gif)
12
-
13
- ## What this plugin solves
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
- From the same directory as the Studio run:
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
- ```sh
62
- yarn add @sanity/document-internationalization@studio-v3
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 plugin is now installed, but you will need to complete the following steps to see the Document Translation UI:
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
- 1. [Known Caveats](docs/known-caveats.md)
79
- 2. [Data structure](docs/datastructure-intl-doc.md)
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
- ## Migrating from sanity-plugin-intl-input
54
+ // ...all other settings
55
+ defineField({
56
+ name: 'language',
57
+ type: 'string',
58
+ readOnly: true,
59
+ hidden: true,
60
+ })
61
+ ```
88
62
 
89
- While most of the UI is the same in the official version of this plugin there are some breaking changes you should be aware of before migrating:
63
+ ## License
90
64
 
91
- [Coming from sanity-plugin-intl-input](docs/coming-from-sanity-plugin-intl-input.md)
65
+ MIT © Simeon Griggs
66
+ See LICENSE