Skip to content

Commit

Permalink
Export _ from language
Browse files Browse the repository at this point in the history
  • Loading branch information
MyIgel authored and weeman1337 committed Jan 16, 2024
1 parent 7c43981 commit 2489727
Show file tree
Hide file tree
Showing 22 changed files with 23 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/about.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { _ } from "./utils/language";
import { CanRender } from "./container";

export const About = function (picturesSource: string, picturesLicense: string): CanRender {
function render(d: HTMLElement) {
let _ = window._;
d.innerHTML =
_.t("sidebar.aboutInfo") +
"<h4>" +
Expand Down
2 changes: 1 addition & 1 deletion lib/filters/filtergui.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _ } from "../utils/language";
import { CanFiltersChanged, DataDistributor, Filter } from "../datadistributor";
import { CanRender } from "../container";

Expand All @@ -16,7 +17,6 @@ export const FilterGui = function (distributor: ReturnType<typeof DataDistributo
}

filters.forEach(function (filter: Filter & CanRender) {
let _ = window._;
let li = document.createElement("li");
container.appendChild(li);
filter.render(li);
Expand Down
2 changes: 1 addition & 1 deletion lib/filters/hostname.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _ } from "../utils/language";
import { Node } from "../utils/node";
import { CanRender } from "../container";
import { Filter } from "../datadistributor";
Expand Down Expand Up @@ -25,7 +26,6 @@ export const HostnameFilter = function (): CanRender & Filter {
}

function render(el: HTMLElement) {
let _ = window._;
input.type = "search";
input.placeholder = _.t("sidebar.nodeFilter");
input.setAttribute("aria-label", _.t("sidebar.nodeFilter"));
Expand Down
1 change: 0 additions & 1 deletion lib/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ declare global {
interface Window {
config: Config;
router: ReturnType<typeof Router>;
_: Polyglot & { phrases?: { [k: string]: any } };
}
}
3 changes: 1 addition & 2 deletions lib/gui.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { interpolate } from "d3-interpolate";

import { _ } from "./utils/language";
import { About } from "./about";
import { Container } from "./container";
import { DataDistributor } from "./datadistributor";
Expand Down Expand Up @@ -27,7 +27,6 @@ export const Gui = function (language: ReturnType<typeof Language>) {
let contentDiv: HTMLDivElement;
let router = window.router;
let config = window.config;
let _ = window._;

let linkScale = interpolate(config.map.tqFrom, config.map.tqTo);
let sidebar: ReturnType<typeof Sidebar>;
Expand Down
3 changes: 1 addition & 2 deletions lib/infobox/link.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";
import { _ } from "../utils/language";
import * as helper from "../utils/helper";
import { LinkInfo } from "../config_default";
import { Link as LinkData } from "../utils/node";

function showStatImg(images: HTMLElement[], linkInfo: LinkInfo, link: LinkData, time: string) {
let _ = window._;
let subst: ReplaceMapping = {
"{SOURCE_ID}": link.source.node_id,
"{SOURCE_NAME}": link.source.hostname.replace(/[^a-z0-9\-]/gi, "_"),
Expand Down Expand Up @@ -36,7 +36,6 @@ export const Link = function (el: HTMLElement, linkData: LinkData[], linkScale:
el.appendChild(images);

self.render = function render() {
let _ = window._;
let config = window.config;
let router = window.router;
let children = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/infobox/location.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { _ } from "../utils/language";
import * as helper from "../utils/helper";
import { TargetLocation } from "../utils/router";

export const location = function (el: HTMLElement, position: TargetLocation) {
let _ = window._;
let config = window.config;
let sidebarTitle = document.createElement("h2");
sidebarTitle.textContent = _.t("location.location");
Expand Down
2 changes: 1 addition & 1 deletion lib/infobox/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _ } from "../utils/language";
import { Link } from "./link";
import { Node } from "./node";
import { location } from "./location";
Expand Down Expand Up @@ -39,7 +40,6 @@ export const Main = function (sidebar: ReturnType<typeof Sidebar>, linkScale: (t
// @ts-ignore
el.destroy = destroy;

let _ = window._;
let router = window.router;
let closeButton = document.createElement("button");
closeButton.classList.add("close");
Expand Down
3 changes: 1 addition & 2 deletions lib/infobox/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";
import { _ } from "../utils/language";

import { SortTable } from "../sorttable";
import * as helper from "../utils/helper";
Expand All @@ -7,7 +8,6 @@ import { NodeInfo } from "../config_default";

function showStatImg(nodeInfo: NodeInfo, node: NodeData) {
let config = window.config;
let _ = window._;
let subst = {
"{NODE_ID}": node.node_id,
"{NODE_NAME}": node.hostname.replace(/[^a-z0-9\-]/gi, "_"),
Expand Down Expand Up @@ -42,7 +42,6 @@ function showDevicePictures(pictures: string, device: NodeData) {
}

export function Node(el: HTMLElement, node: NodeData, linkScale: (t: any) => any, nodeDict: { [k: NodeId]: NodeData }) {
let _ = window._;
let config = window.config;
let router = window.router;

Expand Down
2 changes: 1 addition & 1 deletion lib/legend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _ } from "./utils/language";
import * as helper from "./utils/helper";
import { Language } from "./utils/language";
import { ObjectsLinksAndNodes } from "./datadistributor";
Expand All @@ -11,7 +12,6 @@ export const Legend = function (language: ReturnType<typeof Language>) {
let timestamp = document.createTextNode("");

self.setData = function setData(data: ObjectsLinksAndNodes) {
let _ = window._;
let totalNodes = Object.keys(data.nodeDict).length;
let totalOnlineNodes = data.nodes.online.length;
let totalClients = helper.sum(
Expand Down
2 changes: 1 addition & 1 deletion lib/linklist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";
import { _ } from "./utils/language";
import { Heading, SortTable } from "./sorttable";
import * as helper from "./utils/helper";
import { Link } from "./utils/node";
Expand Down Expand Up @@ -42,7 +43,6 @@ let headings: Heading[] = [
];

export const Linklist = function (linkScale: (t: any) => any): CanRender & CanSetData {
let _ = window._;
let router = window.router;
let table = SortTable(headings, 3, renderRow);
const self = {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import moment from "moment";
import * as L from "leaflet";

import { _ } from "./utils/language";
import { Router } from "./utils/router";
import { Gui } from "./gui";
import { Language } from "./utils/language";
Expand Down Expand Up @@ -96,7 +97,6 @@ export const main = () => {
return new Promise(function (resolve, reject) {
let count = 0;
(function waitForLanguage() {
let _ = window._;
if (Object.keys(_.phrases).length > 0) {
resolve(nodesData);
} else if (count > 500) {
Expand Down
3 changes: 1 addition & 2 deletions lib/map/button.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as L from "leaflet";
import { _ } from "../utils/language";

import { LocationMarker } from "./locationmarker";

Expand Down Expand Up @@ -27,7 +28,6 @@ let ButtonBase = L.Control.extend({

let LocateButton = ButtonBase.extend({
onAdd: function () {
let _ = window._;
let button = L.DomUtil.create("button", "ion-locate");
button.setAttribute("aria-label", _.t("button.tracking"));
L.DomEvent.disableClickPropagation(button);
Expand All @@ -45,7 +45,6 @@ let LocateButton = ButtonBase.extend({

let CoordsPickerButton = ButtonBase.extend({
onAdd: function () {
let _ = window._;
let button = L.DomUtil.create("button", "ion-pin");
button.setAttribute("aria-label", _.t("button.location"));

Expand Down
2 changes: 1 addition & 1 deletion lib/nodelist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";
import { _ } from "./utils/language";
import { Heading, SortTable } from "./sorttable";
import * as helper from "./utils/helper";
import { Node } from "./utils/node";
Expand Down Expand Up @@ -57,7 +58,6 @@ let headings: Heading[] = [
];

export const Nodelist = function (): CanSetData & CanRender {
let _ = window._;
let router = window.router;
const self = {
render: undefined,
Expand Down
2 changes: 1 addition & 1 deletion lib/proportions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";
import * as d3Interpolate from "d3-interpolate";
import { _ } from "./utils/language";
import { DataDistributor, Filter, ObjectsLinksAndNodes } from "./datadistributor";
import { GenericNodeFilter } from "./filters/genericnode";
import * as helper from "./utils/helper";
Expand All @@ -14,7 +15,6 @@ export const Proportions = function (filterManager: ReturnType<typeof DataDistri
renderSingle: undefined,
};
let config = window.config;
let _ = window._;
let scale = d3Interpolate.interpolate(config.forceGraph.tqFrom, config.forceGraph.tqTo);
let time: Moment;

Expand Down
2 changes: 1 addition & 1 deletion lib/sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _ } from "./utils/language";
import { CanRender } from "./container";

export const Sidebar = function (el: HTMLElement) {
Expand All @@ -10,7 +11,6 @@ export const Sidebar = function (el: HTMLElement) {
container: undefined,
button: undefined,
};
let _ = window._;

// Needed to avoid render blocking
let gridBreakpoints = {
Expand Down
2 changes: 1 addition & 1 deletion lib/simplenodelist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import moment from "moment";
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";

import { _ } from "./utils/language";
import * as helper from "./utils/helper";
import { ObjectsLinksAndNodes } from "./datadistributor";
import { Node } from "./utils/node";
Expand Down Expand Up @@ -41,7 +42,6 @@ export const SimpleNodelist = function (nodesState: string, field: string, title
}

let items = nodeList.map(function (node: Node) {
let _ = window._;
let router = window.router;
let td0Content = "";
if (helper.hasLocation(node)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/sorttable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";
import { _ } from "./utils/language";

export interface Heading {
name: string;
Expand Down Expand Up @@ -31,7 +32,6 @@ export const SortTable = function (
}

function updateView() {
let _ = window._;
let children = [];

if (data.length !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/tabs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _ } from "./utils/language";
import { CanRender } from "./container";

export const Tabs = function () {
Expand Down Expand Up @@ -36,7 +37,6 @@ export const Tabs = function () {
}

self.add = function add(title: string, child: CanRender) {
let _ = window._;
let li = document.createElement("li");
li.textContent = _.t(title);
li.onclick = switchTab;
Expand Down
3 changes: 1 addition & 2 deletions lib/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Moment } from "moment";
import { snabbdomBundle as sv } from "snabbdom/snabbdom.bundle";
import { VNode } from "snabbdom/vnode";
import { Map } from "leaflet";
import { _ } from "./language";
import { Node } from "./node";
import { LinkInfo, NodeInfo } from "../config_default";

Expand Down Expand Up @@ -124,7 +125,6 @@ export const showTq = function showTq(tq: number) {
};

export const attributeEntry = function attributeEntry(V: typeof sv, children: VNode[], label: string, value: string) {
let _ = window._;
if (value !== undefined) {
if (typeof value !== "object") {
value = V.h("td", value);
Expand All @@ -135,7 +135,6 @@ export const attributeEntry = function attributeEntry(V: typeof sv, children: VN
};

export const showStat = function showStat(V: typeof sv, linkInfo: LinkInfo | NodeInfo, subst: ReplaceMapping) {
let _ = window._;
let content = V.h("img", {
attrs: {
src: listReplace(linkInfo.image, subst),
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Router } from "./router";

export type LanguageCode = string;

export let _: Polyglot & { phrases?: { [k: string]: any } };

export const Language = function () {
let router: ReturnType<typeof Router>;
let config = globalThis.config;
Expand Down Expand Up @@ -42,7 +44,6 @@ export const Language = function () {
}

function setTranslation(translationJson: { [k: string]: any }) {
let _ = window._;
_.extend(translationJson);

if (moment.locale(_.locale()) !== _.locale()) {
Expand All @@ -64,8 +65,7 @@ export const Language = function () {
function init(routing: ReturnType<typeof Router>) {
router = routing;
/** global: _ */
window._ = new Polyglot({ locale: getLocale(routing.getLang()), allowMissing: true });
let _ = window._;
_ = new Polyglot({ locale: getLocale(routing.getLang()), allowMissing: true });
helper.getJSON("locale/" + _.locale() + ".json?" + config.cacheBreaker).then(setTranslation);
document.querySelector("html").setAttribute("lang", _.locale());
}
Expand Down
5 changes: 1 addition & 4 deletions lib/utils/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { snabbdomBundle as V } from "snabbdom/snabbdom.bundle";
import moment, { Moment } from "moment";
import { _ } from "./language";
import * as helper from "./helper";

export type LinkId = string;
Expand Down Expand Up @@ -90,7 +91,6 @@ function showBar(value: string, width: number, warning: boolean) {
}

self.showStatus = function showStatus(node: Node) {
let _ = window._;
return V.h(
"td",
{ props: { className: node.is_online ? "online" : "offline" } },
Expand All @@ -117,7 +117,6 @@ self.showGeoURI = function showGeoURI(data: Node) {
};

self.showGateway = function showGateway(node: Node) {
let _ = window._;
return node.is_gateway ? _.t("yes") : undefined;
};

Expand Down Expand Up @@ -176,7 +175,6 @@ self.showClients = function showClients(node: Node) {
if (!node.is_online) {
return undefined;
}
let _ = window._;
let localClients = self.countLocalClients(node);

let clients = [
Expand Down Expand Up @@ -228,7 +226,6 @@ self.showIPs = function showIPs(node: Node) {
};

self.showAutoupdate = function showAutoupdate(node: Node) {
let _ = window._;
return node.autoupdater.enabled
? _.t("node.activated", { branch: node.autoupdater.branch })
: _.t("node.deactivated");
Expand Down

0 comments on commit 2489727

Please sign in to comment.