Skip to content

Commit

Permalink
Changes to sentenceCasePostProcessor.
Browse files Browse the repository at this point in the history
  • Loading branch information
lymnyx committed Feb 4, 2024
1 parent 58aae26 commit 1d8af79
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -125,9 +125,25 @@ const titleCasePostProcessor: PostProcessorModule = {
},
};

const sentenceCasePostProcessor: PostProcessorModule = {
type: 'postProcessor',
name: 'sentenceCase',
process: (value: string, _: string, __: TOptions<StringMap>, translator: any) => {
const sentences = value.split('. ');

return sentences
.map((sentence) => {
return (
sentence.charAt(0).toLocaleUpperCase() + (translator.language !== 'de' ? sentence.slice(1).toLocaleLowerCase() : sentence.slice(1))
);
})
.join('. ');
},
};
i18n.use(lowerCasePostProcessor)
.use(upperCasePostProcessor)
.use(titleCasePostProcessor)
.use(sentenceCasePostProcessor)
.use(initReactI18next) // passes i18n down to react-i18next
.init({
fallbackLng: 'en',
Expand Down

0 comments on commit 1d8af79

Please sign in to comment.