You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
1.4 KiB

import { describe, expect, it } from 'vitest'
import { detectReadAloudContentLanguage } from '@/lib/read-aloud-content-language'
describe('detectReadAloudContentLanguage', () => {
it('detects German from umlauts', () => {
expect(detectReadAloudContentLanguage('Grüße aus München und Spaß')).toBe('de')
})
it('detects plain ASCII English', () => {
expect(detectReadAloudContentLanguage('Hello this is a test note about nothing special.')).toBe('en')
})
it('prefers British English when UK spellings dominate', () => {
const s =
'The colour of the behaviour was odd; we organised a favourable defence of the centre.'
expect(detectReadAloudContentLanguage(s)).toBe('en-gb')
})
it('prefers US English when American spellings dominate', () => {
const s = 'The color and behavior at the center were organized with a traveling neighbor.'
expect(detectReadAloudContentLanguage(s)).toBe('en')
})
it('detects Russian from Cyrillic', () => {
expect(detectReadAloudContentLanguage('Привет мир это тест')).toBe('ru')
})
it('detects Polish', () => {
expect(detectReadAloudContentLanguage('Cześć, to jest żółć i łódź.')).toBe('pl')
})
it('detects Turkish from distinctive letters (avoid ü so German is not triggered)', () => {
expect(detectReadAloudContentLanguage('Merhaba, dağ ve şeker \u0130stanbul.')).toBe('tr')
})
})