Browse Source

Make status and issue link types translatable

Merge pull request #148 from NeunEinser/patch-1
MarkusRost 4 years ago
parent
commit
ded52adfa5
2 changed files with 66 additions and 23 deletions
  1. 25 21
      cmds/minecraft/bug.js
  2. 41 2
      i18n/en.json

+ 25 - 21
cmds/minecraft/bug.js

@@ -18,7 +18,7 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 	args = args.slice(1);
 	args = args.slice(1);
 	if ( invoke && /\d+$/.test(invoke) && !args.length ) {
 	if ( invoke && /\d+$/.test(invoke) && !args.length ) {
 		if ( /^\d+$/.test(invoke) ) invoke = 'MC-' + invoke;
 		if ( /^\d+$/.test(invoke) ) invoke = 'MC-' + invoke;
-		var link = 'https://bugs.mojang.com/browse/';
+		var baseBrowseUrl = 'https://bugs.mojang.com/browse/';
 		got.get( 'https://bugs.mojang.com/rest/api/2/issue/' + encodeURIComponent( invoke ) + '?fields=summary,issuelinks,fixVersions,resolution,status' ).then( response => {
 		got.get( 'https://bugs.mojang.com/rest/api/2/issue/' + encodeURIComponent( invoke ) + '?fields=summary,issuelinks,fixVersions,resolution,status' ).then( response => {
 			var body = response.body;
 			var body = response.body;
 			if ( response.statusCode !== 200 || !body || body['status-code'] === 404 || body.errorMessages || body.errors ) {
 			if ( response.statusCode !== 200 || !body || body['status-code'] === 404 || body.errorMessages || body.errors ) {
@@ -27,7 +27,7 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 						msg.reactEmoji('🤷');
 						msg.reactEmoji('🤷');
 					}
 					}
 					else if ( body.errorMessages.includes( 'You do not have the permission to see the specified issue.' ) ) {
 					else if ( body.errorMessages.includes( 'You do not have the permission to see the specified issue.' ) ) {
-						msg.sendChannel( spoiler + lang.get('minecraft.private') + '\n<' + link + invoke + '>' + spoiler );
+						msg.sendChannel( spoiler + lang.get('minecraft.private') + '\n<' + baseBrowseUrl + invoke + '>' + spoiler );
 					}
 					}
 					else {
 					else {
 						console.log( '- ' + ( response && response.statusCode ) + ': Error while getting the issue: ' + body.errorMessages.join(' - ') );
 						console.log( '- ' + ( response && response.statusCode ) + ': Error while getting the issue: ' + body.errorMessages.join(' - ') );
@@ -37,7 +37,7 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 				else {
 				else {
 					console.log( '- ' + response.statusCode + ': Error while getting the issue: ' + ( body && body.message ) );
 					console.log( '- ' + response.statusCode + ': Error while getting the issue: ' + ( body && body.message ) );
 					if ( body && body['status-code'] === 404 ) msg.reactEmoji('error');
 					if ( body && body['status-code'] === 404 ) msg.reactEmoji('error');
-					else msg.sendChannelError( spoiler + '<' + link + invoke + '>' + spoiler );
+					else msg.sendChannelError( spoiler + '<' + baseBrowseUrl + invoke + '>' + spoiler );
 				}
 				}
 			}
 			}
 			else {
 			else {
@@ -45,31 +45,34 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 					msg.reactEmoji('error');
 					msg.reactEmoji('error');
 				}
 				}
 				else {
 				else {
-					var bugs = body.fields.issuelinks.filter( bug => bug.outwardIssue || ( bug.inwardIssue && bug.type.name != 'Duplicate' ) );
-					if ( bugs.length ) {
+					var statusList = lang.get('minecraft.status');
+					var links = body.fields.issuelinks.filter( link => link.outwardIssue || ( link.inwardIssue && link.type.name !== 'Duplicate' ) );
+					if ( links.length ) {
 						var embed = new MessageEmbed();
 						var embed = new MessageEmbed();
-						var extrabugs = [];
-						bugs.forEach( bug => {
-							var ward = ( bug.outwardIssue ? 'outward' : 'inward' );
-							var issue = bug[ward + 'Issue'];
-							var name = bug.type[ward] + ' ' + issue.key;
-							var value = issue.fields.status.name + ': [' + issue.fields.summary.escapeFormatting() + '](' + link + issue.key + ')';
+						var linkList = lang.get('minecraft.issue_link');
+						var extralinks = [];
+						links.forEach( link => {
+							var ward = ( link.outwardIssue ? 'outward' : 'inward' );
+							var issue = link[ward + 'Issue']; // looks for property (in|out)wardIssue
+							var name = ( linkList?.[link.type.name]?.[ward]?.replaceSave( /\$1/g, issue.key ) || link.type[ward] + ' ' + issue.key );
+							var status = issue.fields.status.name;
+							var value = ( statusList?.[status] || status ) + ': [' + issue.fields.summary.escapeFormatting() + '](' + baseBrowseUrl + issue.key + ')';
 							if ( embed.fields.length < 25 ) embed.addField( name, value );
 							if ( embed.fields.length < 25 ) embed.addField( name, value );
-							else extrabugs.push({name,value,inline:false});
+							else extralinks.push({name,value,inline:false});
 						} );
 						} );
-						if ( extrabugs.length ) embed.setFooter( lang.get('minecraft.more', extrabugs.length.toLocaleString(lang.get('dateformat')), extrabugs.length) );
+						if ( extralinks.length ) embed.setFooter( lang.get('minecraft.more', extralinks.length.toLocaleString(lang.get('dateformat')), extralinks.length) );
 					}
 					}
-					var status = '**' + ( body.fields.resolution ? body.fields.resolution.name : body.fields.status.name ) + ':** ';
+					var status = ( body.fields.resolution ? body.fields.resolution.name : body.fields.status.name );
 					var fixed = '';
 					var fixed = '';
 					if ( body.fields.resolution && body.fields.fixVersions && body.fields.fixVersions.length ) {
 					if ( body.fields.resolution && body.fields.fixVersions && body.fields.fixVersions.length ) {
-						fixed = '\n' + lang.get('minecraft.fixed') + ' ' + body.fields.fixVersions.map( v => v.name ).join(', ');
+						fixed = '\n' + lang.get('minecraft.fixed', body.fields.fixVersions.length) + ' ' + body.fields.fixVersions.map( v => v.name ).join(', ');
 					}
 					}
-					msg.sendChannel( spoiler + status + body.fields.summary.escapeFormatting() + '\n<' + link + body.key + '>' + fixed + spoiler, {embed} );
+					msg.sendChannel( spoiler + '**' + ( statusList?.[status] || status ) + '**: ' + body.fields.summary.escapeFormatting() + '\n<' + baseBrowseUrl + body.key + '>' + fixed + spoiler, {embed} );
 				}
 				}
 			}
 			}
 		}, error => {
 		}, error => {
 			console.log( '- Error while getting the issue: ' + error );
 			console.log( '- Error while getting the issue: ' + error );
-			msg.sendChannelError( spoiler + '<' + link + invoke + '>' + spoiler );
+			msg.sendChannelError( spoiler + '<' + baseBrowseUrl + invoke + '>' + spoiler );
 		} ).finally( () => {
 		} ).finally( () => {
 			if ( reaction ) reaction.removeEmoji();
 			if ( reaction ) reaction.removeEmoji();
 		} );
 		} );
