-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The objective is to make the code more readable.
- Loading branch information
1 parent
caf88a5
commit e12ce9c
Showing
6 changed files
with
103 additions
and
94 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,92 @@ | ||
"use strict"; | ||
|
||
import { httpGet, tomlToJson } from "./utils"; | ||
|
||
// Load the afrim configuration through an URL. | ||
export async function loadConfig(path) { | ||
var content = await httpGet(path).then((data) => tomlToJson(data)); | ||
var auto_capitalize = false; | ||
const content = await httpGet(path).then((data) => tomlToJson(data)); | ||
let auto_capitalize = false; | ||
|
||
if (content.core) { | ||
auto_capitalize = content.core.auto_capitalize || false; | ||
} | ||
|
||
if (typeof content.translation == "object") { | ||
var items = await Object.entries(content.translation); | ||
const items = await Object.entries(content.translation); | ||
|
||
for (let item of items) { | ||
var key = item[0]; | ||
var value = item[1]; | ||
for (const item of items) { | ||
const key = item[0]; | ||
const value = item[1]; | ||
|
||
// We extract the translation. | ||
if (typeof value == "object") { | ||
if (value.path) { | ||
await loadConfig(new URL(value.path, path).href); | ||
} else if (value.alias) { | ||
var _ = null; | ||
let _ = null; | ||
|
||
if (value.values) { | ||
_ = value.values; | ||
} else { | ||
_ = [value.value]; | ||
} | ||
|
||
for (let e of value.alias) { | ||
global.memory.dictionary[e] = _; | ||
for (const e of value.alias) { | ||
global.afrim.dictionary[e] = _; | ||
} | ||
global.memory.dictionary[key] = _; | ||
global.afrim.dictionary[key] = _; | ||
} | ||
} else { | ||
global.memory.dictionary[key] = [value]; | ||
global.afrim.dictionary[key] = [value]; | ||
} | ||
} | ||
} | ||
|
||
// We extract the data. | ||
if (typeof content.data == "object") { | ||
var items = await Object.entries(content.data); | ||
const items = await Object.entries(content.data); | ||
|
||
for (let item of items) { | ||
var key = item[0]; | ||
var value = item[1]; | ||
for (const item of items) { | ||
const key = item[0]; | ||
const value = item[1]; | ||
|
||
if (typeof value == "object") { | ||
if (value.path) { | ||
await loadConfig(new URL(value.path, path).href); | ||
} else if (value.alias) { | ||
for (let e of value.alias) { | ||
global.memory.data[e] = value.value; | ||
for (const e of value.alias) { | ||
global.afrim.data[e] = value.value; | ||
|
||
if (auto_capitalize) { | ||
global.memory.data[e[0].toUpperCase() + e.slice(1)] = | ||
global.afrim.data[e[0].toUpperCase() + e.slice(1)] = | ||
value.value.toUpperCase(); | ||
} | ||
} | ||
global.memory.data[key] = value.value; | ||
global.afrim.data[key] = value.value; | ||
|
||
if (auto_capitalize) { | ||
global.memory.data[key[0].toUpperCase() + key.slice(1)] = | ||
global.afrim.data[key[0].toUpperCase() + key.slice(1)] = | ||
value.value.toUpperCase(); | ||
} | ||
} | ||
} else { | ||
global.memory.data[key] = value; | ||
global.afrim.data[key] = value; | ||
} | ||
} | ||
} | ||
|
||
// We extract the translators. | ||
if (typeof content.translator == "object") { | ||
var items = await Object.entries(content.translator); | ||
const items = await Object.entries(content.translator); | ||
|
||
for (let item of items) { | ||
var key = item[0]; | ||
var value = item[1]; | ||
var content = await httpGet(new URL(value, path).href).then( | ||
for (const item of items) { | ||
const key = item[0]; | ||
const value = item[1]; | ||
const content = await httpGet(new URL(value, path).href).then( | ||
(data) => data, | ||
); | ||
|
||
global.memory.translators[key] = content; | ||
global.afrim.translators[key] = content; | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.