-
Notifications
You must be signed in to change notification settings - Fork 4
/
app-lang-auto.ts
87 lines (71 loc) · 1.93 KB
/
app-lang-auto.ts
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
import { App, WindowCreation, WindowFlag, Window, CultureId, Button, Grid } from "../../../src";
interface ILang {
// ave built-in language key
AppTitle: string;
// user defined key
SwitchLang: string;
}
interface Ii18n {
t(key: keyof ILang): string;
switch(id: CultureId): void;
lang: Partial<Record<CultureId, ILang>>;
}
export function run() {
const app = new App();
const i18n: Ii18n = {
t(key: keyof ILang) {
return app.LangGetString(key);
},
switch(this: Ii18n, id: CultureId) {
app.LangSetDefaultString(id, this.lang[id]);
app.LangSetCurrent(id);
},
lang: {
[CultureId.en_us]: {
AppTitle: "My App",
SwitchLang: "Switch Lang",
},
[CultureId.zh_cn]: {
AppTitle: "我的应用",
SwitchLang: "切换语言",
},
},
};
globalThis.app = app;
const cpWindow = new WindowCreation();
cpWindow.Flag |= WindowFlag.Layered;
const window = new Window(cpWindow);
globalThis._window = window;
window.OnCreateContent((sender) => {
//
let lang = CultureId.en_us;
i18n.switch(lang);
//
const button = new Button(window, "SwitchLang" as keyof ILang);
button.OnClick((sender) => {
if (lang === CultureId.en_us) {
lang = CultureId.zh_cn;
} else if (lang === CultureId.zh_cn) {
lang = CultureId.en_us;
}
i18n.switch(lang);
});
const container = getControlDemoContainer(window);
container.ControlAdd(button).SetGrid(1, 1);
window.SetContent(container);
return true;
});
if (!window.CreateWindow()) process.exit(-1);
window.SetVisible(true);
window.Activate();
}
function getControlDemoContainer(window: Window, count = 1, width = 120, height = 32) {
const container = new Grid(window);
container.ColAddSlice(1);
container.ColAddDpx(...Array.from<number>({ length: count }).fill(width));
container.ColAddSlice(1);
container.RowAddSlice(1);
container.RowAddDpx(...Array.from<number>({ length: count }).fill(height));
container.RowAddSlice(1);
return container;
}