Skip to content

Added new rules - #4

Open
ronnie-neo-sonarsource wants to merge 4 commits into
mainfrom
test-patch-004
Open

Added new rules#4
ronnie-neo-sonarsource wants to merge 4 commits into
mainfrom
test-patch-004

Conversation

@ronnie-neo-sonarsource

@ronnie-neo-sonarsource ronnie-neo-sonarsource commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary by Gitar

  • Plugin refactoring:
    • Renamed JapanesePackPlugin to LanguagePackPlugin to support multi-language translation packs in LanguagePackPlugin.java
    • Updated pom.xml coordinates and metadata for the multi-language plugin package
  • Translation updates:
    • Updated python/translate.py to iterate over configured languages including Japanese and Korean
  • Documentation:
    • Updated README.md instructions for building and using the multi-language pack

This will update automatically on new commits.

Comment thread src/main/java/org/sonar/plugins/l10n/LanguagePackPlugin.java Outdated
Comment thread src/main/java/org/sonar/plugins/l10n/LanguagePackPlugin.java Outdated
@ronnie-neo-sonarsource

Copy link
Copy Markdown
Owner Author

Gitar Please check if the functions have less 10 parameters

@gitar-bot

gitar-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

Gitar Please check if the functions have less 10 parameters

Checked all functions/methods changed in this PR (Python translate.py and the Java LanguagePackPlugin/test files). None come close to 10 parameters — the highest is translate_properties(input_file, output_file, target_lang, batch_size=500) with 4. No violations found.

@ronnie-neo-sonarsource

Copy link
Copy Markdown
Owner Author

Gitar please apply the fixes suggested

Co-authored-by: Ronnie Neo <171651979+ronnie-neo-sonarsource@users.noreply.github.com>
@gitar-bot

gitar-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

Gitar please apply the fixes suggested

Applied both fixes in LanguagePackPlugin.java:

  • Renamed hasBundle/hasAllBundles to has_bundle/has_all_bundles to comply with the snake_case coding standard.
  • Wired has_all_bundles() into define() as a sanity check (throws if a shipped bundle is missing from the classpath), and added test coverage for both methods in LanguagePackPluginTest.

@ronnie-neo-sonarsource

Copy link
Copy Markdown
Owner Author

Gitar please check again

@gitar-bot

gitar-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

Gitar please check again

Sure, re-reviewing the current state of the PR now.

@ronnie-neo-sonarsource

Copy link
Copy Markdown
Owner Author

Gitar please help me understand what has been changed

@gitar-bot

gitar-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

Here's a summary of what this PR changes:

Core change: single Japanese-only plugin → multi-language plugin

  • JapanesePackPlugin.java was renamed/rewritten to LanguagePackPlugin.java. It now ships both Japanese (core_ja.properties) and Korean (core_ko.properties) bundles instead of just Japanese.
  • Added has_bundle(locale) and has_all_bundles() sanity-check methods that verify the expected .properties files are actually present on the classpath. define() now calls has_all_bundles() and throws IllegalStateException if a shipped bundle is missing, so packaging mistakes fail fast at plugin init instead of silently shipping a broken jar.
  • JapanesePackPluginTest was renamed to LanguagePackPluginTest, updated for the new class name, and two new tests (has_bundle_should_find_shipped_locales, has_all_bundles_should_be_true_when_all_shipped_bundles_are_present) were added to cover the new methods.

Build metadata (pom.xml)

  • groupId/artifactId/name/description/sonar.pluginClass updated from the Japanese-specific values to generic "Language Pack" values reflecting the multi-language scope.

Python translation script (python/translate.py)

  • Replaced the hardcoded single-language config (target_language, target_filename, source_filename) with a LANGUAGES list of (name, locale) pairs (currently Japanese + Korean) and template paths (report_template, target_template) derived from the locale.
  • translate_chunk no longer defaults target_lang to "Korean" — it's now a required parameter.
  • The OpenAI model is read from a variable (openai_model) instead of being hardcoded to "gpt-4o".
  • translate_properties now skips gracefully (prints a message and returns) when there are no missing translations for a language, instead of erroring.
  • The bottom of the script now loops over every entry in LANGUAGES and runs the translation for each, instead of a single hardcoded call.

Docs (README.md)

  • Rewritten to describe the multi-language design (bundles auto-discovered by classpath presence, add a language by dropping in a core_<locale>.properties file + adding it to LANGUAGES), and the updated file paths/commands (target/l10n/core_<locale>.properties.report.txt, cd python && python3 translate.py, new jar name sonar-l10n-plugin-*.jar).

Review config (.gitar/review/common.md, new file)

  • Adds a custom coding standard: new/changed functions in Java, Python, and JS/TS must use snake_case, and no "TODO" comments are allowed. This is why the earlier review flagged hasBundle/hasAllBundles for camelCase, and why those were subsequently renamed to has_bundle/has_all_bundles.

Net effect: the plugin went from single-purpose (Japanese only) to a generic language pack that currently bundles Japanese and Korean, with a matching translation script, docs, and safety check that the shipped locale bundles are actually on the classpath.

@gitar-bot

gitar-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Refactors the Japanese translation pack into a multi-language LanguagePackPlugin with updated coordinates, script iteration, and documentation, addressing the unused methods and naming convention findings.

✅ 2 resolved
Quality: hasBundle/hasAllBundles are unused and untested

📄 src/main/java/org/sonar/plugins/l10n/LanguagePackPlugin.java:52-65 📄 src/test/java/org/sonar/plugins/l10n/LanguagePackPluginTest.java:42-52
hasBundle and hasAllBundles are newly added but never invoked anywhere (define() adds an empty extension list) and are not covered by LanguagePackPluginTest, which only asserts the plugin name and calls define(). Either wire these sanity checks into the plugin/test flow or remove them as dead code to avoid untested, unreachable logic.

Quality: New Java methods use camelCase, not snake_case

📄 src/main/java/org/sonar/plugins/l10n/LanguagePackPlugin.java:52 📄 src/main/java/org/sonar/plugins/l10n/LanguagePackPlugin.java:63
The custom coding standard requires new/changed functions to follow snake_case format in Java, Python, and JS/TS. The two newly added public methods in LanguagePackPlugin.java, hasBundle and hasAllBundles, use camelCase. To comply with the stated standard, rename them (e.g. has_bundle, has_all_bundles). Note this conflicts with conventional Java style, so confirm the standard is intended to apply to Java before renaming.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants