From 991b7e6c0a6ea07607554c49bcde8eed387bae1b Mon Sep 17 00:00:00 2001 From: Sebastian Sauer Date: Mon, 31 Jul 2023 21:49:31 +0200 Subject: [PATCH] Add i18n --- _locales/en/messages.json | 116 +++++++++++++++++++++++++++++++++++++- manifest.json | 4 +- src/inject/inject.js | 31 +++------- 3 files changed, 125 insertions(+), 26 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 0967ef4..af0871f 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1 +1,115 @@ -{} +{ + "description": { + "message": "An extension to quickly add conventional comments to gitea PR comments." + }, + "blocking": {"message": ""}, + "nonBlocking": {"message": " (non-blocking)"}, + "praise": { + "message": "🏆 praise" + }, + "praiseDescription": { + "message": "$label$s highlight something positive. Try to leave at least one of these comments per review. Do not leave false praise (which can actually be damaging). Do look for something to sincerely praise.", + "placeholders": { + "label": { + "content": "$1", + "example": "praise" + } + } + }, + "nitpick": { + "message": "🔎 nitpick" + }, + "nitpickDescription": { + "message": "$label$s are trivial preference-based requests. These should be non-blocking by nature.", + "placeholders": { + "label": { + "content": "$1", + "example": "nitpick" + } + } + }, + "suggestion": { + "message": "❗ suggestion" + }, + "suggestionDescription": { + "message": "$label$s propose improvements to the current subject. It's important to be explicit and clear on what is being suggested and why it is an improvement. Consider using patches and the blocking or non-blocking decorations to further communicate your intent.", + "placeholders": { + "label": { + "content": "$1", + "example": "suggestion" + } + } + }, + "issue": { + "message": "🪲 issue" + }, + "issueDescription": { + "message": "$label$s highlight specific problems with the subject under review. These problems can be user-facing or behind the scenes. It is strongly recommended to pair this comment with a suggestion. If you are not sure if a problem exists or not, consider leaving a question.", + "placeholders": { + "label": { + "content": "$1", + "example": "issue" + } + } + }, + "question": { + "message": "❓question" + }, + "questionDescription": { + "message": "$label$s are appropriate if you have a potential concern but are not quite sure if it's relevant or not. Asking the author for clarification or investigation can lead to a quick resolution.", + "placeholders": { + "label": { + "content": "$1", + "example": "question" + } + } + }, + "thought": { + "message": "💬 thought" + }, + "thoughtDescription": { + "message": "$label$s represent an idea that popped up from reviewing. These comments are non-blocking by nature, but they are extremely valuable and can lead to more focused initiatives and mentoring opportunities.", + "placeholders": { + "label": { + "content": "$1", + "example": "thought" + } + } + }, + "chore": { + "message": "🏠 chore" + }, + "choreDescription": { + "message": "$label$s are simple tasks that must be done before the subject can be “officially” accepted. Usually, these comments reference some common process. Try to leave a link to the process description so that the reader knows how to resolve the chore.", + "placeholders": { + "label": { + "content": "$1", + "example": "chore" + } + } + }, + "note": { + "message": "📝 note" + }, + "noteDescription": { + "message": "$label$s are always non-blocking and simply highlight something the reader should take note of.", + "placeholders": { + "label": { + "content": "$1", + "example": "note" + } + } + }, + "typo": { + "message": "🪶 typo" + }, + "typoDescription": { + "message": "$label$ comments are like todo:, where the main issue is a mispelling.", + "placeholders": { + "label": { + "content": "$1", + "example": "typo" + } + } + } +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 6c3cf00..2587064 100644 --- a/manifest.json +++ b/manifest.json @@ -2,8 +2,8 @@ "name": "gitea conventional comments buttons", "version": "0.0.2", "manifest_version": 3, - "description": "An extension to quickly add conventional comments to gitea PR comments", - "homepage_url": "https://conventionalcomments.org/", + "description": "__MSG_description__", + "homepage_url": "https://github.com/sebastian-sauer/gitea-conventional-comments-button", "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", diff --git a/src/inject/inject.js b/src/inject/inject.js index e84f46f..6d6942f 100644 --- a/src/inject/inject.js +++ b/src/inject/inject.js @@ -10,60 +10,44 @@ const stickyNoteIcon = ``; /** End of font awesome icons */ +const browser = window.browser ?? window.chrome; + const semanticLabels = { praise: { - text: '🏆 praise', icon: trophyIcon, blocking: false, - description: `s highlight something positive. Try to leave at least one of these comments per review. Do not leave false praise (which can actually be damaging). Do look for something to sincerely praise.`, }, nitpick: { - text: '🔎 nitpick', icon: searchIcon, blocking: false, - description: `s are trivial preference-based requests. These should be non-blocking by nature.`, }, suggestion: { - text: '⁉ suggestion', icon: exclamationIcon, blocking: true, - description: `s propose improvements to the current subject. It's important to be explicit and clear on what is being suggested and why it is an improvement. Consider using patches and the blocking or non-blocking decorations to further communicate your intent.`, }, issue: { - text: '🪲 issue', icon: bugIcon, blocking: true, - description: `s highlight specific problems with the subject under review. These problems can be user-facing or behind the scenes. It is strongly recommended to pair this comment with a suggestion. If you are not sure if a problem exists or not, consider leaving a question.`, }, question: { - text: '❓question', icon: questionIcon, blocking: true, - description: `s are appropriate if you have a potential concern but are not quite sure if it's relevant or not. Asking the author for clarification or investigation can lead to a quick resolution.`, }, thought: { - text: '💬 thought', icon: commentIcon, blocking: false, - description: `s represent an idea that popped up from reviewing. These comments are non-blocking by nature, but they are extremely valuable and can lead to more focused initiatives and mentoring opportunities.`, }, chore: { - text: '🏠 chore', icon: homeIcon, blocking: true, - description: `s are simple tasks that must be done before the subject can be “officially” accepted. Usually, these comments reference some common process. Try to leave a link to the process description so that the reader knows how to resolve the chore.`, }, note: { - text: '📝 note', icon: stickyNoteIcon, blocking: false, - description: `s are always non-blocking and simply highlight something the reader should take note of.`, }, typo: { - text: '🪶 typo', icon: featherIcon, blocking: false, - description: ` comments are like todo:, where the main issue is a mispelling.`, }, }; @@ -82,10 +66,9 @@ const fillTextAreaValue = (textarea, value, emptySubject = true) => { const semanticButtonClickHandler = (e, {textarea, label, blocking}) => { e.preventDefault(); - const decoration = blocking ? '' : ' (non-blocking)'; const semanticComment = semanticCommentStructure - .replace('%text', semanticLabels[label].text) - .replace('%decoration', decoration); + .replace('%text', browser.i18n.getMessage(label)) + .replace('%decoration', (blocking ? '' : ' (non-blocking)')); const cleanedValue = textarea.value.replace( /\*\*.+(\s\(non-blocking\))?:\*\*\s?/, '', @@ -107,7 +90,9 @@ const semanticButtonClickHandler = (e, {textarea, label, blocking}) => { const buttonGenerator = (textarea, parent, label, blocking) => { const button = document.createElement('button'); const semLabel = semanticLabels[label]; - button.setAttribute('data-tooltip-content', semLabel.text + semLabel.description); + const name = browser.i18n.getMessage(label); + const description = browser.i18n.getMessage(label+'Description', name); + button.setAttribute('data-tooltip-content', description); const parser = new DOMParser(); const doc = parser.parseFromString(semLabel.icon, 'image/svg+xml'); button.appendChild(doc.children[0]); @@ -116,7 +101,7 @@ const buttonGenerator = (textarea, parent, label, blocking) => { button.classList.add('blocking'); button.setAttribute( 'data-tooltip-content', - `(blocking) ${semLabel.text}${semLabel.description}`, + `(blocking) ${description}`, ); }