@sanity/document-internationalization 0.3.5 → 0.3.6
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/CHANGELOG.md +6 -0
- package/lib/actions/index.js +11 -15
- package/lib/actions/index.js.map +1 -1
- package/lib/badges/LanguageBadge.d.ts +1 -1
- package/lib/badges/index.js +6 -18
- package/lib/badges/index.js.map +1 -1
- package/lib/language-select/index.js +6 -13
- package/lib/language-select/index.js.map +1 -1
- package/lib/structure/index.js +8 -2
- package/lib/structure/index.js.map +1 -1
- package/lib/types/Ti18nConfig.d.ts +1 -1
- package/lib/utils/getLanguageFromDocument.d.ts +3 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +7 -2
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v0.3.6
|
|
4
|
+
* Updates the internal logic to derive the language from the given field name as opposed to the ID.
|
|
5
|
+
|
|
6
|
+
## v0.3.5
|
|
7
|
+
* Fix how translation draft references are created so that they can be deleted
|
|
8
|
+
|
|
3
9
|
## v0.3.4
|
|
4
10
|
* Updated docs regarding V3 studio
|
|
5
11
|
|
package/lib/actions/index.js
CHANGED
|
@@ -1811,17 +1811,6 @@ var getLanguagesFromOption = /*#__PURE__*/function () {
|
|
|
1811
1811
|
};
|
|
1812
1812
|
}();
|
|
1813
1813
|
|
|
1814
|
-
var getLanguageFromId = function getLanguageFromId(id) {
|
|
1815
|
-
// subpath
|
|
1816
|
-
var rx = new RegExp("".concat(I18nPrefix, "\\.[^.]+\\.([^.]+)"));
|
|
1817
|
-
var match = id.match(rx);
|
|
1818
|
-
if (match && match.length === 2) return match[1]; // delimiter
|
|
1819
|
-
|
|
1820
|
-
var split = id.split(I18nDelimiter);
|
|
1821
|
-
if (split.length > 1) return split[1];
|
|
1822
|
-
return null;
|
|
1823
|
-
};
|
|
1824
|
-
|
|
1825
1814
|
var getBaseIdFromId = function getBaseIdFromId(id) {
|
|
1826
1815
|
var nonDraftId = id.replace(/^drafts\./, ''); // subpath
|
|
1827
1816
|
|
|
@@ -1908,6 +1897,10 @@ function createSanityReference(id) {
|
|
|
1908
1897
|
} : {});
|
|
1909
1898
|
}
|
|
1910
1899
|
|
|
1900
|
+
function getLanguageFromDocument(doc, config) {
|
|
1901
|
+
return (doc === null || doc === void 0 ? void 0 : doc[config.fieldNames.lang]) || config.base || null;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1911
1904
|
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1912
1905
|
|
|
1913
1906
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -1940,7 +1933,7 @@ function _updateIntlFieldsForDocument() {
|
|
|
1940
1933
|
|
|
1941
1934
|
case 11:
|
|
1942
1935
|
langs = _context.sent;
|
|
1943
|
-
languageId =
|
|
1936
|
+
languageId = getLanguageFromDocument(document, config) || ((_getBaseLanguage = getBaseLanguage(langs, config.base)) === null || _getBaseLanguage === void 0 ? void 0 : _getBaseLanguage.id); // Update I18n field for current document
|
|
1944
1937
|
|
|
1945
1938
|
currentDocumentTransaction = client.transaction();
|
|
1946
1939
|
currentDocumentTransaction.createIfNotExists({
|
|
@@ -1975,7 +1968,7 @@ function _updateIntlFieldsForDocument() {
|
|
|
1975
1968
|
|
|
1976
1969
|
if (config.referenceBehavior !== ReferenceBehavior.DISABLED) {
|
|
1977
1970
|
translatedRefs = ___default["default"].compact(translatedDocuments.map(function (doc) {
|
|
1978
|
-
var lang =
|
|
1971
|
+
var lang = getLanguageFromDocument(doc, config);
|
|
1979
1972
|
if (!lang) return null;
|
|
1980
1973
|
return _objectSpread$1({
|
|
1981
1974
|
_key: lang
|
|
@@ -2334,6 +2327,9 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(_ref) {
|
|
|
2334
2327
|
draft = _ref.draft,
|
|
2335
2328
|
published = _ref.published;
|
|
2336
2329
|
var toast = ui.useToast();
|
|
2330
|
+
var config = React__default["default"].useMemo(function () {
|
|
2331
|
+
return getConfig(type);
|
|
2332
|
+
}, [type]);
|
|
2337
2333
|
var client = getSanityClient();
|
|
2338
2334
|
var baseDocumentId = getBaseIdFromId(id);
|
|
2339
2335
|
|
|
@@ -2367,7 +2363,7 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(_ref) {
|
|
|
2367
2363
|
translations.forEach(function (t) {
|
|
2368
2364
|
var isDraft = t._id.startsWith('drafts.');
|
|
2369
2365
|
|
|
2370
|
-
var newId = buildDocId(dupeId,
|
|
2366
|
+
var newId = buildDocId(dupeId, getLanguageFromDocument(t, config));
|
|
2371
2367
|
transaction.create(_objectSpread(_objectSpread({}, t), {}, {
|
|
2372
2368
|
_id: isDraft ? "drafts.".concat(newId) : newId
|
|
2373
2369
|
}));
|
|
@@ -2394,7 +2390,7 @@ var DuplicateWithi18nAction = function DuplicateWithi18nAction(_ref) {
|
|
|
2394
2390
|
}
|
|
2395
2391
|
}
|
|
2396
2392
|
}, _callee, null, [[1, 13]]);
|
|
2397
|
-
})), [client, toast, baseDocumentId, type, draft, published]);
|
|
2393
|
+
})), [client, toast, config, baseDocumentId, type, draft, published]);
|
|
2398
2394
|
return {
|
|
2399
2395
|
icon: ContentCopyIcon__default["default"],
|
|
2400
2396
|
disabled: Boolean(duplicateOp.disabled) || isDuplicating,
|