mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-23 12:43:48 -04:00
(de) add custom translations for some any pronoun groups
This commit is contained in:
parent
c7735a522c
commit
27cbf91e04
@ -75,6 +75,11 @@ pronouns:
|
||||
description: >
|
||||
Auch wenn es für manche Menschen sehr wichtig ist, dass bestimmte Pronomen benutzt werden, wenn über sie geredet wird, ist es anderen egal, welche Pronomen für sie verwendet werden.
|
||||
options: 'Überprüfe die Optionen [share]{/pronomen=hier}.'
|
||||
group:
|
||||
neopronomen:
|
||||
short: 'alle Neopronomen'
|
||||
sonderzeichen:
|
||||
short: 'alle mit Sonderzeichen'
|
||||
comprehensive:
|
||||
simple: 'häufige'
|
||||
comprehensive: 'erweitert'
|
||||
|
@ -10,6 +10,7 @@ export default ({ app, store }) => {
|
||||
|
||||
Vue.prototype.$base = process.env.BASE_URL;
|
||||
|
||||
Vue.prototype.$translator = translator;
|
||||
Vue.prototype.$t = (key, params = {}, warn = false) => translator.translate(key, params, warn);
|
||||
Vue.prototype.$te = (key, fallback = false) => {
|
||||
if (translator.has(key)) {
|
||||
|
@ -14,8 +14,7 @@
|
||||
<div class="alert alert-primary">
|
||||
<h2 class="text-center mb-0">
|
||||
<strong>
|
||||
<T>pronouns.any.short</T>
|
||||
<span v-if="groupKey">{{groupKey}}</span>
|
||||
<Spelling :text="short"/>
|
||||
</strong>
|
||||
</h2>
|
||||
<p class="h6 small text-center mb-0 mt-2">
|
||||
@ -71,13 +70,18 @@
|
||||
data() {
|
||||
const groupKey = this.$route.params.group;
|
||||
let pronounGroups = [];
|
||||
let short;
|
||||
if (groupKey) {
|
||||
pronounGroups = pronounLibrary.byKey()[groupKey];
|
||||
const merged = pronounLibrary.byKey()[groupKey];
|
||||
pronounGroups = merged.groups;
|
||||
short = merged.short(this.$translator);
|
||||
} else {
|
||||
short = this.$t('pronouns.any.short');
|
||||
}
|
||||
|
||||
return {
|
||||
examples,
|
||||
groupKey,
|
||||
short,
|
||||
pronounGroups,
|
||||
|
||||
comprehensive: false,
|
||||
@ -85,7 +89,7 @@
|
||||
},
|
||||
head() {
|
||||
return head({
|
||||
title: `${this.$t('pronouns.intro')}: ${this.$t('pronouns.any.short')} ${this.groupKey || ''}`.trim(),
|
||||
title: `${this.$t('pronouns.intro')}: ${this.short}`.trim(),
|
||||
banner: `api/banner/${this.$t('pronouns.any.short')}.png`,
|
||||
});
|
||||
},
|
||||
|
@ -212,8 +212,10 @@
|
||||
<li>
|
||||
<nuxt-link :to="`/${config.pronouns.any}`"><T>pronouns.any.short</T></nuxt-link>
|
||||
</li>
|
||||
<li v-for="(keyPronouns, key) in pronounLibrary.byKey()">
|
||||
<nuxt-link :to="`/${config.pronouns.any}:${key}`"><T>pronouns.any.short</T> {{key}}</nuxt-link>
|
||||
<li v-for="(merged, key) in pronounLibrary.byKey()" :key="key">
|
||||
<nuxt-link :to="`/${config.pronouns.any}:${key}`">
|
||||
<Spelling :text="merged.short($translator)"/>
|
||||
</nuxt-link>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -579,6 +579,22 @@ export class PronounGroup {
|
||||
}
|
||||
}
|
||||
|
||||
export class MergedPronounGroup {
|
||||
constructor(key, groups) {
|
||||
this.key = key;
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
short(translator) {
|
||||
const specificTranslationKey = `pronouns.any.group.${this.key}.short`;
|
||||
if (translator.has(specificTranslationKey)) {
|
||||
return translator.translate(specificTranslationKey);
|
||||
} else {
|
||||
return `${translator.translate('pronouns.any.short')} ${this.key}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class PronounLibrary {
|
||||
constructor(groups, pronouns) {
|
||||
this.groups = groups;
|
||||
@ -622,7 +638,9 @@ export class PronounLibrary {
|
||||
const ret = {};
|
||||
for (let g of this.groups) {
|
||||
if (g.key === null) { continue; }
|
||||
if (ret[g.key] === undefined) { ret[g.key] = []; }
|
||||
if (ret[g.key] === undefined) {
|
||||
ret[g.key] = new MergedPronounGroup(g.key, []);
|
||||
}
|
||||
|
||||
const p = {};
|
||||
for (let t of g.pronouns) {
|
||||
@ -631,7 +649,7 @@ export class PronounLibrary {
|
||||
p[pronoun.canonicalName] = pronoun;
|
||||
}
|
||||
|
||||
ret[g.key].push({ group: g, groupPronouns: p});
|
||||
ret[g.key].groups.push({ group: g, groupPronouns: p});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
import { beforeEach, describe, expect, jest, test } from '@jest/globals';
|
||||
import { mockTranslations } from './fixtures/translations.js';
|
||||
|
||||
mockTranslations({});
|
||||
|
||||
// workaround to be independent of the current selected locale
|
||||
jest.unstable_mockModule('../data/pronouns/morphemes.js', () => {
|
||||
|
@ -1,8 +1,19 @@
|
||||
import { describe, expect, test } from '@jest/globals';
|
||||
|
||||
import { PronounGroup, PronounLibrary } from '../src/classes.js';
|
||||
import { MergedPronounGroup, PronounGroup, PronounLibrary } from '../src/classes.js';
|
||||
import { mockTranslations } from './fixtures/translations.js';
|
||||
|
||||
import pronouns from './fixtures/pronouns.js';
|
||||
const translations = {
|
||||
pronouns: {
|
||||
any: {
|
||||
short: 'any',
|
||||
},
|
||||
},
|
||||
};
|
||||
mockTranslations(translations);
|
||||
|
||||
const { default: pronouns } = await import('./fixtures/pronouns.js');
|
||||
const { default: translator } = await import('../src/translator.js');
|
||||
|
||||
describe('when merging pronoun groups by key', () => {
|
||||
test('groups without keys are not assigned a merged group', () => {
|
||||
@ -21,18 +32,18 @@ describe('when merging pronoun groups by key', () => {
|
||||
const library = new PronounLibrary(groups, pronouns);
|
||||
expect(library.byKey()).toEqual(
|
||||
{
|
||||
'normative': [
|
||||
'normative': new MergedPronounGroup('normative', [
|
||||
{
|
||||
group: groups[0],
|
||||
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
||||
},
|
||||
],
|
||||
'normative-ish': [
|
||||
]),
|
||||
'normative-ish': new MergedPronounGroup('normative-ish', [
|
||||
{
|
||||
group: groups[1],
|
||||
groupPronouns: { they: pronouns.they },
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
);
|
||||
});
|
||||
@ -45,7 +56,7 @@ describe('when merging pronoun groups by key', () => {
|
||||
const library = new PronounLibrary(groups, pronouns);
|
||||
expect(library.byKey()).toEqual(
|
||||
{
|
||||
'normative-ish': [
|
||||
'normative-ish': new MergedPronounGroup('normative-ish', [
|
||||
{
|
||||
group: groups[0],
|
||||
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
||||
@ -54,8 +65,38 @@ describe('when merging pronoun groups by key', () => {
|
||||
group: groups[1],
|
||||
groupPronouns: { they: pronouns.they },
|
||||
},
|
||||
],
|
||||
]),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when displaying merged groups', () => {
|
||||
test('and no group specific translation is available, the key is used', () => {
|
||||
const group = new PronounGroup('Binary forms', ['he', 'she'], null, 'normative-ish');
|
||||
const merged = new MergedPronounGroup('normative', [
|
||||
{
|
||||
group,
|
||||
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
||||
},
|
||||
]);
|
||||
expect(merged.short(translator)).toBe('any normative');
|
||||
});
|
||||
|
||||
test('and a group specific translation is available, the translation is used', () => {
|
||||
translations.pronouns.any.group = {
|
||||
'normative': {
|
||||
short: 'both binaries',
|
||||
},
|
||||
};
|
||||
|
||||
const group = new PronounGroup('Binary forms', ['he', 'she'], null, 'normative-ish');
|
||||
const merged = new MergedPronounGroup('normative', [
|
||||
{
|
||||
group,
|
||||
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
||||
},
|
||||
]);
|
||||
expect(merged.short(translator)).toBe('both binaries');
|
||||
});
|
||||
});
|
||||
|
12
test/fixtures/translations.js
vendored
Normal file
12
test/fixtures/translations.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { jest } from '@jest/globals';
|
||||
|
||||
const __dirname = new URL('.', import.meta.url).pathname;
|
||||
|
||||
export const mockTranslations = translations => {
|
||||
jest.unstable_mockModule(`${__dirname}/../../data/translations.suml`, () => {
|
||||
return { default: translations };
|
||||
});
|
||||
jest.unstable_mockModule(`${__dirname}/../../locale/_base/translations.suml`, () => {
|
||||
return { default: {} };
|
||||
});
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user