Skip to content

Commit

Permalink
feat(translations): add scope and REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Nov 11, 2024
1 parent 9dc8687 commit 2c0464e
Show file tree
Hide file tree
Showing 39 changed files with 79 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/filters/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/games/duel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/games/gamble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/games/heist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion src/games/roulette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/api/parseTitle.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/checkFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/commons/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { translate } from '../../translate.js';
import { translate } from '../../translations.js';
import { showWithAt } from '../tmi/showWithAt.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/obswebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
38 changes: 1 addition & 37 deletions src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -286,39 +283,6 @@ class Panel extends Core {
cb(null, value);
});

socket.on('responses.get', async function (at: string | null, callback: (responses: Record<string, string>) => 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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/registries/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/services/twitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/services/twitch/calls/updateChannelInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/services/twitch/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/systems/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/systems/cooldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/systems/customcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/systems/emotescombo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/systems/highlights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/systems/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/systems/levels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/systems/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()];

Expand Down
2 changes: 1 addition & 1 deletion src/systems/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/systems/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/systems/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/systems/raffles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/systems/ranks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/systems/scrim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/systems/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/systems/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/systems/top.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/systems/userinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2c0464e

Please sign in to comment.