Skip to content

Commit bc88edf

Browse files
authored
Hide audio writing systems from UI (#1659)
* add `IsAudio` to the writing system * hide audio writing systems from frontend * use language tag parsing to determine if it's an audio writing system * validate that all well known writing systems can be parsed
1 parent 6af9878 commit bc88edf

File tree

9 files changed

+42
-6
lines changed

9 files changed

+42
-6
lines changed

backend/FwLite/MiniLcm.Tests/WritingSystemIdTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@
22

33
public class WritingSystemIdTests
44
{
5+
public static IEnumerable<object[]> ValidWritingSystemIds =>
6+
WritingSystemCodes.ValidTwoLetterCodes.Select(code => new object[] { code });
7+
58
[Theory]
9+
[MemberData(nameof(ValidWritingSystemIds))]
610
[InlineData("en")]
711
[InlineData("th")]
12+
[InlineData("xba")]
813
[InlineData("en-Zxxx-x-audio")]
914
public void ValidWritingSystemId_ShouldNotThrow(string code)
1015
{
1116
var ws = new WritingSystemId(code);
1217
ws.Should().NotBe(default);
1318
}
1419

20+
[Theory]
21+
[InlineData("en-Zxxx-x-audio")]
22+
[InlineData("seh-Zxxx-x-audio-var")]
23+
public void DetectsAudioWritingSystems(string code)
24+
{
25+
var ws = new WritingSystemId(code);
26+
ws.IsAudio.Should().BeTrue();
27+
}
28+
1529
[Theory]
1630
[InlineData("gx")]
1731
[InlineData("oo")]

backend/FwLite/MiniLcm/Models/WritingSystem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public record WritingSystem: IObjectWithId<WritingSystem>
66
{
77
public required Guid Id { get; set; }
88
public virtual required WritingSystemId WsId { get; set; }
9+
public bool IsAudio => WsId.IsAudio;
910
public virtual required string Name { get; set; }
1011
public virtual required string Abbreviation { get; set; }
1112
public virtual required string Font { get; set; }

backend/FwLite/MiniLcm/Models/WritingSystemId.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,27 @@ public override void WriteAsPropertyName(Utf8JsonWriter writer, WritingSystemId
3030
public readonly record struct WritingSystemId: ISpanFormattable, ISpanParsable<WritingSystemId>
3131
{
3232
public string Code { get; init; }
33+
public bool IsAudio { get; } = false;
3334

3435
public static readonly WritingSystemId Default = "default";
3536

3637
public WritingSystemId(string code)
3738
{
3839
//__key is used by the LfClassicMiniLcmApi to smuggle non guid ids with possibilitie lists
39-
if (code == "default" || code == "__key" || IetfLanguageTag.IsValid(code))
40+
if (code == "default" || code == "__key")
4041
{
4142
Code = code;
4243
}
44+
else if (IetfLanguageTag.TryGetParts(code,
45+
out string? subtag,
46+
out string? script,
47+
out string? region,
48+
out string? variants))
49+
{
50+
Code = code;
51+
IsAudio = script?.Equals(WellKnownSubtags.AudioScript, StringComparison.OrdinalIgnoreCase) == true &&
52+
variants?.Split('-').Any(v => v == WellKnownSubtags.AudioPrivateUse) == true;
53+
}
4354
else
4455
{
4556
throw new ArgumentException($"Invalid writing system ID '{code}'", nameof(code));

frontend/viewer/src/SvelteUxProjectView.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@
119119
120120
const writingSystemService = initWritingSystemService(deriveAsync(connected, isConnected => {
121121
if (!isConnected) return Promise.resolve(null);
122-
return lexboxApi.getWritingSystems();
122+
return lexboxApi.getWritingSystems().then(ws => {
123+
return {analysis: ws.analysis.filter(ws => !ws.isAudio), vernacular: ws.vernacular.filter(ws => !ws.isAudio)};
124+
});
123125
}).value);
124126
125127
const trigger = writable(0);

frontend/viewer/src/lib/demo-entry-data.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export const writingSystems: IWritingSystems = {
4040
'font': '???',
4141
'exemplars': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
4242
'type': WritingSystemType.Analysis,
43-
'order': 0
43+
'order': 0,
44+
isAudio: false,
4445
},
4546
{
4647
'id': 'pt',
@@ -50,7 +51,8 @@ export const writingSystems: IWritingSystems = {
5051
'font': '???',
5152
'exemplars': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
5253
'type': WritingSystemType.Analysis,
53-
'order': 1
54+
'order': 1,
55+
isAudio: false,
5456
}
5557
],
5658
'vernacular': [
@@ -62,7 +64,8 @@ export const writingSystems: IWritingSystems = {
6264
'font': '???',
6365
'exemplars': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
6466
'type': WritingSystemType.Vernacular,
65-
'order': 0
67+
'order': 0,
68+
isAudio: false,
6669
},
6770
{
6871
'id': 'seh-fonipa-x-etic',
@@ -72,7 +75,8 @@ export const writingSystems: IWritingSystems = {
7275
'font': '???',
7376
'exemplars': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
7477
'type': WritingSystemType.Vernacular,
75-
'order': 1
78+
'order': 1,
79+
isAudio: false,
7680
}
7781
]
7882
};

frontend/viewer/src/lib/dotnet-types/generated-types/MiniLcm/Models/IWritingSystem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface IWritingSystem extends IObjectWithId
1010
{
1111
id: string;
1212
wsId: string;
13+
isAudio: boolean;
1314
name: string;
1415
abbreviation: string;
1516
font: string;

frontend/viewer/src/lib/entry-editor/field-editors/MultiOptionEditor.test.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const context = new Map<string, unknown>([
2828
exemplars: ['test'],
2929
order: 0,
3030
type: WritingSystemType.Vernacular,
31+
isAudio: false,
3132
}],
3233
}))],
3334
['currentView', readable(views[0])],

frontend/viewer/src/lib/sandbox/OptionSandbox.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
exemplars: [],
1919
type: WritingSystemType.Analysis,
2020
order: 0,
21+
isAudio: false,
2122
}],
2223
vernacular: [],
2324
}));

frontend/viewer/src/lib/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function defaultWritingSystem(type: WritingSystemType): IWritingSystem {
6161
return {
6262
id: randomId(),
6363
wsId: 'en',
64+
isAudio: false,
6465
name: 'English',
6566
abbreviation: 'en',
6667
font: 'Arial',

0 commit comments

Comments
 (0)