mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-22 12:03:25 -04:00
(refactor)(nouns) rename nounConventions.suml to nounsData.suml
This commit is contained in:
parent
6975c76005
commit
dc1ee7424e
@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { NounDeclension } from '~/src/classes.ts';
|
import { NounDeclension } from '~/src/classes.ts';
|
||||||
import { loadNounConventions } from '~/src/data.ts';
|
import { loadNounsData } from '~/src/data.ts';
|
||||||
import type { NounClass, NounConvention } from '~/src/nouns.ts';
|
import type { NounClass, NounConvention } from '~/src/nouns.ts';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@ -9,10 +9,10 @@ const props = defineProps<{
|
|||||||
plural?: boolean;
|
plural?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const nounConventions = await loadNounConventions();
|
const nounsData = await loadNounsData();
|
||||||
|
|
||||||
if (nounConventions === undefined) {
|
if (nounsData === undefined) {
|
||||||
throw new Error('no nounConventions defined');
|
throw new Error('nounsData is undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
const template = computed(() => props.nounConvention.templates[props.nounClass.key]);
|
const template = computed(() => props.nounConvention.templates[props.nounClass.key]);
|
||||||
@ -33,14 +33,14 @@ const declension = computed(() => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const declension = nounConventions.declensions[template.value.declension];
|
const declension = nounsData.declensions[template.value.declension];
|
||||||
if (!declension[numerus.value]) {
|
if (!declension[numerus.value]) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const entries = Object.entries(declension[numerus.value] ?? {}).map(([caseAbbreviation, declensionSuffix]) => {
|
const entries = Object.entries(declension[numerus.value] ?? {}).map(([caseAbbreviation, declensionSuffix]) => {
|
||||||
return [caseAbbreviation.toUpperCase() + (props.plural ? '_pl' : ''),
|
return [caseAbbreviation.toUpperCase() + (props.plural ? '_pl' : ''),
|
||||||
nounConventions.classExample[numerus.value][caseAbbreviation].replace(/\{([^}]+)}/, (_match, morpheme) => {
|
nounsData.classExample[numerus.value][caseAbbreviation].replace(/\{([^}]+)}/, (_match, morpheme) => {
|
||||||
const value = props.nounConvention.morphemes[morpheme];
|
const value = props.nounConvention.morphemes[morpheme];
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import useSimpleHead from '~/composables/useSimpleHead.ts';
|
import useSimpleHead from '~/composables/useSimpleHead.ts';
|
||||||
import { loadNounConventions } from '~/src/data.ts';
|
import { loadNounsData } from '~/src/data.ts';
|
||||||
import { Example } from '~/src/language/examples.ts';
|
import { Example } from '~/src/language/examples.ts';
|
||||||
import { MorphemeValues } from '~/src/language/morphemes.ts';
|
import { MorphemeValues } from '~/src/language/morphemes.ts';
|
||||||
import type { NounConvention } from '~/src/nouns.ts';
|
import type { NounConvention } from '~/src/nouns.ts';
|
||||||
@ -11,9 +11,9 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const { $translator: translator } = useNuxtApp();
|
const { $translator: translator } = useNuxtApp();
|
||||||
|
|
||||||
const nounConventions = await loadNounConventions();
|
const nounsData = await loadNounsData();
|
||||||
if (nounConventions === undefined) {
|
if (nounsData === undefined) {
|
||||||
throw new Error('nounConventions is undefined');
|
throw new Error('nounsData is undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
useSimpleHead({
|
useSimpleHead({
|
||||||
@ -28,7 +28,7 @@ const exampleValues = computed(() => {
|
|||||||
return {
|
return {
|
||||||
morphemeValues: new MorphemeValues(props.nounConvention.morphemes),
|
morphemeValues: new MorphemeValues(props.nounConvention.morphemes),
|
||||||
nounConvention: props.nounConvention,
|
nounConvention: props.nounConvention,
|
||||||
nounDeclensions: nounConventions.declensions,
|
nounDeclensions: nounsData.declensions,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,12 +36,12 @@ const examples = computed(() => {
|
|||||||
if (exampleValues.value === undefined) {
|
if (exampleValues.value === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return nounConventions?.examples.map((example) => Example.parse(example))
|
return nounsData?.examples.map((example) => Example.parse(example))
|
||||||
.filter((example) => example.areRequiredExampleValuesPresent(exampleValues.value!));
|
.filter((example) => example.areRequiredExampleValuesPresent(exampleValues.value!));
|
||||||
});
|
});
|
||||||
|
|
||||||
const nounConventionGroup = computed(() => {
|
const nounConventionGroup = computed(() => {
|
||||||
return Object.values(nounConventions.groups).find((nounConventionGroup) => {
|
return Object.values(nounsData.groups).find((nounConventionGroup) => {
|
||||||
return nounConventionGroup.conventions.includes(props.nounConvention.key);
|
return nounConventionGroup.conventions.includes(props.nounConvention.key);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -95,7 +95,7 @@ const nounConventionGroup = computed(() => {
|
|||||||
<T>pronouns.grammarTable</T><T>quotation.colon</T>
|
<T>pronouns.grammarTable</T><T>quotation.colon</T>
|
||||||
</h2>
|
</h2>
|
||||||
<GrammarTable
|
<GrammarTable
|
||||||
v-for="(grammarTable, t) in nounConventions.grammarTables"
|
v-for="(grammarTable, t) in nounsData.grammarTables"
|
||||||
:key="t"
|
:key="t"
|
||||||
:grammar-table="grammarTable"
|
:grammar-table="grammarTable"
|
||||||
:example-values
|
:example-values
|
||||||
@ -106,7 +106,7 @@ const nounConventionGroup = computed(() => {
|
|||||||
<section>
|
<section>
|
||||||
<div class="row d-flex">
|
<div class="row d-flex">
|
||||||
<NounsClassItem
|
<NounsClassItem
|
||||||
v-for="(nounClass, key) of nounConventions.classes"
|
v-for="(nounClass, key) of nounsData.classes"
|
||||||
:key
|
:key
|
||||||
:noun-class="{ ...nounClass, key }"
|
:noun-class="{ ...nounClass, key }"
|
||||||
:noun-convention
|
:noun-convention
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { loadNounConventions } from '~/src/data.ts';
|
import { loadNounsData } from '~/src/data.ts';
|
||||||
|
|
||||||
const nounConventions = await loadNounConventions();
|
const nounsData = await loadNounsData();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ul v-if="nounConventions" class="list-group mt-4">
|
<ul v-if="nounsData" class="list-group mt-4">
|
||||||
<li
|
<li
|
||||||
v-for="nounConventionGroup of withKey(nounConventions.groups)"
|
v-for="nounConventionGroup of withKey(nounsData.groups)"
|
||||||
:key="nounConventionGroup.key"
|
:key="nounConventionGroup.key"
|
||||||
class="list-group-item"
|
class="list-group-item"
|
||||||
>
|
>
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { loadNounConventions } from '~/src/data.ts';
|
import { loadNounsData } from '~/src/data.ts';
|
||||||
import type { NounConventionGroup } from '~/src/nouns.ts';
|
import type { NounConventionGroup } from '~/src/nouns.ts';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
nounConventionGroup: NounConventionGroup;
|
nounConventionGroup: NounConventionGroup;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const nounConventions = await loadNounConventions();
|
const nounsData = await loadNounsData();
|
||||||
if (nounConventions === undefined) {
|
if (nounsData === undefined) {
|
||||||
throw new Error('no nounConventions defined');
|
throw new Error('nounsData is undefined');
|
||||||
}
|
}
|
||||||
const visibleNounConventions = computed(() => {
|
const visibleNounConventions = computed(() => {
|
||||||
return withKey(nounConventions.conventions).filter((nounConvention) => {
|
return withKey(nounsData.conventions).filter((nounConvention) => {
|
||||||
return props.nounConventionGroup.conventions.includes(nounConvention.key);
|
return props.nounConventionGroup.conventions.includes(nounConvention.key);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { loadNounConventions } from '~/src/data.ts';
|
import { loadNounsData } from '~/src/data.ts';
|
||||||
import type { NounConvention } from '~/src/nouns.ts';
|
import type { NounConvention } from '~/src/nouns.ts';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
nounConvention: WithKey<NounConvention>;
|
nounConvention: WithKey<NounConvention>;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const nounConventions = await loadNounConventions();
|
const nounsData = await loadNounsData();
|
||||||
|
|
||||||
if (nounConventions === undefined) {
|
if (nounsData === undefined) {
|
||||||
throw new Error('no nounConventions defined');
|
throw new Error('nounsData is undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
const template = props.nounConvention.templates.t1;
|
const template = props.nounConvention.templates.t1;
|
||||||
@ -24,7 +24,7 @@ const stem = computed(() => {
|
|||||||
return stems[template.stem ?? 'default'];
|
return stems[template.stem ?? 'default'];
|
||||||
});
|
});
|
||||||
|
|
||||||
const declension = nounConventions.declensions[template.declension];
|
const declension = nounsData.declensions[template.declension];
|
||||||
|
|
||||||
const singularExample = computed(() => {
|
const singularExample = computed(() => {
|
||||||
if (declension.singular?.n === undefined) {
|
if (declension.singular?.n === undefined) {
|
||||||
|
@ -94,8 +94,8 @@ export default withNuxt(
|
|||||||
schema: 'locale/config.schema.json',
|
schema: 'locale/config.schema.json',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fileMatch: ['locale/*/nouns/nounConventions.suml'],
|
fileMatch: ['locale/*/nouns/nounsData.suml'],
|
||||||
schema: 'locale/nounConventions.schema.json',
|
schema: 'locale/nounsData.schema.json',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
|
@ -40,6 +40,6 @@ const generateFontsModule = async () => {
|
|||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
generateJsonSchema(`${__dirname}/config.ts`, 'Config'),
|
generateJsonSchema(`${__dirname}/config.ts`, 'Config'),
|
||||||
generateJsonSchema(`${__dirname}/../src/nouns.ts`, 'NounConventions'),
|
generateJsonSchema(`${__dirname}/../src/nouns.ts`, 'NounsData'),
|
||||||
generateFontsModule(),
|
generateFontsModule(),
|
||||||
]);
|
]);
|
||||||
|
@ -2,7 +2,7 @@ import { defineNuxtRouteMiddleware, useNuxtApp } from 'nuxt/app';
|
|||||||
|
|
||||||
import type { Config } from '~/locale/config.ts';
|
import type { Config } from '~/locale/config.ts';
|
||||||
import { buildPronoun } from '~/src/buildPronoun.ts';
|
import { buildPronoun } from '~/src/buildPronoun.ts';
|
||||||
import { loadNounConventions, loadPronounLibrary } from '~/src/data.ts';
|
import { loadNounsData, loadPronounLibrary } from '~/src/data.ts';
|
||||||
import type { Translator } from '~/src/translator.ts';
|
import type { Translator } from '~/src/translator.ts';
|
||||||
|
|
||||||
const findPronoun = async (path: string, config: Config, translator: Translator) => {
|
const findPronoun = async (path: string, config: Config, translator: Translator) => {
|
||||||
@ -23,9 +23,9 @@ const findNounConvention = async (path: string, config: Config) => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nounConventions = await loadNounConventions();
|
const nounsData = await loadNounsData();
|
||||||
|
|
||||||
return withKey(nounConventions?.conventions ?? {})
|
return withKey(nounsData?.conventions ?? {})
|
||||||
.find((nounConvention) => nounConvention.key === path);
|
.find((nounConvention) => nounConvention.key === path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import { buildCalendar } from '~/src/calendar/calendar.ts';
|
|||||||
import { getLocaleForUrl, getUrlForLocale } from '~/src/domain.ts';
|
import { getLocaleForUrl, getUrlForLocale } from '~/src/domain.ts';
|
||||||
import { Example } from '~/src/language/examples.ts';
|
import { Example } from '~/src/language/examples.ts';
|
||||||
import type { VariantsFromBaseConverter } from '~/src/language/grammarTables.ts';
|
import type { VariantsFromBaseConverter } from '~/src/language/grammarTables.ts';
|
||||||
import type { NounConventions } from '~/src/nouns.ts';
|
import type { NounsData } from '~/src/nouns.ts';
|
||||||
|
|
||||||
export const getLocale = () => {
|
export const getLocale = () => {
|
||||||
return getLocaleForUrl(useRequestURL()) ?? '_';
|
return getLocaleForUrl(useRequestURL()) ?? '_';
|
||||||
@ -64,9 +64,9 @@ export const loadPronounLibrary = async (config: Config) => {
|
|||||||
return new PronounLibrary(config, pronounGroups, pronouns);
|
return new PronounLibrary(config, pronounGroups, pronouns);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadNounConventions = async (): Promise<NounConventions | undefined> => {
|
export const loadNounsData = async (): Promise<NounsData | undefined> => {
|
||||||
try {
|
try {
|
||||||
return (await import(`~/locale/${getLocale()}/nouns/nounConventions.suml`)).default;
|
return (await import(`~/locale/${getLocale()}/nouns/nounsData.suml`)).default;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ export interface NounDeclension {
|
|||||||
plural?: Record<string, string>;
|
plural?: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NounConventions {
|
export interface NounsData {
|
||||||
morphemes: string[];
|
morphemes: string[];
|
||||||
examples: string[];
|
examples: string[];
|
||||||
grammarTables: GrammarTableDefinition[];
|
grammarTables: GrammarTableDefinition[];
|
||||||
|
@ -9,7 +9,7 @@ import { normaliseKey } from '~/src/buildPronoun.ts';
|
|||||||
import { Example } from '~/src/language/examples.ts';
|
import { Example } from '~/src/language/examples.ts';
|
||||||
import type { VariantsFromBaseConverter } from '~/src/language/grammarTables.ts';
|
import type { VariantsFromBaseConverter } from '~/src/language/grammarTables.ts';
|
||||||
import { availableGenders, gendersWithNumerus } from '~/src/nouns.ts';
|
import { availableGenders, gendersWithNumerus } from '~/src/nouns.ts';
|
||||||
import type { NounConventions } from '~/src/nouns.ts';
|
import type { NounsData } from '~/src/nouns.ts';
|
||||||
|
|
||||||
function toHaveValidMorphemes(actual: string, morphemes: string[]): SyncExpectationResult {
|
function toHaveValidMorphemes(actual: string, morphemes: string[]): SyncExpectationResult {
|
||||||
const containedMorphemes = Example.parse(actual).parts
|
const containedMorphemes = Example.parse(actual).parts
|
||||||
@ -164,13 +164,13 @@ describe.each(allLocales)('data files of $code', async ({ code }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.nouns.conventions?.enabled) {
|
if (config.nouns.conventions?.enabled) {
|
||||||
const nounConventions = await loadSuml<NounConventions>(`locale/${code}/nouns/nounConventions.suml`);
|
const nounsData = await loadSuml<NounsData>(`locale/${code}/nouns/nounsData.suml`);
|
||||||
|
|
||||||
describe('nouns/nounConventions.suml', () => {
|
describe('nouns/nounsData.suml', () => {
|
||||||
test('has valid variant types', async () => {
|
test('has valid variant types', async () => {
|
||||||
const grammarTableVariantsConverter = (await import(`~/locale/${code}/language/grammarTableVariantsConverter.ts`)).default as VariantsFromBaseConverter;
|
const grammarTableVariantsConverter = (await import(`~/locale/${code}/language/grammarTableVariantsConverter.ts`)).default as VariantsFromBaseConverter;
|
||||||
|
|
||||||
for (const grammarTable of nounConventions.grammarTables) {
|
for (const grammarTable of nounsData.grammarTables) {
|
||||||
for (const section of grammarTable.sections) {
|
for (const section of grammarTable.sections) {
|
||||||
if (!Array.isArray(section.variants)) {
|
if (!Array.isArray(section.variants)) {
|
||||||
expect(Object.keys(grammarTableVariantsConverter)).toContain(section.variants.type);
|
expect(Object.keys(grammarTableVariantsConverter)).toContain(section.variants.type);
|
||||||
@ -179,14 +179,14 @@ describe.each(allLocales)('data files of $code', async ({ code }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('has valid morphemes', () => {
|
test('has valid morphemes', () => {
|
||||||
for (const convention of Object.values(nounConventions.conventions)) {
|
for (const convention of Object.values(nounsData.conventions)) {
|
||||||
expect(nounConventions.morphemes)
|
expect(nounsData.morphemes)
|
||||||
.toEqual(expect.arrayContaining(Object.keys(convention.morphemes)));
|
.toEqual(expect.arrayContaining(Object.keys(convention.morphemes)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('groups reference conventions by key', () => {
|
test('groups reference conventions by key', () => {
|
||||||
for (const group of Object.values(nounConventions.groups)) {
|
for (const group of Object.values(nounsData.groups)) {
|
||||||
expect(Object.keys(nounConventions.conventions)).toEqual(expect.arrayContaining(group.conventions));
|
expect(Object.keys(nounsData.conventions)).toEqual(expect.arrayContaining(group.conventions));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user