[bugfix/enhancement] Fixes german translations being sentence-case (#491)

* Fixes german translations' case (#490).

* Smaller improvements to german translations.

* Changes to sentenceCasePostProcessor.
This commit is contained in:
lymnyx 2024-02-04 14:47:52 +00:00 committed by GitHub
parent 6520a105d2
commit 29df2a6215
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 22 deletions

View file

@ -1,4 +1,4 @@
import { PostProcessorModule } from 'i18next';
import { PostProcessorModule, TOptions, StringMap } from 'i18next';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import en from './locales/en.json';
@ -125,16 +125,18 @@ const titleCasePostProcessor: PostProcessorModule = {
},
};
const ignoreSentenceCaseLanguages = ['de']
const sentenceCasePostProcessor: PostProcessorModule = {
type: 'postProcessor',
name: 'sentenceCase',
process: (value: string) => {
process: (value: string, _key: string, _options: TOptions<StringMap>, translator: any) => {
const sentences = value.split('. ');
return sentences
.map((sentence) => {
return (
sentence.charAt(0).toLocaleUpperCase() + sentence.slice(1).toLocaleLowerCase()
sentence.charAt(0).toLocaleUpperCase() + (!ignoreSentenceCaseLanguages.includes(translator.language) ? sentence.slice(1).toLocaleLowerCase() : sentence.slice(1))
);
})
.join('. ');