Implement age-based gender labels in FalukantWidget and update translations: Added logic to determine gender labels based on age groups and updated locale files for German and English.
This commit is contained in:
@@ -45,17 +45,19 @@ export default {
|
||||
const g = this.falukantData?.gender;
|
||||
if (g == null || g === '') return '—';
|
||||
|
||||
// Altersabhängige Bezeichnung (sprachlich natürlicher im Widget)
|
||||
// Default: unter 18 = Junge/Mädchen, sonst Mann/Frau
|
||||
const age = Number(this.falukantData?.age);
|
||||
const isChild = !Number.isNaN(age) && age < 18;
|
||||
if (g === 'female') return isChild ? 'Mädchen' : 'Frau';
|
||||
if (g === 'male') return isChild ? 'Junge' : 'Mann';
|
||||
// Altersabhängige, (auf Wunsch) altertümlichere Bezeichnungen
|
||||
const age = Number(this.falukantData?.age);
|
||||
const group = this._getAgeGroupKey(age);
|
||||
if (group && (g === 'female' || g === 'male')) {
|
||||
const key = `falukant.genderAge.${g}.${group}`;
|
||||
const t = this.$t(key);
|
||||
if (t !== key) return t;
|
||||
}
|
||||
|
||||
// Fallback auf vorhandene Übersetzungen
|
||||
const key = `falukant.create.${g}`;
|
||||
const t = this.$t(key);
|
||||
return t === key ? this.$t(`general.gender.${g}`) || g : t;
|
||||
// Fallback auf vorhandene Übersetzungen
|
||||
const key = `falukant.create.${g}`;
|
||||
const t = this.$t(key);
|
||||
return t === key ? this.$t(`general.gender.${g}`) || g : t;
|
||||
},
|
||||
falukantAgeLabel() {
|
||||
const ageValue = this.falukantData?.age;
|
||||
@@ -65,6 +67,31 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
_getAgeGroupKey(age) {
|
||||
const a = Number(age);
|
||||
if (Number.isNaN(a)) return null;
|
||||
|
||||
// Pro Sprache konfigurierbare Schwellenwerte aus i18n.
|
||||
// Format: "key:maxAge|key2:maxAge2|..." (maxAge exklusiv, letzte Gruppe sollte hoch gesetzt sein)
|
||||
const raw = this.$t('falukant.genderAge.ageGroups');
|
||||
const parsed = typeof raw === 'string' ? raw : '';
|
||||
const rules = parsed.split('|')
|
||||
.map(part => part.trim())
|
||||
.filter(Boolean)
|
||||
.map(part => {
|
||||
const [key, num] = part.split(':').map(s => (s ?? '').trim());
|
||||
return { key, max: Number(num) };
|
||||
})
|
||||
.filter(r => r.key && !Number.isNaN(r.max))
|
||||
.sort((x, y) => x.max - y.max);
|
||||
|
||||
for (const r of rules) {
|
||||
if (a < r.max) return r.key;
|
||||
}
|
||||
|
||||
// Fallback, falls Konfig kaputt ist
|
||||
return 'adult';
|
||||
},
|
||||
formatMoney(value) {
|
||||
const n = Number(value);
|
||||
if (Number.isNaN(n)) return '—';
|
||||
|
||||
Reference in New Issue
Block a user