itube-specs 0.0.1050 → 0.0.1051

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 (2) hide show
  1. package/nuxt.config.ts +22 -2
  2. package/package.json +1 -1
package/nuxt.config.ts CHANGED
@@ -1,19 +1,39 @@
1
1
  import { readdirSync } from 'node:fs';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { defineNuxtConfig } from 'nuxt/config';
4
+ import { useNuxt } from 'nuxt/kit';
4
5
 
5
6
  // Общие для всех сайтов переводы (навигация, сортировки, UI-действия). `@nuxtjs/i18n`
6
7
  // мержит локали слоёв: файл слоя встаёт в `files` ПЕРЕД проектным, поэтому проект
7
8
  // перекрывает любой ключ, а `deepCopy` мержит вложенные группы, не заменяя их целиком.
8
- // Список кодов выводится из самих файлов, поэтому набор здесь — канонический:
9
- // код, которого нет в locales приложения, добавит приложению лишнюю локаль.
9
+ // Список кодов выводится из самих файлов, поэтому набор здесь — надмножество локалей всех
10
+ // сайтов. Код, которого нет в locales приложения, i18n добавил бы приложению лишней локалью
11
+ // (без `language` → «ISO code is required to generate alternate link», лишние /<code>/ роуты),
12
+ // поэтому до установки модулей локали слоя урезаются до объявленных приложением.
10
13
  const sharedLocalesDir = fileURLToPath(new URL('./i18n/locales', import.meta.url));
11
14
  const sharedLocales = readdirSync(sharedLocalesDir)
12
15
  .filter(file => file.endsWith('.json'))
13
16
  .sort()
14
17
  .map(file => ({ code: file.split('-')[0], file }));
15
18
 
19
+ const localeCode = (locale: string | { code: string }) => typeof locale === 'string' ? locale : locale.code;
20
+
16
21
  export default defineNuxtConfig({
22
+ hooks: {
23
+ 'modules:before'() {
24
+ const [project, ...layers] = useNuxt().options._layers;
25
+ const appCodes = new Set((project.config.i18n?.locales ?? []).map(localeCode));
26
+ if (!appCodes.size) {
27
+ return;
28
+ }
29
+ for (const layer of layers) {
30
+ const i18n = layer.config.i18n;
31
+ if (i18n?.locales) {
32
+ i18n.locales = i18n.locales.filter(locale => appCodes.has(localeCode(locale)));
33
+ }
34
+ }
35
+ },
36
+ },
17
37
  modules: ['@nuxt/eslint', '@nuxt/icon', '@nuxtjs/i18n'],
18
38
  imports: {
19
39
  dirs: ['composables/**']
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.1050",
4
+ "version": "0.0.1051",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {