@docusaurus/theme-translations 2.0.0-beta.16 → 2.0.0-beta.19

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 (44) hide show
  1. package/lib/index.d.ts +2 -1
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +18 -17
  4. package/lib/index.js.map +1 -1
  5. package/lib/utils.d.ts +13 -0
  6. package/lib/utils.d.ts.map +1 -0
  7. package/lib/utils.js +82 -0
  8. package/lib/utils.js.map +1 -0
  9. package/locales/ar/theme-common.json +4 -1
  10. package/locales/base/theme-common.json +8 -2
  11. package/locales/bn/theme-common.json +4 -1
  12. package/locales/cs/theme-common.json +4 -1
  13. package/locales/cs/theme-search-algolia.json +1 -1
  14. package/locales/da/theme-common.json +4 -1
  15. package/locales/de/plugin-ideal-image.json +5 -5
  16. package/locales/de/theme-common.json +18 -15
  17. package/locales/de/theme-search-algolia.json +1 -1
  18. package/locales/es/theme-common.json +4 -1
  19. package/locales/fa/theme-common.json +4 -1
  20. package/locales/fil/theme-common.json +4 -1
  21. package/locales/fr/theme-common.json +4 -1
  22. package/locales/he/theme-common.json +4 -1
  23. package/locales/hi/theme-common.json +4 -1
  24. package/locales/it/theme-common.json +4 -1
  25. package/locales/ja/theme-common.json +4 -1
  26. package/locales/ko/theme-common.json +4 -1
  27. package/locales/pl/plugin-ideal-image.json +5 -5
  28. package/locales/pl/theme-common.json +25 -22
  29. package/locales/pl/theme-search-algolia.json +2 -2
  30. package/locales/pt-BR/theme-common.json +4 -1
  31. package/locales/pt-PT/theme-common.json +4 -1
  32. package/locales/ru/plugin-ideal-image.json +5 -5
  33. package/locales/ru/theme-common.json +19 -16
  34. package/locales/ru/theme-search-algolia.json +1 -1
  35. package/locales/sr/theme-common.json +4 -1
  36. package/locales/tr/theme-common.json +4 -1
  37. package/locales/vi/plugin-ideal-image.json +5 -5
  38. package/locales/vi/theme-common.json +13 -10
  39. package/locales/vi/theme-search-algolia.json +1 -1
  40. package/locales/zh-Hans/theme-common.json +5 -2
  41. package/locales/zh-Hant/theme-common.json +5 -2
  42. package/package.json +9 -9
  43. package/src/index.ts +18 -16
  44. package/src/utils.ts +99 -0
package/src/utils.ts ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ // This file isn't used by index.ts. It's used by update.mjs and tests. It's
9
+ // only here so that (a) we get a partially typed infrastructure (although the
10
+ // update script has ts-check anyways) (b) the test coverage isn't destroyed by
11
+ // the untested update.mjs file (c) we can ergonomically import the util
12
+ // functions in the Jest test without using `await import`
13
+
14
+ import path from 'path';
15
+ import fs from 'fs-extra';
16
+ // Unsafe import, should we create a package for the translationsExtractor ?;
17
+ import {
18
+ globSourceCodeFilePaths,
19
+ extractAllSourceCodeFileTranslations,
20
+ } from '@docusaurus/core/lib/server/translations/translationsExtractor';
21
+ import type {TranslationFileContent} from '@docusaurus/types';
22
+
23
+ async function getPackageCodePath(packageName: string) {
24
+ const packagePath = path.join(__dirname, '../..', packageName);
25
+ const packageJsonPath = path.join(packagePath, 'package.json');
26
+ const {main} = await fs.readJSON(packageJsonPath);
27
+ const packageSrcPath = path.join(packagePath, path.dirname(main));
28
+ const packageLibNextPath = packageSrcPath.replace('lib', 'lib-next');
29
+ return (await fs.pathExists(packageLibNextPath))
30
+ ? packageLibNextPath
31
+ : packageSrcPath;
32
+ }
33
+
34
+ export async function getThemes(): Promise<{name: string; src: string[]}[]> {
35
+ return [
36
+ {
37
+ name: 'theme-common',
38
+ src: [
39
+ await getPackageCodePath('docusaurus-theme-classic'),
40
+ await getPackageCodePath('docusaurus-theme-common'),
41
+ ],
42
+ },
43
+ {
44
+ name: 'theme-search-algolia',
45
+ src: [await getPackageCodePath('docusaurus-theme-search-algolia')],
46
+ },
47
+ {
48
+ name: 'theme-live-codeblock',
49
+ src: [await getPackageCodePath('docusaurus-theme-live-codeblock')],
50
+ },
51
+ {
52
+ name: 'plugin-pwa',
53
+ src: [await getPackageCodePath('docusaurus-plugin-pwa')],
54
+ },
55
+ {
56
+ name: 'plugin-ideal-image',
57
+ src: [await getPackageCodePath('docusaurus-plugin-ideal-image')],
58
+ },
59
+ ];
60
+ }
61
+
62
+ export async function extractThemeCodeMessages(
63
+ targetDirs?: string[],
64
+ ): Promise<TranslationFileContent> {
65
+ // eslint-disable-next-line no-param-reassign
66
+ targetDirs ??= (await getThemes()).flatMap((theme) => theme.src);
67
+
68
+ const filePaths = (await globSourceCodeFilePaths(targetDirs)).filter(
69
+ (filePath) => ['.js', '.jsx'].includes(path.extname(filePath)),
70
+ );
71
+
72
+ const filesExtractedTranslations = await extractAllSourceCodeFileTranslations(
73
+ filePaths,
74
+ {
75
+ presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
76
+ },
77
+ );
78
+
79
+ filesExtractedTranslations.forEach((fileExtractedTranslations) => {
80
+ if (fileExtractedTranslations.warnings.length > 0) {
81
+ throw new Error(`
82
+ Please make sure all theme translations are static!
83
+ Some warnings were found!
84
+
85
+ ${fileExtractedTranslations.warnings.join('\n\n')}
86
+ `);
87
+ }
88
+ });
89
+
90
+ const translations = filesExtractedTranslations.reduce(
91
+ (acc, extractedTranslations) => ({
92
+ ...acc,
93
+ ...extractedTranslations.translations,
94
+ }),
95
+ {},
96
+ );
97
+
98
+ return translations;
99
+ }