Skip to content

Log Overlay: load whitelist keywords from i18n#161

Open
Halizeur wants to merge 5 commits into
Darkbot-Plugins:mainfrom
Halizeur:halizeur-log-overlay-i18n
Open

Log Overlay: load whitelist keywords from i18n#161
Halizeur wants to merge 5 commits into
Darkbot-Plugins:mainfrom
Halizeur:halizeur-log-overlay-i18n

Conversation

@Halizeur
Copy link
Copy Markdown
Contributor

@Halizeur Halizeur commented May 10, 2026

Switches the hardcoded EN/FR whitelist to an i18n-driven one so other locales can override it via their strings_.properties.

  • LogOverlay.java loads halizeur.log_overlay.whitelist via I18nAPI
  • Falls back to a default English whitelist when the key is missing
  • Adds the key in strings_en.properties and strings_fr.properties

Suggested by @do-gamer in the post-merge review of #159.

Summary by Sourcery

Load log overlay whitelist keywords from i18n with a locale-specific fallback.

Enhancements:

  • Replace hardcoded English/French log overlay whitelist with a locale-driven list loaded via I18n, falling back to a default when missing.
  • Allow translators to customize log overlay whitelist keywords via the halizeur.log_overlay.whitelist key in locale properties files.

Switches the hardcoded EN/FR whitelist to an i18n-driven one so other
locales can override it via their strings_<locale>.properties.

- LogOverlay.java loads halizeur.log_overlay.whitelist via I18nAPI
- Falls back to a default English whitelist when the key is missing
- Adds the key in strings_en.properties and strings_fr.properties

Suggested by @do-gamer in the post-merge review of Darkbot-Plugins#159.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 10, 2026

Reviewer's Guide

Refactors the log overlay whitelist from a hardcoded EN/FR array to a locale-aware, i18n-configured comma-separated string, parsed at startup with a safe default, and updates EN/FR resource bundles to define the whitelist per locale.

Sequence diagram for loading whitelist from i18n in LogOverlay constructor

sequenceDiagram
    actor PluginLoader
    participant PluginAPI
    participant LogOverlay
    participant I18nAPI

    PluginLoader->>PluginAPI: createLogOverlay()
    PluginAPI->>LogOverlay: new LogOverlay(api)
    activate LogOverlay
    LogOverlay->>PluginAPI: requireAPI(EventBrokerAPI)
    PluginAPI-->>LogOverlay: EventBrokerAPI instance
    LogOverlay->>PluginAPI: requireAPI(I18nAPI)
    PluginAPI-->>LogOverlay: I18nAPI instance
    LogOverlay->>I18nAPI: getOrDefault(halizeur.log_overlay.whitelist, DEFAULT_WHITELIST)
    I18nAPI-->>LogOverlay: csvKeywords
    LogOverlay->>LogOverlay: whitelist = parseKeywords(csvKeywords)
    deactivate LogOverlay
Loading

Class diagram for updated LogOverlay whitelist handling

classDiagram
    class PluginAPI {
        +requireAPI(apiClass)
    }

    class I18nAPI {
        +getOrDefault(key, defaultValue) String
    }

    class LogOverlay {
        -static long DISPLAY_MS
        -static String DEFAULT_WHITELIST
        -Deque~Entry~ entries
        -List~String~ whitelist
        -LogOverlayConfig config
        +LogOverlay(PluginAPI api)
        -static List~String~ parseKeywords(String csv)
        -boolean isAllowed(String msg)
    }

    PluginAPI --> LogOverlay : constructs
    LogOverlay ..> I18nAPI : uses
    LogOverlay ..> PluginAPI : requires APIs
Loading

File-Level Changes

Change Details Files
Replace hardcoded whitelist array with an i18n-driven, locale-specific whitelist loaded at construction time.
  • Remove the static string-array whitelist and replace it with a single comma-separated default whitelist string constant.
  • Introduce a whitelist instance field and initialize it in the constructor via I18nAPI.getOrDefault using the halizeur.log_overlay.whitelist key with fallback to the default string.
  • Add a parseKeywords helper that splits the CSV, trims whitespace, lowercases entries, and filters out empties to produce the runtime whitelist list.
