Skip to content

Commit

Permalink
feat: Translate error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Sep 7, 2023
1 parent fcaade5 commit 2e45f0c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
11 changes: 11 additions & 0 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"yes": "Ja",
"no": "Nein",

"%errors": "",
"error_api_not_found": "Die Star Citizen Wiki API ist unter der angegebenen URL nicht erreichbar.",
"error_api_no_connection": "Die Star Citizen Wiki API ist derzeit nicht erreichbar",
"error_no_data": "Ich konnte keine Daten zu der Eingabe finden.",
"error_too_many_requests": "Zu viele Anfragen gesendet. Bitte warten.",
"error_command_failure": "Der Befehl konnte nicht ausgeführt werden.",

"%comm-link": "",
"newest_comm_link": "Der neueste Comm-Link",
"newest_comm_links": "Die neuesten Comm-Links",

"%galactapedia": "",
"related_articles": "Verwandte Artikel",

Expand Down
11 changes: 11 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"yes": "Yes",
"no": "No",

"%errors": "",
"error_api_not_found": "The Star Citizen Wiki API is not reachable at the specified URL.",
"error_api_no_connection": "The Star Citizen Wiki API is currently unreachable",
"error_no_data": "I could not find any data related to the input.",
"error_too_many_requests": "Too many requests sent. Please wait.",
"error_command_failure": "The command could not be executed.",

"%comm-link": "",
"newest_comm_link": "The current Comm-Link",
"newest_comm_links": "The current Comm-Links",

"%galactapedia": "",
"related_articles": "Related articles",

Expand Down
11 changes: 11 additions & 0 deletions i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"yes": "Oui",
"no": "Non",

"%errors": "",
"error_api_not_found" : "L'API Star Citizen Wiki n'est pas accessible à l'URL indiquée",
"error_api_no_connection" : "L'API Star Citizen Wiki est actuellement inaccessible",
"error_no_data" : "Je n'ai trouvé aucune donnée concernant l'entrée",
"error_too_many_requests" : "Trop de demandes envoyées. Veuillez patienter",
"error_command_failure" : "La commande n'a pas pu être exécutée",

"%comm-link": "",
"newest_comm_link": "Le Comm-Link actuel",
"newest_comm_links": "Les Comm-Links actuels",

"%galactapedia": "",
"related_articles": "Articles connexes",

Expand Down
11 changes: 6 additions & 5 deletions src/events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Events } = require('discord.js');
const log = require('../lib/console-logger');
const { translate } = require('../lib/translate');

module.exports = {
name: Events.InteractionCreate,
Expand All @@ -15,14 +16,14 @@ module.exports = {
if (error.code === 'ENOTFOUND') {
log('Could not connect to API', error.message, 'error');

return interaction.editReply({ content: 'Die Star Citizen Wiki API ist unter der angegebenen URL nicht erreichbar.' });
return interaction.editReply({ content: translate(interaction, 'error_api_not_found') });
}

if (typeof error.response !== 'undefined' && typeof error.response.status !== 'undefined') {
if (error.response.status === 504 || error.response.status === 500) {
log('Could not connect to API', error, 'error');

return interaction.editReply({ content: 'Die Star Citizen Wiki API ist derzeit nicht erreichbar' });
return interaction.editReply({ content: translate(interaction, 'error_api_no_connection') });
}

if (error.response.status === 404) {
Expand All @@ -35,18 +36,18 @@ module.exports = {
console.error(error);
}

return interaction.editReply({ content: 'Ich konnte keine Daten zu der Eingabe finden.' });
return interaction.editReply({ content: translate(interaction, 'error_no_data') });
}

if (error.response.status === 429) {
log('API calls are rate-limited', {}, 'warn');

return interaction.editReply({ content: 'Zu viele Anfragen gesendet. Bitte warten.' });
return interaction.editReply({ content: translate(interaction, 'error_too_many_requests') });
}
}

console.error(error);
interaction.reply({ content: 'Der Befehl konnte nicht ausgeführt werden.' })
interaction.reply({ content: translate(interaction, 'error_command_failure') })
.catch(() => {
log('Could not send message');
});
Expand Down
6 changes: 4 additions & 2 deletions src/lib/embed/comm-links-embed.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const { EmbedBuilder } = require('discord.js');
const { footer, wiki_url } = require('../../../config.json');
const { getLocale } = require('../translate');
const { getLocale, translate } = require('../translate');

/**
* @param {Object} data
* @param {ChatInputCommandInteraction} interaction
* @return {EmbedBuilder}
*/
const createEmbed = (data, interaction) => {
const title = data.length === 1 ? 'Der neueste Comm-Link' : 'Die neuesten Comm-Links';
const title = data.length === 1
? translate(interaction, 'newest_comm_link')
: translate(interaction, 'newest_comm_links');
const url = data.length === 1 ? `${wiki_url}/Comm-Link:${data[0].id}` : `${wiki_url}/Comm-Link:Übersicht`;

const reply = new EmbedBuilder({
Expand Down

0 comments on commit 2e45f0c

Please sign in to comment.