mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -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: >
|
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.
|
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}.'
|
options: 'Überprüfe die Optionen [share]{/pronomen=hier}.'
|
||||||
|
group:
|
||||||
|
neopronomen:
|
||||||
|
short: 'alle Neopronomen'
|
||||||
|
sonderzeichen:
|
||||||
|
short: 'alle mit Sonderzeichen'
|
||||||
comprehensive:
|
comprehensive:
|
||||||
simple: 'häufige'
|
simple: 'häufige'
|
||||||
comprehensive: 'erweitert'
|
comprehensive: 'erweitert'
|
||||||
|
@ -10,6 +10,7 @@ export default ({ app, store }) => {
|
|||||||
|
|
||||||
Vue.prototype.$base = process.env.BASE_URL;
|
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.$t = (key, params = {}, warn = false) => translator.translate(key, params, warn);
|
||||||
Vue.prototype.$te = (key, fallback = false) => {
|
Vue.prototype.$te = (key, fallback = false) => {
|
||||||
if (translator.has(key)) {
|
if (translator.has(key)) {
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
<div class="alert alert-primary">
|
<div class="alert alert-primary">
|
||||||
<h2 class="text-center mb-0">
|
<h2 class="text-center mb-0">
|
||||||
<strong>
|
<strong>
|
||||||
<T>pronouns.any.short</T>
|
<Spelling :text="short"/>
|
||||||
<span v-if="groupKey">{{groupKey}}</span>
|
|
||||||
</strong>
|
</strong>
|
||||||
</h2>
|
</h2>
|
||||||
<p class="h6 small text-center mb-0 mt-2">
|
<p class="h6 small text-center mb-0 mt-2">
|
||||||
@ -71,13 +70,18 @@
|
|||||||
data() {
|
data() {
|
||||||
const groupKey = this.$route.params.group;
|
const groupKey = this.$route.params.group;
|
||||||
let pronounGroups = [];
|
let pronounGroups = [];
|
||||||
|
let short;
|
||||||
if (groupKey) {
|
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 {
|
return {
|
||||||
examples,
|
examples,
|
||||||
groupKey,
|
short,
|
||||||
pronounGroups,
|
pronounGroups,
|
||||||
|
|
||||||
comprehensive: false,
|
comprehensive: false,
|
||||||
@ -85,7 +89,7 @@
|
|||||||
},
|
},
|
||||||
head() {
|
head() {
|
||||||
return 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`,
|
banner: `api/banner/${this.$t('pronouns.any.short')}.png`,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -212,8 +212,10 @@
|
|||||||
<li>
|
<li>
|
||||||
<nuxt-link :to="`/${config.pronouns.any}`"><T>pronouns.any.short</T></nuxt-link>
|
<nuxt-link :to="`/${config.pronouns.any}`"><T>pronouns.any.short</T></nuxt-link>
|
||||||
</li>
|
</li>
|
||||||
<li v-for="(keyPronouns, key) in pronounLibrary.byKey()">
|
<li v-for="(merged, key) in pronounLibrary.byKey()" :key="key">
|
||||||
<nuxt-link :to="`/${config.pronouns.any}:${key}`"><T>pronouns.any.short</T> {{key}}</nuxt-link>
|
<nuxt-link :to="`/${config.pronouns.any}:${key}`">
|
||||||
|
<Spelling :text="merged.short($translator)"/>
|
||||||
|
</nuxt-link>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</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 {
|
export class PronounLibrary {
|
||||||
constructor(groups, pronouns) {
|
constructor(groups, pronouns) {
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
@ -622,7 +638,9 @@ export class PronounLibrary {
|
|||||||
const ret = {};
|
const ret = {};
|
||||||
for (let g of this.groups) {
|
for (let g of this.groups) {
|
||||||
if (g.key === null) { continue; }
|
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 = {};
|
const p = {};
|
||||||
for (let t of g.pronouns) {
|
for (let t of g.pronouns) {
|
||||||
@ -631,7 +649,7 @@ export class PronounLibrary {
|
|||||||
p[pronoun.canonicalName] = pronoun;
|
p[pronoun.canonicalName] = pronoun;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret[g.key].push({ group: g, groupPronouns: p});
|
ret[g.key].groups.push({ group: g, groupPronouns: p});
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { beforeEach, describe, expect, jest, test } from '@jest/globals';
|
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
|
// workaround to be independent of the current selected locale
|
||||||
jest.unstable_mockModule('../data/pronouns/morphemes.js', () => {
|
jest.unstable_mockModule('../data/pronouns/morphemes.js', () => {
|
||||||
|
@ -1,8 +1,19 @@
|
|||||||
import { describe, expect, test } from '@jest/globals';
|
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', () => {
|
describe('when merging pronoun groups by key', () => {
|
||||||
test('groups without keys are not assigned a merged group', () => {
|
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);
|
const library = new PronounLibrary(groups, pronouns);
|
||||||
expect(library.byKey()).toEqual(
|
expect(library.byKey()).toEqual(
|
||||||
{
|
{
|
||||||
'normative': [
|
'normative': new MergedPronounGroup('normative', [
|
||||||
{
|
{
|
||||||
group: groups[0],
|
group: groups[0],
|
||||||
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
||||||
},
|
},
|
||||||
],
|
]),
|
||||||
'normative-ish': [
|
'normative-ish': new MergedPronounGroup('normative-ish', [
|
||||||
{
|
{
|
||||||
group: groups[1],
|
group: groups[1],
|
||||||
groupPronouns: { they: pronouns.they },
|
groupPronouns: { they: pronouns.they },
|
||||||
},
|
},
|
||||||
],
|
]),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -45,7 +56,7 @@ describe('when merging pronoun groups by key', () => {
|
|||||||
const library = new PronounLibrary(groups, pronouns);
|
const library = new PronounLibrary(groups, pronouns);
|
||||||
expect(library.byKey()).toEqual(
|
expect(library.byKey()).toEqual(
|
||||||
{
|
{
|
||||||
'normative-ish': [
|
'normative-ish': new MergedPronounGroup('normative-ish', [
|
||||||
{
|
{
|
||||||
group: groups[0],
|
group: groups[0],
|
||||||
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
groupPronouns: { he: pronouns.he, she: pronouns.she },
|
||||||
@ -54,8 +65,38 @@ describe('when merging pronoun groups by key', () => {
|
|||||||
group: groups[1],
|
group: groups[1],
|
||||||
groupPronouns: { they: pronouns.they },
|
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