ctucx.git: trainsearch

web based trip-planner, fork of https://cyberchaos.dev/yuka/trainsearch

commit fae27599d7eb28edcd4f74a1b31236dc50346710
parent d2ee8742991a99d3bbaf307f0c8ed28e4367528b
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 30 Jan 2025 12:09:21 +0100

app_functions: move `t` function to `languages.js`
9 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/src/app_functions.js b/src/app_functions.js
@@ -195,17 +195,6 @@ export const newJourneys = async (params) => {
 	return data;
 };
 
-export const t = (key, ...params) => {
-	let translation = languages[settings.language][key];
-	if (!translation) translation = languages['en'][key]
-	if (!translation) return key;
-
-	while (params.length >= 1)
-		translation = translation.replace('{}', params.shift());
-
-	return translation;
-};
-
 export const ds100Names = (id) => {
 	if (!settings.showDS100) return '';
 	if (!ds100[Number(id)])  return '';
diff --git a/src/departuresView.js b/src/departuresView.js
@@ -2,11 +2,12 @@ import { html, nothing, render } from 'lit-html';
 import { settings } from './settings.js';
 import { platformTemplate, timeTemplate } from './templates.js';
 import { ElementById, setThemeColor, queryBackgroundColor } from './helpers.js';
-import { t, processLeg } from './app_functions.js';
+import { processLeg } from './app_functions.js';
 import { formatDateTime, formatDuration, formatPrice } from './formatters.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
 import { getHafasClient, client } from './hafas_client.js';
+import { t } from './languages.js';
 
 const departuresTemplate = (data, profile) => {
 	let changes = 0;
diff --git a/src/journeyView.js b/src/journeyView.js
@@ -3,10 +3,11 @@ import { cachedCoachSequence } from './coach-sequence/index.js';
 import { settings } from './settings.js';
 import { remarksModalTemplate, platformTemplate, stopTemplate, timeTemplate } from './templates.js';
 import { ElementById, setThemeColor, queryBackgroundColor } from './helpers.js';
-import { t, getJourney, refreshJourney } from './app_functions.js';
+import { getJourney, refreshJourney } from './app_functions.js';
 import { formatName, formatDateTime, formatDuration, formatPrice, formatTrainTypes, formatLineAdditionalName, formatLineDisplayName } from './formatters.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
+import { t } from './languages.js';
 
 const legTemplate = (leg, profile) => {
 	const remarks        = leg.remarks || [];
diff --git a/src/journeysView.js b/src/journeysView.js
@@ -1,12 +1,13 @@
 import { html, nothing, render } from 'lit-html';
 import { ElementById, setThemeColor, queryBackgroundColor, getFrom, getTo, padZeros } from './helpers.js';
-import { t, getJourneys, getMoreJourneys, refreshJourneys } from './app_functions.js';
+import { getJourneys, getMoreJourneys, refreshJourneys } from './app_functions.js';
 import { formatName, formatDuration, formatFromTo, formatPrice } from './formatters.js';
 import { timeTemplate } from './templates.js';
 import { settings, modifySettings } from './settings.js';
 import { setupCanvas } from './canvas.js';
 import { go } from './router.js';
 import { showAlertModal, showLoader, hideOverlay } from './overlays.js';
+import { t } from './languages.js';
 
 const journeysTemplate = (data) => html`
 	<div class="journeysView column">
diff --git a/src/languages.js b/src/languages.js
@@ -1,4 +1,17 @@
-export const languages = {
+import { settings } from './settings.js';
+
+export const t = (key, ...params) => {
+	let translation = languages[settings.language][key];
+	if (!translation) translation = languages['en'][key]
+	if (!translation) return key;
+
+	while (params.length >= 1)
+		translation = translation.replace('{}', params.shift());
+
+	return translation;
+};
+
+const languages = {
 	'de': {
 		'access_full':        'Barrierefrei',
 		'access_none':        'Keine Einschränkungen',
diff --git a/src/searchView.js b/src/searchView.js
@@ -1,11 +1,12 @@
 import { html, nothing, render } from 'lit-html';
 import { ElementById, hideElement, showElement, elementHidden, flipElement, unflipElement, setThemeColor, queryBackgroundColor, padZeros, isValidDate, loyaltyCardFromString } from './helpers.js';
 import { db } from './dataStorage.js';
-import { t, getJourneys, newJourneys, ds100Reverse } from './app_functions.js';
+import { getJourneys, newJourneys, ds100Reverse } from './app_functions.js';
 import { formatName, formatFromTo } from './formatters.js';
 import { modifySettings, settings } from './settings.js';
 import { go } from './router.js';
 import { showAlertModal, showSelectModal, showLoader, hideOverlay} from './overlays.js';
+import { t } from './languages.js';
 import { showSettings } from './settingsView.js';
 import { client } from './hafas_client.js';
 

@@ -358,6 +359,8 @@ const submitForm = async (event) => {
 
 	hideOverlay();
 
+	console.log(responseData)
+
 	go(`/${responseData.slug}/${settings.journeysViewMode}`);
 };
 
diff --git a/src/settingsView.js b/src/settingsView.js
@@ -3,7 +3,7 @@ import { db, clearDataStorage } from './dataStorage.js';
 import { modifySettings, settings } from './settings.js';
 import { showModal, hideOverlay } from './overlays.js';
 import { ElementById, hideElement, showElement } from './helpers.js';
-import { t } from './app_functions.js';
+import { t } from './languages.js';
 import { searchView } from './searchView.js';
 import { initHafasClient } from './hafas_client.js';
 
diff --git a/src/templates.js b/src/templates.js
@@ -3,7 +3,8 @@ import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
 import { formatDateTime, lineAdditionalName } from './formatters.js';
 import { showModal } from './overlays.js';
 import { settings } from './settings.js';
-import { t, ds100Names } from './app_functions.js';
+import { ds100Names } from './app_functions.js';
+import { t } from './languages.js';
 
 export const remarksModalTemplate = (remarks) => html`
 	<div class="remarksView">
diff --git a/src/tripView.js b/src/tripView.js
@@ -2,11 +2,12 @@ import { html, nothing, render } from 'lit-html';
 import { settings } from './settings.js';
 import { remarksModalTemplate, platformTemplate, stopTemplate, timeTemplate } from './templates.js';
 import { ElementById, showElement, setThemeColor, queryBackgroundColor } from './helpers.js';
-import { t, processLeg } from './app_functions.js';
+import { processLeg } from './app_functions.js';
 import { formatDateTime, formatDuration, formatPrice, formatLineAdditionalName, formatLineDisplayName } from './formatters.js';
 import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js';
 import { go } from './router.js';
 import { getHafasClient, client } from './hafas_client.js';
+import { t } from './languages.js';
 
 const tripTemplate = (data, profile) => {
 	let changes = 0;