(nuxt) replace mechanism in router.options.ts for locale-specific noun pages with route.meta.translatedPaths

now possible because Nuxt scans definePageMeta for pages added by pages:extend
This commit is contained in:
Valentyne Stigloher 2025-08-10 10:05:21 +02:00
parent 73005d0d2c
commit 86c59d7d82
6 changed files with 24 additions and 5 deletions

View File

@ -30,11 +30,6 @@ const routerOptions: RouterOptions = {
meta: translatedRoute.meta,
};
});
} else if (typeof route.name === 'string' &&
route.name.startsWith('nouns-') && !route.name.startsWith(`nouns-${config.locale}`)) {
// workaround for dynamic inclusion of nouns subroutes,
// as translatedPaths does not work because definePageMeta is not scanned in pages:extend hook in Nuxt 3
return [];
}
return [route];
});

View File

@ -0,0 +1,8 @@
import type { Config } from '~~/locale/config.ts';
export default (config: Config, locale: string, route: string): string[] => {
if (config.locale !== locale) {
return [];
}
return [`/${encodeURIComponent(route)}`];
};

View File

@ -12,6 +12,10 @@ import { neutralGenderNameInjectionKey } from '~~/shared/injectionKeys.ts';
import { availableGenders, genders, numeri, symbolsByNumeri } from '~~/shared/nouns.ts';
import type { NounDeclension, NounWords } from '~~/shared/nouns.ts';
definePageMeta({
translatedPaths: (config) => translatedPathForSingleLocale(config, 'pl', 'dukatywy'),
});
const dukajDeclension: NounDeclension = {
singular: {
m: ['u'],

View File

@ -13,6 +13,10 @@ import { neutralGenderNameInjectionKey } from '~~/shared/injectionKeys.ts';
import { availableGenders, genders, numeri, symbolsByNumeri } from '~~/shared/nouns.ts';
import type { NounWords, NounDeclension } from '~~/shared/nouns.ts';
definePageMeta({
translatedPaths: (config) => translatedPathForSingleLocale(config, 'pl', 'iksatywy'),
});
const xDeclension: NounDeclension = {
singular: {
m: ['x'],

View File

@ -8,6 +8,10 @@ import { removeSuffix } from '~~/shared/helpers.ts';
import { numeri, symbolsByNumeri } from '~~/shared/nouns.ts';
import type { NounDeclension } from '~~/shared/nouns.ts';
definePageMeta({
translatedPaths: (config) => translatedPathForSingleLocale(config, 'pl', 'neutratywy'),
});
const { $translator: translator } = useNuxtApp();
const config = useConfig();

View File

@ -9,6 +9,10 @@ import type { Source } from '~~/shared/classes.ts';
import { neutralGenderNameInjectionKey } from '~~/shared/injectionKeys.ts';
import { availableGenders } from '~~/shared/nouns.ts';
definePageMeta({
translatedPaths: (config) => translatedPathForSingleLocale(config, 'pl', 'osobatywy'),
});
const { $translator: translator } = useNuxtApp();
useSimpleHead({
title: translator.translate('nouns.personNouns.header'),