source: main/trunk/model-interfaces-dev/atea/macron-restoration/src/main.js@ 35741

Last change on this file since 35741 was 35741, checked in by cstephen, 2 years ago

Fix translation resolution

File size: 2.4 KB
Line 
1import { createApp } from "vue";
2import { createStore } from "vuex"
3import Util from "./js/Util"
4import App from "./App.vue";
5import ToggleButton from "./components/ToggleButton.vue"
6
7const store = createStore({
8 state() {
9 return {
10 /** @type {Map<String, String>} */
11 translations: new Map(),
12 macronisedFileInfos: [],
13 directInput: null,
14 directOutput: []
15 }
16 },
17 mutations: {
18 setTranslations(state, translations) {
19 state.translations = translations;
20 },
21 pushFileInfo(state, fileInfo) {
22 state.macronisedFileInfos.push({
23 id: Util.generateUuid(),
24 ...fileInfo
25 });
26 },
27 setDirectInput(state, input) {
28 state.directInput = input;
29 },
30 setDirectOutput(state, output) {
31 state.directOutput = output;
32 }
33 }
34});
35
36const app = createApp(App);
37
38app.use(store);
39app.component("ToggleButton", ToggleButton)
40 .mount("#app");
41
42/* === Get interface translations === */
43
44/** @type {Map<String, String>} */
45const translations = new Map();
46
47/* We might be running under Greenstone, so pull the tranlsations from there if so */
48/* eslint-disable no-undef */
49if (typeof gs !== "undefined" && gs.text && gs.text.atea && gs.text.atea.macroniser) {
50 for (const key in gs.text.atea.macroniser) {
51 translations.set(key, gs.text.atea.macroniser[key]);
52 }
53
54 store.commit("setTranslations", translations)
55}
56/* eslint-enable no-undef */
57else {
58 fetch("resources/interface_atea.properties")
59 .then(
60 async response => {
61 const responseText = await response.text();
62 const responseTranslations = responseText.split("\n");
63
64 for (const translation of responseTranslations) {
65 const keyvalue = translation.split("=");
66
67 if (keyvalue.length !== 2) {
68 continue;
69 }
70
71 const namespace = keyvalue[0].split(".");
72 if (namespace.length !== 3 || namespace[1] !== "macroniser") {
73 continue;
74 }
75
76 translations.set(namespace[namespace.length - 1], keyvalue[1]);
77 }
78
79 store.commit("setTranslations", translations)
80 }
81 );
82}
Note: See TracBrowser for help on using the repository browser.