src/main/java/dev/shared/halizeur/log_overlay/LogOverlay.java
Update whitelist filtering logic to use the parsed, locale-aware keyword list.
  • Adjust isAllowed to iterate over the whitelist List field instead of the removed static array.
  • Clarify Javadoc on isAllowed to describe the i18n-based whitelist behavior tied to the user’s DarkBot locale.
src/main/java/dev/shared/halizeur/log_overlay/LogOverlay.java
Define the whitelist i18n key for English and French locales to preserve existing behavior while allowing overrides for other locales.
  • Add halizeur.log_overlay.whitelist to strings_en.properties with the English keywords previously hardcoded in Java.
  • Add halizeur.log_overlay.whitelist to strings_fr.properties with the French (and shared) keywords previously hardcoded in Java, keeping behavior consistent for FR users.
src/main/resources/dev/shared/lang/strings_en.properties
src/main/resources/dev/shared/lang/strings_fr.properties

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/main/java/dev/shared/halizeur/log_overlay/LogOverlay.java" line_range="78" />
<code_context>
+        List<String> out = new ArrayList<>();
+        if (csv == null) return out;
+        for (String s : csv.split(",")) {
+            String t = s.trim().toLowerCase();
+            if (!t.isEmpty()) out.add(t);
+        }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Use a locale-independent lowercasing to avoid subtle issues on non-English locales.

`toLowerCase()` without an explicit locale can mis-handle some characters (e.g., in Turkish). Since these are technical identifiers, please use `toLowerCase(Locale.ROOT)` so behavior is consistent across all user locales.

Suggested implementation:

```java
import java.util.List;
import java.util.Locale;

```

```java
            String t = s.trim().toLowerCase(Locale.ROOT);

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/main/java/dev/shared/halizeur/log_overlay/LogOverlay.java Outdated
@do-gamer
Copy link
Copy Markdown
Contributor

do-gamer commented May 10, 2026

@Halizeur As suggestion you may try to add whitelist to config as multi-select/checkbox-list, to choose what display.
Maybe not an exact whitelist, but like groups of keywords "resources", "errors", etc.

Per do-gamer review: replace the comma-separated halizeur.log_overlay.whitelist
i18n key with a Categories sub-config of 6 toggles (gains, currencies,
resources, boosters, errors, combat). Each category bundles FR + EN
keywords so the filter works on both locales without per-translator upkeep.
Default: 5 categories on, combat off.
@do-gamer
Copy link
Copy Markdown
Contributor

do-gamer commented May 10, 2026

Actually need to use GameResourcesAPI instance of i18n

API link: https://javadoc.jitpack.io/eu/darkbot/DarkBotAPI/darkbot-api/master-359b80a001-1/javadoc/eu/darkbot/api/managers/GameResourcesAPI.html

The Bigpoint templates which use the API (English) https://darkorbit-22.bpsecure.com/spacemap/templates/en/flashres.xml

Example:

<item name="log_msg_gather_credit_p"><![CDATA[You received %COUNT% Credits.]]></item>
<item name="log_msg_gather_uridium_p"><![CDATA[You received %COUNT% Uridium.]]></item>

Halizeur and others added 2 commits May 10, 2026 18:28
Per do-gamer review: drop the hardcoded FR + EN keyword list and match
messages via GameResourcesAPI.getTranslationMatcher() on the official
Bigpoint flashres keys instead. Categories Gains, Boosters, Errors and
Combat are now driven by translation matchers; Currencies / Resources
stay on substring matching since their names appear inside the %!
placeholder of the gain templates (resource names are resolved via
findTranslation("ore_*") so they still adapt to the active locale).
@sonarqubecloud
Copy link
Copy Markdown

Comment on lines 26 to +37
@@ -26,6 +30,11 @@
* Source: {@link GameLogAPI.LogMessageEvent} emitted by DarkBot for each
* new system message. Each line disappears after DISPLAY_MS ms so the
* canvas does not get cluttered.
*
* Filter: per category, the overlay matches messages against translation
* patterns from {@link GameResourcesAPI} (the official Bigpoint flashres
* keys), so the filter works on every game locale without per-language
* keyword maintenance.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments like this

Comment on lines +105 to +108
/** Currency names. DarkOrbit keeps these mostly untranslated across
* locales, so a static list works as a substring filter against any
* raw log message. Lower-cased at init time for case-insensitive
* comparison. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments like this

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.

3 participants