diff --git a/src/filters/list.ts b/src/filters/list.ts index f9a217acd0b..5809a8af922 100644 --- a/src/filters/list.ts +++ b/src/filters/list.ts @@ -19,7 +19,7 @@ import { format } from '~/helpers/number.js'; import { get } from '~/helpers/permissions/get.js'; import { getCommandPermission } from '~/helpers/permissions/getCommandPermission.js'; import { getPointsName } from '~/helpers/points/index.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; const list: ResponseFilter = { '(list.#)': async function (filter: string) { diff --git a/src/games/duel.ts b/src/games/duel.ts index 37b17576c9d..0d5c47bf2b3 100644 --- a/src/games/duel.ts +++ b/src/games/duel.ts @@ -18,7 +18,7 @@ import { getPointsName } from '~/helpers/points/index.js'; import * as changelog from '~/helpers/user/changelog.js'; import { isBroadcaster } from '~/helpers/user/isBroadcaster.js'; import { isModerator } from '~/helpers/user/isModerator.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; const ERROR_NOT_ENOUGH_OPTIONS = '0'; const ERROR_ZERO_BET = '1'; diff --git a/src/games/gamble.ts b/src/games/gamble.ts index d647c18306b..8d3d04ce707 100644 --- a/src/games/gamble.ts +++ b/src/games/gamble.ts @@ -15,7 +15,7 @@ import { format } from '~/helpers/number.js'; import { getUserHighestPermission } from '~/helpers/permissions/getUserHighestPermission.js'; import { getPointsName } from '~/helpers/points/index.js'; import * as changelog from '~/helpers/user/changelog.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; const ERROR_NOT_ENOUGH_OPTIONS = '0'; const ERROR_ZERO_BET = '1'; diff --git a/src/games/heist.ts b/src/games/heist.ts index 2a6bd5c8dea..4b0f807254d 100644 --- a/src/games/heist.ts +++ b/src/games/heist.ts @@ -12,7 +12,7 @@ import { announce, prepare } from '~/helpers/commons/index.js'; import { getLocalizedName } from '~/helpers/getLocalizedName.js'; import { debug, warning } from '~/helpers/log.js'; import * as changelog from '~/helpers/user/changelog.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; export type Level = { name: string; winPercentage: number; payoutMultiplier: number; maxUsers: number }; export type Result = { percentage: number; message: string }; diff --git a/src/games/roulette.ts b/src/games/roulette.ts index 4692127b598..a455fa96e4e 100644 --- a/src/games/roulette.ts +++ b/src/games/roulette.ts @@ -7,7 +7,7 @@ import { tmiEmitter } from '~/helpers/tmi/index.js'; import * as changelog from '~/helpers/user/changelog.js'; import { isBroadcaster } from '~/helpers/user/isBroadcaster.js'; import { isModerator } from '~/helpers/user/isModerator.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !roulette - 50/50 chance to timeout yourself diff --git a/src/general.ts b/src/general.ts index e01e3f0402d..e42a6263bdb 100644 --- a/src/general.ts +++ b/src/general.ts @@ -31,7 +31,7 @@ import { socketsConnected } from '~/helpers/panel/index.js'; import defaultPermissions from '~/helpers/permissions/defaultPermissions.js'; import { list } from '~/helpers/register.js'; import { getMuteStatus } from '~/helpers/tmi/muteStatus.js'; -import translateLib, { translate } from '~/translate.js'; +import translateLib, { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; let threadStartTimestamp = Date.now(); diff --git a/src/helpers/api/parseTitle.ts b/src/helpers/api/parseTitle.ts index 2d0dfcc27cb..47a37d23adf 100644 --- a/src/helpers/api/parseTitle.ts +++ b/src/helpers/api/parseTitle.ts @@ -1,7 +1,7 @@ import { isNil } from 'lodash-es'; import { rawStatus } from './cache.js'; -import { translate } from '../../translate.js'; +import { translate } from '../../translations.js'; import { getValueOf, isVariableSet } from '../customvariables/index.js'; async function parseTitle (title: string | null) { diff --git a/src/helpers/checkFilter.ts b/src/helpers/checkFilter.ts index 2c44fcdb5d2..d6e5fa07bbf 100644 --- a/src/helpers/checkFilter.ts +++ b/src/helpers/checkFilter.ts @@ -22,7 +22,7 @@ import lastfm from '../integrations/lastfm.js'; import spotify from '../integrations/spotify.js'; import ranks from '../systems/ranks.js'; import songs from '../systems/songs.js'; -import { translate } from '../translate.js'; +import { translate } from '../translations.js'; import { CacheGames } from '~/database/entity/cacheGames.js'; import { AppDataSource } from '~/database.js'; diff --git a/src/helpers/commons/prepare.ts b/src/helpers/commons/prepare.ts index 020fab48607..d54deab1db6 100644 --- a/src/helpers/commons/prepare.ts +++ b/src/helpers/commons/prepare.ts @@ -1,4 +1,4 @@ -import { translate } from '../../translate.js'; +import { translate } from '../../translations.js'; import { showWithAt } from '../tmi/showWithAt.js'; /** diff --git a/src/integrations/obswebsocket.ts b/src/integrations/obswebsocket.ts index 409b91b1bf2..4f29813835f 100644 --- a/src/integrations/obswebsocket.ts +++ b/src/integrations/obswebsocket.ts @@ -22,7 +22,7 @@ import { app, ioServer } from '~/helpers/panel.js'; import { ParameterError } from '~/helpers/parameterError.js'; import { defaultPermissions } from '~/helpers/permissions/defaultPermissions.js'; import { Types } from '~/plugins/ListenTo.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; class OBSWebsocket extends Integration { @onStartup() diff --git a/src/main.ts b/src/main.ts index 9979ec68370..fb910279b28 100644 --- a/src/main.ts +++ b/src/main.ts @@ -70,7 +70,7 @@ async function main () { try { // Initialize all core singletons setTimeout(async () => { - const translate = (await import('./translate.js')).default; + const translate = (await import('./translations.js')).default; translate._load().then(async () => { await import('./general.js'); diff --git a/src/message.ts b/src/message.ts index 0935c51f492..acb8fb84a39 100644 --- a/src/message.ts +++ b/src/message.ts @@ -14,7 +14,7 @@ import { getGlobalVariables } from '~/helpers/checkFilter.js'; import { getUserSender } from '~/helpers/commons/index.js'; import { app } from '~/helpers/panel.js'; import twitch from '~/services/twitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import { withScope } from './helpers/socket.js'; (function initializeMessageParserAPI() { diff --git a/src/panel.ts b/src/panel.ts index a52796e76ab..bd4785aa9e5 100644 --- a/src/panel.ts +++ b/src/panel.ts @@ -18,7 +18,6 @@ import { possibleLists } from '../d.ts/src/helpers/socket.js'; import Core from '~/_interface.js'; import { CacheGames, CacheGamesInterface } from '~/database/entity/cacheGames.js'; import { CacheTitles } from '~/database/entity/cacheTitles.js'; -import { Translation } from '~/database/entity/translation.js'; import { User } from '~/database/entity/user.js'; import { AppDataSource } from '~/database.js'; import { onStartup } from '~/decorators/on.js'; @@ -27,9 +26,7 @@ import { getURL, getValueOf, isVariableSet, postURL, } from '~/helpers/customvariables/index.js'; import { getIsBotStarted } from '~/helpers/database.js'; -import { flatten } from '~/helpers/flatten.js'; import { setValue } from '~/helpers/general/index.js'; -import { getLang } from '~/helpers/locales.js'; import { info, } from '~/helpers/log.js'; @@ -47,7 +44,7 @@ import { sendGameFromTwitch } from '~/services/twitch/calls/sendGameFromTwitch.j import { updateChannelInfo } from '~/services/twitch/calls/updateChannelInfo.js'; import { processAuth, default as socketSystem } from '~/socket.js'; import highlights from '~/systems/highlights.js'; -import translateLib, { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; // __dirname is not available in ES6 module @@ -286,39 +283,6 @@ class Panel extends Core { cb(null, value); }); - socket.on('responses.get', async function (at: string | null, callback: (responses: Record) => void) { - const responses = flatten(!_.isNil(at) ? translateLib.translations[getLang()][at] : translateLib.translations[getLang()]); - _.each(responses, function (value, key) { - const _at = !_.isNil(at) ? at + '.' + key : key; - responses[key] = {}; // remap to obj - responses[key].default = translate(_at, true); - responses[key].current = translate(_at); - }); - callback(responses); - }); - socket.on('responses.set', function (data: { key: string }) { - _.remove(translateLib.custom, function (o: any) { - return o.key === data.key; - }); - translateLib.custom.push(data); - translateLib._save(); - - const lang = {}; - _.merge( - lang, - translate({ root: 'webpanel' }), - translate({ root: 'ui' }), // add ui root -> slowly refactoring to new name - ); - socket.emit('lang', lang); - }); - socket.on('responses.revert', async function (data: { name: string }, callback: (translation: string) => void) { - _.remove(translateLib.custom, function (o: any) { - return o.name === data.name; - }); - await AppDataSource.getRepository(Translation).delete({ name: data.name }); - callback(translate(data.name)); - }); - socket.on('connection_status', (cb: (status: typeof statusObj) => void) => { cb(statusObj); }); diff --git a/src/parser.ts b/src/parser.ts index 396bc3bcdb0..94e14790fea 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -17,7 +17,7 @@ import { import { parserEmitter } from '~/helpers/parser/emitter.js'; import { check } from '~/helpers/permissions/check.js'; import { getCommandPermission } from '~/helpers/permissions/getCommandPermission.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; parserEmitter.on('process', async (opts, cb) => { cb(await (new Parser(opts)).process()); diff --git a/src/registries/alerts.ts b/src/registries/alerts.ts index f1f7a30daab..4c5231525ef 100644 --- a/src/registries/alerts.ts +++ b/src/registries/alerts.ts @@ -25,7 +25,7 @@ import { ioServer } from '~/helpers/panel.js'; import { defaultPermissions } from '~/helpers/permissions/defaultPermissions.js'; import { itemsToEvalPart } from '~/helpers/queryFilter.js'; import { Types } from '~/plugins/ListenTo.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; const filterMutex = new Mutex(); diff --git a/src/services/twitch.ts b/src/services/twitch.ts index 73cffca0eb2..435531df4bf 100644 --- a/src/services/twitch.ts +++ b/src/services/twitch.ts @@ -39,7 +39,7 @@ import getNameById from '~/helpers/user/getNameById.js'; import { isIgnored } from '~/helpers/user/isIgnored.js'; import { sendGameFromTwitch } from '~/services/twitch/calls/sendGameFromTwitch.js'; import { updateChannelInfo } from '~/services/twitch/calls/updateChannelInfo.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; const urls = { diff --git a/src/services/twitch/calls/updateChannelInfo.ts b/src/services/twitch/calls/updateChannelInfo.ts index 50951727d3b..55462107c08 100644 --- a/src/services/twitch/calls/updateChannelInfo.ts +++ b/src/services/twitch/calls/updateChannelInfo.ts @@ -16,7 +16,7 @@ import { getFunctionName } from '~/helpers/getFunctionName.js'; import { debug, warning } from '~/helpers/log.js'; import { setImmediateAwait } from '~/helpers/setImmediateAwait.js'; import twitch from '~/services/twitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; async function updateChannelInfo (args: { title?: string | null; game?: string | null, tags?: string[], contentClassificationLabels?: string[] }): Promise<{ response: string; status: boolean } | null> { diff --git a/src/services/twitch/chat.ts b/src/services/twitch/chat.ts index 9044e01dcc9..f1b462db15f 100644 --- a/src/services/twitch/chat.ts +++ b/src/services/twitch/chat.ts @@ -46,7 +46,7 @@ import { getBadgeImagesFromBadgeSet } from '~/overlays/chat.js'; import eventlist from '~/overlays/eventlist.js'; import { Parser } from '~/parser.js'; import alerts from '~/registries/alerts.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import users from '~/users.js'; import { variables } from '~/watchers.js'; diff --git a/src/stats.ts b/src/stats.ts index 40fd0175cf2..5b9a2451395 100644 --- a/src/stats.ts +++ b/src/stats.ts @@ -21,7 +21,7 @@ import { linesParsed } from '~/helpers/parser.js'; import lastfm from '~/integrations/lastfm.js'; import spotify from '~/integrations/spotify.js'; import songs from '~/systems/songs.js'; -import translateLib, { translate } from '~/translate.js'; +import translateLib, { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; import { withScope } from './helpers/socket.js'; diff --git a/src/systems/alias.ts b/src/systems/alias.ts index ca0c3da296a..a905db91700 100644 --- a/src/systems/alias.ts +++ b/src/systems/alias.ts @@ -25,7 +25,7 @@ import { get } from '~/helpers/permissions/get.js'; import { Types } from '~/plugins/ListenTo.js'; import plugins from '~/plugins.js'; import customCommands from '~/systems/customcommands.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !alias - gets an info about alias usage diff --git a/src/systems/cooldown.ts b/src/systems/cooldown.ts index 42fe7ede8f6..c74fcffbda6 100644 --- a/src/systems/cooldown.ts +++ b/src/systems/cooldown.ts @@ -26,7 +26,7 @@ import * as changelog from '~/helpers/user/changelog.js'; import { isOwner } from '~/helpers/user/index.js'; import alias from '~/systems/alias.js'; import customCommands from '~/systems/customcommands.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; const cache: { id: string; cooldowns: CooldownEntity[] }[] = []; const defaultCooldowns: { name: string; lastRunAt: number, permId: string }[] = []; diff --git a/src/systems/customcommands.ts b/src/systems/customcommands.ts index 00485d6bf89..514f817f401 100644 --- a/src/systems/customcommands.ts +++ b/src/systems/customcommands.ts @@ -25,7 +25,7 @@ import { info, warning } from '~/helpers/log.js'; import { check } from '~/helpers/permissions/check.js'; import { defaultPermissions } from '~/helpers/permissions/defaultPermissions.js'; import { get } from '~/helpers/permissions/get.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !command - gets an info about command usage diff --git a/src/systems/emotescombo.ts b/src/systems/emotescombo.ts index 42412896887..dcb541ff76c 100644 --- a/src/systems/emotescombo.ts +++ b/src/systems/emotescombo.ts @@ -6,7 +6,7 @@ import { onStreamStart } from '~/decorators/on.js'; import { prepare } from '~/helpers/commons/index.js'; import { LOW, SECOND } from '~/helpers/constants.js'; import { ioServer } from '~/helpers/panel.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; class EmotesCombo extends System { @settings() diff --git a/src/systems/highlights.ts b/src/systems/highlights.ts index 4ec208e5fd5..2fa511bf59b 100644 --- a/src/systems/highlights.ts +++ b/src/systems/highlights.ts @@ -22,7 +22,7 @@ import getBotUserName from '~/helpers/user/getBotUserName.js'; import getBroadcasterId from '~/helpers/user/getBroadcasterId.js'; import { createMarker } from '~/services/twitch/calls/createMarker.js'; import twitch from '~/services/twitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; const ERROR_STREAM_NOT_ONLINE = '1'; const ERROR_MISSING_TOKEN = '2'; diff --git a/src/systems/keywords.ts b/src/systems/keywords.ts index 4d0e5919395..44c795cec4b 100644 --- a/src/systems/keywords.ts +++ b/src/systems/keywords.ts @@ -22,7 +22,7 @@ import { import { check } from '~/helpers/permissions/check.js'; import { defaultPermissions } from '~/helpers/permissions/defaultPermissions.js'; import { get } from '~/helpers/permissions/get.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; class Keywords extends System { constructor() { diff --git a/src/systems/levels.ts b/src/systems/levels.ts index 8c7d1f39bfe..6f9be12f2c4 100644 --- a/src/systems/levels.ts +++ b/src/systems/levels.ts @@ -28,7 +28,7 @@ import { } from '~/helpers/type.js'; import * as changelog from '~/helpers/user/changelog.js'; import { isBotId } from '~/helpers/user/isBot.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; let cachedLevelsHash = ''; const cachedLevels: bigint[] = []; diff --git a/src/systems/moderation.ts b/src/systems/moderation.ts index 46c300d09d3..513081c21cd 100644 --- a/src/systems/moderation.ts +++ b/src/systems/moderation.ts @@ -34,7 +34,7 @@ import banUser from '~/services/twitch/calls/banUser.js'; import getUserByName from '~/services/twitch/calls/getUserByName.js'; import aliasSystem from '~/systems/alias.js'; import songs from '~/systems/songs.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; const tlds = [...TLDs.tlds.keys()]; diff --git a/src/systems/points.ts b/src/systems/points.ts index c893301b144..12da46adf1e 100644 --- a/src/systems/points.ts +++ b/src/systems/points.ts @@ -33,7 +33,7 @@ import { getPointsName, name } from '~/helpers/points/index.js'; import * as changelog from '~/helpers/user/changelog.js'; import { isBot, isBotId } from '~/helpers/user/isBot.js'; import { getIdFromTwitch } from '~/services/twitch/calls/getIdFromTwitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; class Points extends System { diff --git a/src/systems/price.ts b/src/systems/price.ts index fe0fbf8639e..a2a7a281837 100644 --- a/src/systems/price.ts +++ b/src/systems/price.ts @@ -19,7 +19,7 @@ import defaultPermissions from '~/helpers/permissions/defaultPermissions.js'; import { getPointsName } from '~/helpers/points/index.js'; import * as changelog from '~/helpers/user/changelog.js'; import { isBroadcaster, isOwner } from '~/helpers/user/index.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !price - gets an info about price usage diff --git a/src/systems/queue.ts b/src/systems/queue.ts index 7d20dada659..978f43e4c22 100644 --- a/src/systems/queue.ts +++ b/src/systems/queue.ts @@ -15,7 +15,7 @@ import * as changelog from '~/helpers/user/changelog.js'; import getBotId from '~/helpers/user/getBotId.js'; import getBotUserName from '~/helpers/user/getBotUserName.js'; import twitch from '~/services/twitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !queue - gets an info whether queue is opened or closed diff --git a/src/systems/raffles.ts b/src/systems/raffles.ts index 99aa5b69751..95a82c1c225 100644 --- a/src/systems/raffles.ts +++ b/src/systems/raffles.ts @@ -26,7 +26,7 @@ import defaultPermissions from '~/helpers/permissions/defaultPermissions.js'; import { tmiEmitter } from '~/helpers/tmi/index.js'; import * as changelog from '~/helpers/user/changelog.js'; import points from '~/systems/points.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; const TYPE_NORMAL = 0; const TYPE_TICKETS = 1; diff --git a/src/systems/ranks.ts b/src/systems/ranks.ts index 6d7e79f23e9..6c1a2bef69e 100644 --- a/src/systems/ranks.ts +++ b/src/systems/ranks.ts @@ -12,7 +12,7 @@ import { prepare } from '~/helpers/commons/index.js'; import { getLocalizedName } from '~/helpers/getLocalizedName.js'; import defaultPermissions from '~/helpers/permissions/defaultPermissions.js'; import * as changelog from '~/helpers/user/changelog.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !rank - show user rank diff --git a/src/systems/scrim.ts b/src/systems/scrim.ts index a8182afa816..f94b8999975 100644 --- a/src/systems/scrim.ts +++ b/src/systems/scrim.ts @@ -19,7 +19,7 @@ import defaultPermissions from '~/helpers/permissions/defaultPermissions.js'; import getBotId from '~/helpers/user/getBotId.js'; import getBotUserName from '~/helpers/user/getBotUserName.js'; import twitch from '~/services/twitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; enum ERROR { ALREADY_OPENED, diff --git a/src/systems/songs.ts b/src/systems/songs.ts index 7c5e82fa2bd..4696f5e366c 100644 --- a/src/systems/songs.ts +++ b/src/systems/songs.ts @@ -33,7 +33,7 @@ import * as changelog from '~/helpers/user/changelog.js'; import getBotId from '~/helpers/user/getBotId.js'; import getBotUserName from '~/helpers/user/getBotUserName.js'; import { isModerator } from '~/helpers/user/isModerator.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; let importInProgress = false; const cachedTags = new Set(); diff --git a/src/systems/timers.ts b/src/systems/timers.ts index 89f837968b5..cd73b6c2962 100644 --- a/src/systems/timers.ts +++ b/src/systems/timers.ts @@ -17,7 +17,7 @@ import { announce } from '~/helpers/commons/index.js'; import { isDbConnected } from '~/helpers/database.js'; import { linesParsed } from '~/helpers/parser.js'; import defaultPermissions from '~/helpers/permissions/defaultPermissions.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !timers - gets an info about timers usage diff --git a/src/systems/top.ts b/src/systems/top.ts index d66d7d8d0ca..c1abfcbd645 100644 --- a/src/systems/top.ts +++ b/src/systems/top.ts @@ -19,7 +19,7 @@ import { unserialize } from '~/helpers/type.js'; import * as changelog from '~/helpers/user/changelog.js'; import { getIgnoreList, isIgnored } from '~/helpers/user/isIgnored.js'; import twitch from '~/services/twitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; import { variables } from '~/watchers.js'; enum TYPE { diff --git a/src/systems/userinfo.ts b/src/systems/userinfo.ts index 814e604225a..bedb3a2ea75 100644 --- a/src/systems/userinfo.ts +++ b/src/systems/userinfo.ts @@ -28,7 +28,7 @@ import { getUserHighestPermission } from '~/helpers/permissions/getUserHighestPe import { getPointsName } from '~/helpers/points/index.js'; import * as changelog from '~/helpers/user/changelog.js'; import twitch from '~/services/twitch.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; /* * !me diff --git a/src/translate.ts b/src/translations.ts similarity index 79% rename from src/translate.ts rename to src/translations.ts index 5a5cfbe2c9d..ea877a685a6 100644 --- a/src/translate.ts +++ b/src/translations.ts @@ -4,8 +4,11 @@ import { normalize } from 'path'; import { glob } from 'glob'; import { set, isNil, remove, isUndefined, cloneDeep, each, get } from 'lodash-es'; +import { Delete, Get, Post } from './decorators/endpoint.js'; +import { onStartup } from './decorators/on.js'; import { areDecoratorsLoaded } from './decorators.js'; +import Core from '~/_interface.js'; import { Settings } from '~/database/entity/settings.js'; import { Translation } from '~/database/entity/translation.js'; import { AppDataSource } from '~/database.js'; @@ -14,17 +17,51 @@ import { getLang, setLang } from '~/helpers/locales.js'; import { error, warning } from '~/helpers/log.js'; import { addMenu } from '~/helpers/panel.js'; -class Translate { +class Translations extends Core { custom: any[] = []; translations: any = {}; isLoaded = false; - constructor () { + @onStartup() + onStartup () { addMenu({ - category: 'settings', name: 'translations', id: 'settings/translations', this: null, + category: 'settings', name: 'translations', id: 'settings/translations', this: null, scopeParent: this.scope(), }); } + @Get('/') + async getTranslations () { + const responses = flatten(this.translations[getLang()]); + for (const key of Object.keys(responses)) { + const value = { + default: this.translate(key, true), + current: this.translate(key), + }; + responses[key] = value; + } + return responses; + } + + @Post('/:key') + async setTranslations(req: any) { + const key = req.params.key; + const data = req.body; + + remove(this.custom, function (o: any) { + return o.key === key; + }); + this.custom.push(data); + await this._save(); + } + + @Delete('/:key') + async revertTranslations(req: any) { + remove(this.custom, function (o: any) { + return o.name === req.params.key; + }); + await AppDataSource.getRepository(Translation).delete({ name: req.params.key }); + } + async check(lang: string): Promise { return typeof this.translations[lang] !== 'undefined'; } @@ -128,7 +165,7 @@ class Translate { } } -const translate_class = new Translate(); +const translate_class = new Translations(); const translate = translate_class.translate; export default translate_class; export { translate }; diff --git a/src/widgets/eventlist.ts b/src/widgets/eventlist.ts index e806410785c..96730e72be9 100644 --- a/src/widgets/eventlist.ts +++ b/src/widgets/eventlist.ts @@ -13,7 +13,7 @@ import { SECOND } from '~/helpers/constants.js'; import { getLocalizedName } from '~/helpers/getLocalizedName.js'; import { error } from '~/helpers/log.js'; import getNameById from '~/helpers/user/getNameById.js'; -import { translate } from '~/translate.js'; +import { translate } from '~/translations.js'; class EventList extends Widget { @Get('/')