sanity-plugin-transifex 2.0.6 → 3.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 (35) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +84 -84
  3. package/dist/index.d.ts +52 -11
  4. package/dist/index.esm.js +192 -0
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/index.js +251 -7
  7. package/dist/index.js.map +1 -0
  8. package/package.json +87 -48
  9. package/sanity.json +8 -0
  10. package/src/index.ts +14 -19
  11. package/src/transifexAdapter/createTask.ts +12 -17
  12. package/src/transifexAdapter/getLocales.ts +10 -11
  13. package/src/transifexAdapter/getTranslation.ts +48 -60
  14. package/src/transifexAdapter/getTranslationTask.ts +12 -19
  15. package/src/transifexAdapter/helpers.ts +3 -3
  16. package/src/transifexAdapter/index.ts +5 -5
  17. package/v2-incompatible.js +11 -0
  18. package/.github/workflows/main.yml +0 -29
  19. package/.github/workflows/npm-publish.yml +0 -19
  20. package/dist/sanity-plugin-transifex.cjs.development.js +0 -903
  21. package/dist/sanity-plugin-transifex.cjs.development.js.map +0 -1
  22. package/dist/sanity-plugin-transifex.cjs.production.min.js +0 -2
  23. package/dist/sanity-plugin-transifex.cjs.production.min.js.map +0 -1
  24. package/dist/sanity-plugin-transifex.esm.js +0 -844
  25. package/dist/sanity-plugin-transifex.esm.js.map +0 -1
  26. package/dist/transifexAdapter/createTask.d.ts +0 -6
  27. package/dist/transifexAdapter/getLocales.d.ts +0 -2
  28. package/dist/transifexAdapter/getTranslation.d.ts +0 -2
  29. package/dist/transifexAdapter/getTranslationTask.d.ts +0 -6
  30. package/dist/transifexAdapter/helpers.d.ts +0 -7
  31. package/dist/transifexAdapter/index.d.ts +0 -2
  32. package/test/directives.test.ts +0 -155
  33. package/test/localeId.test.ts +0 -17
  34. package/test/mergeTranslation.test.ts +0 -113
  35. package/tsconfig.json +0 -35
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanity-plugin-transifex.esm.js","sources":["../src/transifexAdapter/helpers.ts","../src/transifexAdapter/getLocales.ts","../src/transifexAdapter/getTranslationTask.ts","../src/transifexAdapter/getTranslation.ts","../src/transifexAdapter/createTask.ts","../src/transifexAdapter/index.ts","../src/index.ts"],"sourcesContent":["import { Secrets } from 'sanity-translations-tab'\n\nexport const baseTransifexUrl = 'https://rest.api.transifex.com'\n\nexport const getHeaders = (secrets: Secrets | null) => ({\n Authorization: `Bearer ${secrets?.token}`,\n 'Content-Type': 'application/vnd.api+json',\n})\n\nexport const projOrgSlug = (secrets: Secrets | null) =>\n `o:${secrets?.organization}:p:${secrets?.project}`\n","import { Secrets } from 'sanity-translations-tab'\nimport { baseTransifexUrl, projOrgSlug, getHeaders } from './helpers'\n\nexport default async function getLocales(secrets: Secrets | null) {\n if (secrets) {\n return fetch(\n `${baseTransifexUrl}/projects/${projOrgSlug(secrets)}/languages`,\n { headers: getHeaders(secrets) }\n )\n .then(res => res.json())\n .then(res =>\n res.data.map((lang: Record<string, any>) => ({\n enabled: true,\n description: lang.attributes.name,\n localeId: lang.attributes.code,\n }))\n )\n } else {\n return []\n }\n}\n","import { Secrets } from 'sanity-translations-tab'\nimport { baseTransifexUrl, projOrgSlug, getHeaders } from './helpers'\nimport getLocales from './getLocales'\n\nexport default async function getTranslationTask(\n documentId: string,\n secrets: Secrets | null\n) {\n if (!documentId || !secrets) {\n return {\n taskId: documentId,\n documentId: documentId,\n locales: [],\n }\n }\n const projectFilter = `filter[project]=${projOrgSlug(secrets)}`\n const resourceFilter = `filter[resource]=${projOrgSlug(\n secrets\n )}:r:${documentId}`\n const task = await fetch(\n `${baseTransifexUrl}/resource_language_stats?${projectFilter}&${resourceFilter}`,\n { headers: getHeaders(secrets) }\n )\n .then(res => {\n if (res.ok) {\n return res.json()\n }\n //normal -- just means that this task doesn't exist yet.\n else if (res.status === 404) {\n return { data: [] }\n } else {\n throw Error(\n `Failed to retrieve tasks from Transifex. Status: ${res.status}`\n )\n }\n })\n .then(res => ({\n taskId: `${projOrgSlug(secrets)}:r:${documentId}`,\n documentId: documentId,\n locales: res.data.map((locale: Record<string, any>) => ({\n localeId: locale.relationships.language.data.id.split(':')[1],\n progress: Math.floor(\n 100 *\n (locale.attributes.reviewed_strings /\n parseFloat(locale.attributes.total_strings))\n ),\n })),\n }))\n\n const locales = await getLocales(secrets)\n const localeIds = locales.map((l: Record<string, any>) => l.localeId)\n const validLocales = task.locales.filter((locale: Record<string, any>) =>\n localeIds.find((id: string) => id === locale.localeId)\n )\n task.locales = validLocales\n\n return task\n}\n","import { Secrets } from 'sanity-translations-tab'\nimport { baseTransifexUrl, getHeaders } from './helpers'\n\nexport default async function getTranslation(\n taskId: string,\n localeId: string,\n secrets: Secrets | null\n) {\n const resourceDownloadBody = {\n data: {\n attributes: {\n content_encoding: 'text',\n },\n relationships: {\n language: {\n data: {\n id: `l:${localeId}`,\n type: 'languages',\n },\n },\n resource: {\n data: {\n id: taskId,\n type: 'resources',\n },\n },\n },\n type: 'resource_translations_async_downloads',\n },\n }\n\n const resourceDownloadUrl = `${baseTransifexUrl}/resource_translations_async_downloads`\n const translationDownloadId = await fetch(resourceDownloadUrl, {\n headers: getHeaders(secrets),\n method: 'POST',\n body: JSON.stringify(resourceDownloadBody),\n })\n .then(res => res.json())\n .then(res => res.data.id)\n\n const headers = getHeaders(secrets)\n const location = await pollForFileDownloadLocation(\n resourceDownloadUrl,\n translationDownloadId,\n headers\n )\n return handleFileDownload(location)\n}\n\nconst pollForFileDownloadLocation = async (\n resourceDownloadUrl: string,\n translationDownloadId: string,\n headers: Record<string, any>\n): Promise<string> => {\n const response = await fetch(\n `${resourceDownloadUrl}/${translationDownloadId}`,\n {\n headers: headers,\n }\n )\n\n if (response.status === 500) {\n console.info(\n `Transifex plugin message: Received 500 for translation download ID ${translationDownloadId}. Trying to reconnect...`\n )\n await new Promise(resolve => setTimeout(resolve, 3000))\n return pollForFileDownloadLocation(\n resourceDownloadUrl,\n translationDownloadId,\n headers\n )\n } else if (response.redirected) {\n console.info(\n `Transifex plugin message: Received redirect for translation download ID ${translationDownloadId}. Following redirect now for file download.`\n )\n return response.url\n } else if (response.status === 200) {\n console.info(\n `Transifex plugin message: Requested download location for translation download ID ${translationDownloadId}. Location is still pending, trying again.`\n )\n await new Promise(resolve => setTimeout(resolve, 3000))\n return pollForFileDownloadLocation(\n resourceDownloadUrl,\n translationDownloadId,\n headers\n )\n } else {\n console.info(\n `Transifex plugin message: Requested download location for translation download ID ${translationDownloadId} but received error code ${response.status}. Waiting and trying again.`\n )\n await new Promise(resolve => setTimeout(resolve, 3000))\n return pollForFileDownloadLocation(\n resourceDownloadUrl,\n translationDownloadId,\n headers\n )\n }\n}\n\nconst handleFileDownload = async (url: string) => {\n return fetch(url).then(res => res.text())\n}\n","import { Secrets } from 'sanity-translations-tab'\nimport { baseTransifexUrl, projOrgSlug, getHeaders } from './helpers'\nimport getTranslationTask from './getTranslationTask'\n\nconst createResource = async (\n doc: Record<string, any>,\n documentId: string,\n secrets: Secrets | null\n) => {\n const resourceCreateBody = {\n data: {\n attributes: {\n accept_translations: true,\n name: doc.name,\n slug: documentId,\n },\n relationships: {\n i18n_format: {\n data: {\n id: 'HTML_FRAGMENT',\n type: 'i18n_formats',\n },\n },\n project: {\n data: {\n id: projOrgSlug(secrets),\n type: 'projects',\n },\n },\n },\n type: 'resources',\n },\n }\n\n return fetch(`${baseTransifexUrl}/resources`, {\n headers: getHeaders(secrets),\n method: 'POST',\n body: JSON.stringify(resourceCreateBody),\n })\n .then(res => res.json())\n .then(res => res.data.id)\n}\n\nexport default async function createTask(\n documentId: string,\n document: Record<string, any>,\n //unfortunately Transifex doesn't let you specify locales on creating a task\n //@ts-ignore\n localeIds: string[],\n secrets: Secrets | null\n) {\n let resourceId = await fetch(\n `${baseTransifexUrl}/resources/${projOrgSlug(secrets)}:r:${documentId}`,\n { headers: getHeaders(secrets) }\n )\n .then(res => res.json())\n .then(res => (res.data ? res.data.id : null))\n\n if (!resourceId) {\n resourceId = await createResource(document, documentId, secrets)\n }\n\n const resourceUploadUrl = `${baseTransifexUrl}/resource_strings_async_uploads`\n const resourceUploadBody = {\n data: {\n attributes: {\n content: document.content,\n content_encoding: 'text',\n },\n relationships: {\n resource: {\n data: {\n id: resourceId,\n type: 'resources',\n },\n },\n },\n type: 'resource_strings_async_uploads',\n },\n }\n\n return fetch(resourceUploadUrl, {\n method: 'POST',\n body: JSON.stringify(resourceUploadBody),\n headers: getHeaders(secrets),\n }).then(() => getTranslationTask(documentId, secrets))\n}\n","import { Adapter } from 'sanity-translations-tab'\n\nimport getLocales from './getLocales'\nimport getTranslationTask from './getTranslationTask'\nimport getTranslation from './getTranslation'\nimport createTask from './createTask'\n\nexport const TransifexAdapter: Adapter = {\n getLocales,\n getTranslationTask,\n createTask,\n getTranslation,\n}\n","import {\n TranslationsTab,\n baseDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n Adapter,\n documentLevelPatch,\n fieldLevelPatch,\n} from 'sanity-translations-tab'\nimport { TransifexAdapter } from './transifexAdapter'\n\ninterface ConfigOptions {\n adapter: Adapter\n secretsNamespace: string | null\n exportForTranslation: (id: string) => Promise<Record<string, any>>\n importTranslation: (\n id: string,\n localeId: string,\n doc: string\n ) => Promise<void>\n}\nconst defaultDocumentLevelConfig: ConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: TransifexAdapter,\n secretsNamespace: 'transifex',\n}\n\nconst defaultFieldLevelConfig: ConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: TransifexAdapter,\n secretsNamespace: 'transifex',\n}\n\nexport {\n TranslationsTab,\n findLatestDraft,\n documentLevelPatch,\n fieldLevelPatch,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n TransifexAdapter,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n}\n"],"names":["baseTransifexUrl","getHeaders","secrets","Authorization","token","projOrgSlug","organization","project","getLocales","fetch","headers","then","res","json","data","map","lang","enabled","description","attributes","name","localeId","code","getTranslationTask","documentId","taskId","locales","projectFilter","resourceFilter","ok","status","Error","locale","relationships","language","id","split","progress","Math","floor","reviewed_strings","parseFloat","total_strings","task","localeIds","l","validLocales","filter","find","getTranslation","resourceDownloadBody","content_encoding","type","resource","resourceDownloadUrl","method","body","JSON","stringify","translationDownloadId","pollForFileDownloadLocation","location","handleFileDownload","response","console","info","Promise","resolve","setTimeout","redirected","url","text","createResource","doc","resourceCreateBody","accept_translations","slug","i18n_format","createTask","document","resourceId","resourceUploadUrl","resourceUploadBody","content","TransifexAdapter","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","secretsNamespace","defaultFieldLevelConfig","baseFieldLevelConfig"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAMA,gBAAgB,GAAG,gCAAzB;AAEA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,OAAD;EAAA,OAA8B;IACtDC,aAAa,eAAYD,OAAZ,oBAAYA,OAAO,CAAEE,KAArB,CADyC;IAEtD,gBAAgB;GAFQ;AAAA,CAAnB;AAKA,IAAMC,WAAW,GAAG,SA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ADsB;cAE9BC,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAewB,kBAAf,CAFwB;cAG9BxE,OAAO,EAAET,UAAU,CAACC,OAAD;aAHT,CAAL,CAIJS,IAJI,CAIC;cAAA,OAAMY,kBAAkB,CAACC,UAAD,EAAatB,OAAb,CAAxB;aAJD,CAtCM;;UAAA;UAAA;YAAA;;;;;;;;ICpCFkF,gBAAgB,GAAY;EACvC5E,UAAU,EAAVA,UADuC;EAEvCe,kBAAkB,EAAlBA,kBAFuC;EAGvCuD,UAAU,EAAVA,UAHuC;EAIvC7B,cAAc,EAAdA;AAJuC,CAAlC;;ICmBDoC,0BAA0B,6BAC3BC,uBAD2B;EAE9BC,OAAO,EAAEH,gBAFqB;EAG9BI,gBAAgB,EAAE;AAHY,EAAhC;;AAMA,IAAMC,uBAAuB,6BACxBC,oBADwB;EAE3BH,OAAO,EAAEH,gBAFkB;EAG3BI,gBAAgB,EAAE;AAHS,EAA7B;;;;"}
@@ -1,6 +0,0 @@
1
- import { Secrets } from 'sanity-translations-tab';
2
- export default function createTask(documentId: string, document: Record<string, any>, localeIds: string[], secrets: Secrets | null): Promise<{
3
- taskId: string;
4
- documentId: string;
5
- locales: any;
6
- }>;
@@ -1,2 +0,0 @@
1
- import { Secrets } from 'sanity-translations-tab';
2
- export default function getLocales(secrets: Secrets | null): Promise<any>;
@@ -1,2 +0,0 @@
1
- import { Secrets } from 'sanity-translations-tab';
2
- export default function getTranslation(taskId: string, localeId: string, secrets: Secrets | null): Promise<string>;
@@ -1,6 +0,0 @@
1
- import { Secrets } from 'sanity-translations-tab';
2
- export default function getTranslationTask(documentId: string, secrets: Secrets | null): Promise<{
3
- taskId: string;
4
- documentId: string;
5
- locales: any;
6
- }>;
@@ -1,7 +0,0 @@
1
- import { Secrets } from 'sanity-translations-tab';
2
- export declare const baseTransifexUrl = "https://rest.api.transifex.com";
3
- export declare const getHeaders: (secrets: Secrets | null) => {
4
- Authorization: string;
5
- 'Content-Type': string;
6
- };
7
- export declare const projOrgSlug: (secrets: Secrets | null) => string;
@@ -1,2 +0,0 @@
1
- import { Adapter } from 'sanity-translations-tab';
2
- export declare const TransifexAdapter: Adapter;
@@ -1,155 +0,0 @@
1
- import { formatProperty, collectFormats } from '../src/formatPath'
2
- import {
3
- directives,
4
- formatDirectives,
5
- SmartlingDirectives,
6
- } from '../src/directives'
7
-
8
- describe('formatProperty', () => {
9
- it('figures out what kind of content it is', () => {
10
- expect(
11
- formatProperty({
12
- _type: 'localeString',
13
- en: 'This is a string',
14
- })
15
- ).toEqual('txt')
16
-
17
- expect(
18
- formatProperty({
19
- _type: 'localeMarkdown',
20
- en: '# Hi there',
21
- })
22
- ).toEqual('markdown')
23
-
24
- expect(
25
- formatProperty({
26
- _type: 'localeHtml',
27
- en: '<b>Hello</b>',
28
- })
29
- ).toEqual('html')
30
-
31
- expect(
32
- formatProperty({
33
- _type: 'html',
34
- en: '<b>Hello</b>',
35
- })
36
- ).toEqual('html')
37
-
38
- expect(formatProperty('hello')).toEqual('txt')
39
- expect(formatProperty(12)).toEqual('txt')
40
- })
41
- })
42
-
43
- describe('collect format paths', () => {
44
- it('collects all the different supported formats', () => {
45
- const doc = {
46
- title: {
47
- en: 'English',
48
- },
49
- seo: {
50
- heading: {
51
- en: 'English SEO title',
52
- fr: 'French SEO title',
53
- },
54
- },
55
- number: 12,
56
- heading: 'Dont mind me',
57
- body: {
58
- _type: 'localeMarkdown',
59
- en: '#Heading\nLine',
60
- no: '#Overskrift\nLinje',
61
- },
62
- nested: {
63
- body: {
64
- _type: 'markdown',
65
- en: '# HOho',
66
- },
67
- },
68
- web: {
69
- content: {
70
- _type: 'html',
71
- html: '<b>Hello</b>',
72
- },
73
- },
74
- }
75
-
76
- const result = collectFormats(doc, 'en')
77
- expect(result.txt).toEqual(['title/en', 'seo/heading/en'])
78
- expect(result.markdown).toEqual(['body/en', 'nested/body/en'])
79
- expect(result.html).toBeUndefined()
80
- })
81
- })
82
-
83
- describe('directives', () => {
84
- const result = directives(
85
- {
86
- _id: 'abcdef',
87
- _rev: '12',
88
- title: {
89
- en: 'English title',
90
- },
91
- deep: {
92
- object: {
93
- en: 'Deep english value',
94
- },
95
- },
96
- body: {
97
- _type: 'localeMarkdown',
98
- en: '# Title goes here\n- List or something here',
99
- },
100
- ignoreMe: {
101
- es: 'Esta',
102
- },
103
- },
104
- 'en'
105
- )
106
-
107
- it('always sets vairants enabled', () => {
108
- expect(result.variants_enabled).toBe(true)
109
- })
110
-
111
- it('translate_paths for all base language properties', () => {
112
- expect(result.translate_paths).toEqual([
113
- {
114
- path: '*/en',
115
- key: '{*}/{en}',
116
- },
117
- ])
118
- })
119
-
120
- it('collects the different formats in the file', () => {
121
- expect(result.string_format_paths).toEqual({
122
- txt: ['title/en', 'deep/object/en'],
123
- markdown: ['body/en'],
124
- })
125
- })
126
- })
127
-
128
- describe('formatDirectives', () => {
129
- it('formats directives for query param use', () => {
130
- const directives: SmartlingDirectives = {
131
- variants_enabled: true,
132
- translate_paths: [
133
- {
134
- path: 'fields/*/en-US',
135
- character_limit: 'fields/*/character_limit',
136
- key: '{*}/{en-US}',
137
- },
138
- ],
139
- string_format_paths: {
140
- txt: ['all/txt/en'],
141
- markdown: ['other/markdown/en'],
142
- html: ['seo/content/en'],
143
- },
144
- }
145
-
146
- const result = formatDirectives(directives)
147
- expect(result).toEqual({
148
- 'smartling.string_format_paths':
149
- 'txt: [all/txt/en], markdown: [other/markdown/en], html: [seo/content/en]',
150
- 'smartling.translate_paths':
151
- '[{"path":"fields/*/en-US","character_limit":"fields/*/character_limit","key":"{*}/{en-US}"}]',
152
- 'smartling.variants_enabled': 'true',
153
- })
154
- })
155
- })
@@ -1,17 +0,0 @@
1
- import { localeIdToSmartling, localeIdFromSmartling } from '../src/localeId'
2
-
3
- describe('localeIdToSmartling', () => {
4
- it('translates between Sanity locale ID and Smartling', () => {
5
- expect(localeIdToSmartling('en_UK')).toEqual('en-UK')
6
- expect(localeIdToSmartling('en')).toEqual('en')
7
- expect(localeIdToSmartling('no_NB')).toEqual('no-NB')
8
- })
9
- })
10
-
11
- describe('localeIdFromSmartling', () => {
12
- it('translates between Smartling locale ID and Sanity', () => {
13
- expect(localeIdFromSmartling('en-UK')).toEqual('en_UK')
14
- expect(localeIdFromSmartling('en')).toEqual('en')
15
- expect(localeIdFromSmartling('no-NB')).toEqual('no_NB')
16
- })
17
- })
@@ -1,113 +0,0 @@
1
- import { createPatches } from '../src/mergeTranslation'
2
-
3
- describe('createPatches', () => {
4
- it('collects paths and values for translated strings', () => {
5
- const translated = {
6
- _id: 'abcef',
7
- _type: 'article',
8
- title: {
9
- en: 'French title',
10
- },
11
- keyword: 'static',
12
- }
13
-
14
- const result = createPatches(translated, 'en', 'fr')
15
-
16
- expect(result).toEqual({
17
- 'title.fr': 'French title',
18
- })
19
- })
20
-
21
- it('finds whole objects that are translated', () => {
22
- const translated = {
23
- object: {
24
- en: {
25
- title: 'French',
26
- },
27
- },
28
- }
29
- const result = createPatches(translated, 'en', 'fr')
30
- expect(result).toEqual({
31
- 'object.fr': {
32
- title: 'French',
33
- },
34
- })
35
- })
36
-
37
- it('finds translated fields in arrays', () => {
38
- const translated = {
39
- title: {
40
- en: 'French title',
41
- },
42
- list: [
43
- {
44
- _key: 'a',
45
- en: 'French A',
46
- },
47
- {
48
- _key: 'b',
49
- en: 'French B',
50
- },
51
- {
52
- _key: 'ignoreThis',
53
- title: 'Not translated',
54
- },
55
- {
56
- _key: 'includeThis',
57
- en: 'Success!',
58
- },
59
- ],
60
- }
61
-
62
- const result = createPatches(translated, 'en', 'fr')
63
- expect(result).toEqual({
64
- 'title.fr': 'French title',
65
- 'list[_key == "a"].fr': 'French A',
66
- 'list[_key == "b"].fr': 'French B',
67
- 'list[_key == "includeThis"].fr': 'Success!',
68
- })
69
- })
70
-
71
- it('uses array indexing if _key is not available on all members', () => {
72
- const translated = {
73
- list: [
74
- {
75
- _key: 'a',
76
- en: 'Item 0',
77
- },
78
- {
79
- en: 'Item 1',
80
- },
81
- {
82
- en: 'Item 2',
83
- },
84
- ],
85
- }
86
-
87
- const result = createPatches(translated, 'en', 'fr')
88
- expect(result).toEqual({
89
- 'list[0].fr': 'Item 0',
90
- 'list[1].fr': 'Item 1',
91
- 'list[2].fr': 'Item 2',
92
- })
93
- })
94
-
95
- it('finds whole translated objects', () => {
96
- const translated = {
97
- seo: {
98
- en: {
99
- title: 'SEO title',
100
- desc: 'SEO desc',
101
- },
102
- },
103
- }
104
-
105
- const result = createPatches(translated, 'en', 'fr')
106
- expect(result).toEqual({
107
- 'seo.fr': {
108
- title: 'SEO title',
109
- desc: 'SEO desc',
110
- },
111
- })
112
- })
113
- })
package/tsconfig.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
3
- "include": ["src", "types"],
4
- "compilerOptions": {
5
- "module": "esnext",
6
- "lib": ["dom", "esnext"],
7
- "importHelpers": true,
8
- // output .d.ts declaration files for consumers
9
- "declaration": true,
10
- // output .js.map sourcemap files for consumers
11
- "sourceMap": true,
12
- // match output dir to input dir. e.g. dist/index instead of dist/src/index
13
- "rootDir": "./src",
14
- // stricter type-checking for stronger correctness. Recommended by TS
15
- "strict": true,
16
- // linter checks for common issues
17
- "noImplicitReturns": true,
18
- "noFallthroughCasesInSwitch": true,
19
- // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
22
- // use Node's module resolution algorithm, instead of the legacy TS one
23
- "moduleResolution": "node",
24
- // transpile JSX to React.createElement
25
- "jsx": "react",
26
- // interop between ESM and CJS modules. Recommended by TS
27
- "esModuleInterop": true,
28
- // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS
29
- "skipLibCheck": true,
30
- // error out if import and file system have a casing mismatch. Recommended by TS
31
- "forceConsistentCasingInFileNames": true,
32
- // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
33
- "noEmit": true
34
- }
35
- }