diff --git a/resources/i18n/panel.properties b/resources/i18n/panel.properties new file mode 100644 index 0000000..ebb147f --- /dev/null +++ b/resources/i18n/panel.properties @@ -0,0 +1,31 @@ +type.of.change = Type of change +scope.of.this.change = Scope of this change +short.description = Short description +long.description = Long description +closed.issues = Closed issues +closed.issues.description = Comma-separated list of issues which are closed by this commit +breaking.changes = Breaking changes +FEAT = feat +feat.description = feat - A new feature +FIX = fix +fix.description = fix - A bug fix +DOCS = docs +docs.description = docs - Documentation only changes +STYLE = style +style.description = style - Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) +REFACTOR = refactor +refactor.description = refactor - A code change that neither fixes a bug nor adds a feature +PERF = perf +perf.description = perf - A code change that improves performance +TEST = test +test.description = test - Adding missing tests or correcting existing tests +BUILD = build +build.description = build - Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) +CI = ci +ci.description = ci - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) +CHORE = chore +chore.description = chore - Other changes that don't modify src or test files +REVERT = revert +revert.description = revert - Reverts a previous commit +wrap.at.72.characters = Wrap at 72 characters? +skip.ci = &Skip CI? \ No newline at end of file diff --git a/resources/i18n/panel_en.properties b/resources/i18n/panel_en.properties new file mode 100644 index 0000000..3394b58 --- /dev/null +++ b/resources/i18n/panel_en.properties @@ -0,0 +1,31 @@ +type.of.change = Type of change +scope.of.this.change = Scope of this change +short.description = Short description +long.description = Long description +closed.issues = Closed issues +closed.issues.description = Comma-separated list of issues which are closed by this commit +breaking.changes = Breaking changes +FEAT = feat +feat.description = feat - A new feature +FIX = fix +fix.description = fix - A bug fix +DOCS = docs +docs.description = docs - Documentation only changes +STYLE = style +style.description = style - Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) +REFACTOR = refactor +refactor.description = refactor - A code change that neither fixes a bug nor adds a feature +PERF = perf +perf.description = perf - A code change that improves performance +TEST = test +test.description = test - Adding missing tests or correcting existing tests +BUILD = build +build.description = build - Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) +CI = ci +ci.description = ci - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) +CHORE = chore +chore.description = chore - Other changes that don't modify src or test files +REVERT = revert +revert.description = revert - Reverts a previous commit +wrap.at.72.characters = Wrap at 72 characters? +skip.ci = Skip CI? \ No newline at end of file diff --git a/resources/i18n/panel_zh.properties b/resources/i18n/panel_zh.properties new file mode 100644 index 0000000..8d730e3 --- /dev/null +++ b/resources/i18n/panel_zh.properties @@ -0,0 +1,31 @@ +type.of.change = 提交类别 +scope.of.this.change = 变更范围 +short.description = 简短描述 +long.description = 详细描述 +closed.issues = 关闭问题 +closed.issues.description = 此次提交关闭的问题列表,以逗号分隔 +breaking.changes = 不兼容变动 +FEAT = 功能 +feat.description = 功能 - 新功能 +FIX = 修复 +fix.description = 修复 - Bug 修复 +DOCS = 文档 +docs.description = 文档 - 仅文档更改 +STYLE = 样式 +style.description = 样式 - 不会影响代码含义的更改(空格,格式,缺少分号等) +REFACTOR = 重构 +refactor.description = 重构 - 既无修正错误也未增加功能的代码更改 +PERF = 性能 +perf.description = 性能 - 改进性能的代码更改 +TEST = 测试 +test.description = 测试 - 添加缺失的测试或更正现有的测试 +BUILD = 构建 +build.description = 构建 - 影响构建系统或外部依赖项的更改 (示例范围: maven, gradle, npm) +CI = 持续集成 +ci.description = 持续集成 - 对 CI 配置文件和脚本的更改 (示例范围: Travis, Circle, BrowserStack, SauceLabs) +CHORE = 其他 +chore.description = 其他 - 其他非 src 或 test 文件的更改 +REVERT = 回滚 +revert.description = 回滚 - 回滚先前的提交 +wrap.at.72.characters = 72 个字符后换行? +skip.ci = 跳过持续集成? diff --git a/src/com/leroymerlin/commit/ChangeType.java b/src/com/leroymerlin/commit/ChangeType.java index 1271b25..11896d4 100644 --- a/src/com/leroymerlin/commit/ChangeType.java +++ b/src/com/leroymerlin/commit/ChangeType.java @@ -7,32 +7,45 @@ */ public enum ChangeType { - FEAT("Features", "A new feature"), - FIX("Bug Fixes", "A bug fix"), - DOCS("Documentation", "Documentation only changes"), - STYLE("Styles", "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)"), - REFACTOR("Code Refactoring", "A code change that neither fixes a bug nor adds a feature"), - PERF("Performance Improvements", "A code change that improves performance"), - TEST("Tests", "Adding missing tests or correcting existing tests"), - BUILD("Builds", "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)"), - CI("Continuous Integrations", "Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)"), - CHORE("Chores", "Other changes that don't modify src or test files"), - REVERT("Reverts", "Reverts a previous commit"); - - public final String title; - public final String description; - - ChangeType(String title, String description) { + FEAT("feat", ""), + FIX("fix", ""), + DOCS("docs", ""), + STYLE("style", ""), + REFACTOR("refactor", ""), + PERF("perf", ""), + TEST("test", ""), + BUILD("build", ""), + CI("ci", ""), + CHORE("chore", ""), + REVERT("revert", ""); + + private final String title; + private String i18n; + + ChangeType(String title, String i18n) { this.title = title; - this.description = description; + this.i18n = i18n; + } + + public void setI18n(String i18n) { + this.i18n = i18n; + } + + public String label(boolean english) { + return english ? title : i18n; } - public String label() { - return this.name().toLowerCase(); + public static ChangeType lookup(String value) { + for (ChangeType type : ChangeType.values()) { + if (type.title.equalsIgnoreCase(value) || type.i18n.equals(value)) { + return type; + } + } + throw new IllegalArgumentException("ChangeType not found: " + value); } @Override public String toString() { - return String.format("%s - %s", this.label(), this.description); + return String.format("%s - %s", this.name(), this.title); } } diff --git a/src/com/leroymerlin/commit/CommitMessage.java b/src/com/leroymerlin/commit/CommitMessage.java index c5ec119..4bdb7fd 100644 --- a/src/com/leroymerlin/commit/CommitMessage.java +++ b/src/com/leroymerlin/commit/CommitMessage.java @@ -14,10 +14,11 @@ class CommitMessage { private static final int MAX_LINE_LENGTH = 72; // https://stackoverflow.com/a/2120040/5138796 - public static final Pattern COMMIT_FIRST_LINE_FORMAT = Pattern.compile("^([a-z]+)(\\((.+)\\))?: (.+)"); + public static final Pattern COMMIT_FIRST_LINE_FORMAT = Pattern.compile("^(.+?)(\\((.+)\\))?: (.+)"); public static final Pattern COMMIT_CLOSES_FORMAT = Pattern.compile("Closes (.+)"); private ChangeType changeType; + private boolean english = true; private String changeScope, shortDescription, longDescription, breakingChanges, closedIssues; private boolean wrapText = true; private boolean skipCI = false; @@ -28,9 +29,10 @@ private CommitMessage() { this.closedIssues = ""; } - public CommitMessage(ChangeType changeType, String changeScope, String shortDescription, String longDescription, + public CommitMessage(ChangeType changeType, boolean english, String changeScope, String shortDescription, String longDescription, String breakingChanges, String closedIssues, boolean wrapText, boolean skipCI) { this.changeType = changeType; + this.english = english; this.changeScope = changeScope; this.shortDescription = shortDescription; this.longDescription = longDescription; @@ -43,7 +45,7 @@ public CommitMessage(ChangeType changeType, String changeScope, String shortDesc @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append(changeType.label()); + builder.append(changeType.label(english)); if (isNotBlank(changeScope)) { builder .append('(') @@ -101,7 +103,7 @@ public static CommitMessage parse(String message) { Matcher matcher = COMMIT_FIRST_LINE_FORMAT.matcher(message); if (!matcher.find()) return commitMessage; - commitMessage.changeType = ChangeType.valueOf(matcher.group(1).toUpperCase()); + commitMessage.changeType = ChangeType.lookup(matcher.group(1)); commitMessage.changeScope = matcher.group(3); commitMessage.shortDescription = matcher.group(4); @@ -168,4 +170,8 @@ public String getClosedIssues() { public boolean isSkipCI() { return skipCI; } + + public boolean isEnglish() { + return english; + } } \ No newline at end of file diff --git a/src/com/leroymerlin/commit/CommitPanel.form b/src/com/leroymerlin/commit/CommitPanel.form index dc4a59d..d240b19 100644 --- a/src/com/leroymerlin/commit/CommitPanel.form +++ b/src/com/leroymerlin/commit/CommitPanel.form @@ -1,9 +1,9 @@