summaryrefslogtreecommitdiff
path: root/src/language.ts
blob: 2d0f547de6411e09febaf15c803ff4eba7fb1b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
export enum VowelHeight {
	Open,
	NearOpen,
	OpenMid,
	Mid,
	CloseMid,
	NearClose,
	Close,
}
export enum VowelDepth {
	Front,
	Central,
	Back,
}
export interface VowelFeatures {
	height: VowelHeight;
	depth: VowelDepth;
	round: boolean;
	long: boolean;
	nasal: boolean;
}
export function vowelFeaturesToIpa(features: VowelFeatures): string {
	const ipa = () => {
		switch (features.height) {
			case VowelHeight.Open:
			switch (features.depth) {
				case VowelDepth.Front:
				return features.round ? 'ɶ' : 'a';
				case VowelDepth.Central:
				return features.round ? 'ɞ' : 'ä';
				case VowelDepth.Back:
				return features.round ? 'ɒ' : 'ɑ';
			}

			case VowelHeight.NearOpen:
			switch (features.depth) {
				case VowelDepth.Front:
				return features.round ? 'ɶ' : 'æ';
				case VowelDepth.Central:
				return features.round ? 'ɞ' : 'ɐ';
				case VowelDepth.Back:
				return features.round ? 'ɒ' : 'ɑ';
			}

			case VowelHeight.OpenMid:
			switch (features.depth) {
				case VowelDepth.Front:
				return features.round ? 'œ' : 'ɛ';
				case VowelDepth.Central:
				return features.round ? 'ɞ' : 'ɜ';
				case VowelDepth.Back:
				return features.round ? 'ɒ' : 'ɑ';
			}

			case VowelHeight.Mid:
			switch (features.depth) {
				case VowelDepth.Front:
				return features.round ? 'ø̞' : 'e̞';
				case VowelDepth.Central:
				return features.round ? 'ɵ' : 'ə';
				case VowelDepth.Back:
				return features.round ? 'o̞' : 'ɤ̞';
			}

			case VowelHeight.CloseMid:
			switch (features.depth) {
				case VowelDepth.Front:
				return features.round ? 'ø' : 'e';
				case VowelDepth.Central:
				return features.round ? 'ɵ' : 'ɘ';
				case VowelDepth.Back:
				return features.round ? 'o' : 'ɤ';
			}

			case VowelHeight.NearClose:
			switch (features.depth) {
				case VowelDepth.Front:
				return features.round ? 'ʏ' : 'ɪ';
				case VowelDepth.Central:
				return features.round ? 'ʉ' : 'ɨ';
				case VowelDepth.Back:
				return features.round ? 'u' : 'ʊ';
			}

			case VowelHeight.Close:
			switch (features.depth) {
				case VowelDepth.Front:
				return features.round ? 'y' : 'i';
				case VowelDepth.Central:
				return features.round ? 'ʉ' : 'ɨ';
				case VowelDepth.Back:
				return features.round ? 'u' : 'ɯ';
			}

			default:
			throw new Error(`bad vowel height: ${features.height}`);
		}
	};

	const nasal = features.nasal ? '̃' : '';
	const vlong = features.long ? 'ː' : '';
	return ipa() + nasal + vlong;
}