@@ -78,7 +81,7 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 		var jql = new URLSearchParams({
 		var jql = new URLSearchParams({
 			jql: 'fixVersion="' + args.join(' ').replace( /["\\]/g, '\\$&' ) + '" order by key'
 			jql: 'fixVersion="' + args.join(' ').replace( /["\\]/g, '\\$&' ) + '" order by key'
 		});
 		});
-		var link = 'https://bugs.mojang.com/issues/?' + jql;
+		var uri = 'https://bugs.mojang.com/issues/?' + jql;
 		got.get( 'https://bugs.mojang.com/rest/api/2/search?fields=summary,resolution,status&' + jql + '&maxResults=25' ).then( response => {
 		got.get( 'https://bugs.mojang.com/rest/api/2/search?fields=summary,resolution,status&' + jql + '&maxResults=25' ).then( response => {
 			var body = response.body;
 			var body = response.body;
 			if ( response.statusCode !== 200 || !body || body['status-code'] === 404 || body.errorMessages || body.errors ) {
 			if ( response.statusCode !== 200 || !body || body['status-code'] === 404 || body.errorMessages || body.errors ) {
@@ -94,7 +97,7 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 				else {
 				else {
 					console.log( '- ' + response.statusCode + ': Error while getting the issues: ' + ( body && body.message ) );
 					console.log( '- ' + response.statusCode + ': Error while getting the issues: ' + ( body && body.message ) );
 					if ( body && body['status-code'] === 404 ) msg.reactEmoji('error');
 					if ( body && body['status-code'] === 404 ) msg.reactEmoji('error');
-					else msg.sendChannelError( spoiler + '<' + link + '>' + spoiler );
+					else msg.sendChannelError( spoiler + '<' + uri + '>' + spoiler );
 				}
 				}
 			}
 			}
 			else {
 			else {
@@ -104,9 +107,10 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 				else {
 				else {
 					if ( body.total > 0 ) {
 					if ( body.total > 0 ) {
 						var embed = new MessageEmbed();
 						var embed = new MessageEmbed();
+						var statusList = lang.get('minecraft.status');
 						body.issues.forEach( bug => {
 						body.issues.forEach( bug => {
 							var status = ( bug.fields.resolution ? bug.fields.resolution.name : bug.fields.status.name );
 							var status = ( bug.fields.resolution ? bug.fields.resolution.name : bug.fields.status.name );
-							var value = status + ': [' + bug.fields.summary.escapeFormatting() + '](https://bugs.mojang.com/browse/' + bug.key + ')';
+							var value = ( statusList?.[status] || status ) + ': [' + bug.fields.summary.escapeFormatting() + '](https://bugs.mojang.com/browse/' + bug.key + ')';
 							embed.addField( bug.key, value );
 							embed.addField( bug.key, value );
 						} );
 						} );
 						if ( body.total > 25 ) {
 						if ( body.total > 25 ) {
@@ -134,4 +138,4 @@ function minecraft_bug(lang, msg, args, title, cmd, querystring, fragment, react
 module.exports = {
 module.exports = {
 	name: 'bug',
 	name: 'bug',
 	run: minecraft_bug
 	run: minecraft_bug
-};
+};

+ 41 - 2
i18n/en.json

@@ -391,11 +391,50 @@
     },
     },
     "minecraft": {
     "minecraft": {
         "cmdpage": "Commands/",
         "cmdpage": "Commands/",
-        "fixed": "Fixed Version:",
+        "fixed": "Fixed {{PLURAL:$2|Version|Versions}}:",
         "link": "https://minecraft.gamepedia.com/",
         "link": "https://minecraft.gamepedia.com/",
         "more": "And $1 more.",
         "more": "And $1 more.",
         "private": "**Private Issue**",
         "private": "**Private Issue**",
-        "total": "$1 {{PLURAL:$2|issue|issues}} fixed"
+        "total": "$1 {{PLURAL:$2|issue|issues}} fixed",
+        "issue_link": {
+            "Blocks": {
+                "inward": "is blocked by $1",
+                "outward": "blocks $1"
+            },
+            "Bonfire Testing": {
+                "inward": "discovered while testing $1",
+                "outward": "testing discovered $1"
+            },
+            "Cloners": {
+                "inward": "is cloned by $1",
+                "outward": "clones $1"
+            },
+            "Duplicate": {
+                "inward": "is duplicated by $1",
+                "outward": "duplicates $1"
+            },
+            "Relates": {
+                "inward": "relates to $1",
+                "outward": "relates to $1"
+            }
+        },
+        "status": {
+            "Awaiting Response": "Awaiting Response",
+            "Cannot Reproduce": "Cannot Reproduce",
+            "Closed": "Closed",
+            "Done": "Done",
+            "Duplicate": "Duplicate",
+            "Fixed": "Fixed",
+            "In Progress": "In Progress",
+            "Incomplete": "Incomplete",
+            "Invalid": "Invalid",
+            "Open": "Open",
+            "Postponed": "Postponed",
+            "Reopened": "Reopened",
+            "Resolved": "Resolved",
+            "Won't Fix": "Won't Fix",
+            "Works As Intended": "Works As Intended"
+        }
     },
     },
     "overview": {
     "overview": {
         "articles": "Articles:",
         "articles": "Articles:",