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