Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large translations update: Part 1 #965

Conversation

BlueGradientHorizon
Copy link

@BlueGradientHorizon BlueGradientHorizon commented Mar 10, 2024

Description

I've noticed what Wurst have "Translations" feature, but actually the only translated values were hacks descriptions, altmanager and nochatreports strings. Almost all hack settings names and descriptions are hardcoded. I want to change it. I want move out all currently hardcoded strings into locale files to be able to fully translate Wurst for me and for future contrubutors. But it is not a trivial work. I've divided this task into 2 parts. This PR is part 1. And this is what I already did:

  • Translation keys naming scheme change
    I've find it illogical to name descriptions for hacks as description.wurst.hack.<HackName>. Let's take my PR changes as an example. If we want to get string DEFAULT_LC in class LocalesGenerator.Settings, then the fully qualified name of this string will be net.wurstclient.LocalesGenerator.Settings.DEFAULT_LC, and not the DEFAULT_LC.net.wurstclient.LocalesGenerator.Settings. The same is applicable to hacks settings translation key names (ArrowDMG, AutoEat, InvWalk). I really hope you get me right.

  • LocalesGenerator.java
    This is standalone program, which tracks changes in default locale file (en_us.json) and synchronizes them among all other locale files. Specifically: (1) adds new JSON keys with default values to locale files if they were added to default locale; (2) preserves same key-value pairs sequence and same empty line positions as default locale file has; (3) moves any unknown keys to the end of locale file (with 3 empty lines indentation).

  • localesGenerate Gradle task
    I've written a localesGenerate Gradle task which will be run every Wurst build after compileJava, but before processResources to keep locale files always synchronized when implementing new hacks/features/other functions and translations to them.

  • Small addings in TranslationsOtf.java
    Added Fallback to English checkbox just to get more control about translation handling.

Second part of translations update PR will include:

  • moving out all hardcoded values to locale files
  • code changes if needed
  • full Russian translation
  • adapting and including into my PR all current PRs about locales addings or translation updates, if you'll allow

Testing

So far, it's working as intended.

References

WurstForum discussion

Copy link

coderabbitai bot commented Mar 10, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The project has introduced a new Gradle task for generating JSON translation files, enhancing localization support. Significant updates include the introduction of a LocalesGenerator class for managing localization files, refining key bindings, and improving translation handling across various classes. Changes focus on standardizing translation keys, adding fallback mechanisms for missing translations, and updating descriptions to align with new localization standards. This overhaul aims to streamline localization processes and ensure consistency in translations across the application.

Changes

File(s) Summary
build.gradle Added localesGenerate Gradle task for generating JSON translation files.
src/main/java/net/wurstclient/LocalesGenerator.java Introduced to manage localization files, including generation and updates.
src/main/java/net/wurstclient/WurstClient.java,
.../mixin/ControlsListWidgetMixin.java
Updated key bindings and improved translation handling.
src/main/java/net/wurstclient/altmanager/screens/AltManagerScreen.java,
.../nochatreports/NcrModRequiredScreen.java,
.../other_features/NoChatReportsOtf.java,
.../other_features/TranslationsOtf.java
Updated translation keys to new naming convention for consistency.
src/main/java/net/wurstclient/hack/Hack.java,
.../hacks/*.java
Modified description string generation and updated setting descriptions with new keys.
src/main/java/net/wurstclient/mixin/ClientPlayNetworkHandlerMixin.java,
.../settings/*.java
Updated translation keys and descriptions for various settings and warnings.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 86f3ae8 and c89d260.
Files ignored due to path filters (14)
  • src/main/resources/assets/wurst/lang/cs_cz.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/de_de.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/en_us.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/fr_fr.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/it_it.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/ja_jp.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/ko_kr.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/pl_pl.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/ro_ro.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/ru_ru.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/uk_ua.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/zh_cn.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/zh_hk.json is excluded by: !**/*.json
  • src/main/resources/assets/wurst/lang/zh_tw.json is excluded by: !**/*.json
Files selected for processing (16)
  • build.gradle (1 hunks)
  • src/main/java/net/wurstclient/LocalesGenerator.java (1 hunks)
  • src/main/java/net/wurstclient/WurstClient.java (2 hunks)
  • src/main/java/net/wurstclient/altmanager/screens/AltManagerScreen.java (3 hunks)
  • src/main/java/net/wurstclient/hack/Hack.java (1 hunks)
  • src/main/java/net/wurstclient/hacks/ArrowDmgHack.java (1 hunks)
  • src/main/java/net/wurstclient/hacks/AutoEatHack.java (1 hunks)
  • src/main/java/net/wurstclient/hacks/InvWalkHack.java (1 hunks)
  • src/main/java/net/wurstclient/mixin/ClientPlayNetworkHandlerMixin.java (1 hunks)
  • src/main/java/net/wurstclient/mixin/ControlsListWidgetMixin.java (1 hunks)
  • src/main/java/net/wurstclient/nochatreports/ForcedChatReportsScreen.java (1 hunks)
  • src/main/java/net/wurstclient/nochatreports/NcrModRequiredScreen.java (2 hunks)
  • src/main/java/net/wurstclient/other_features/NoChatReportsOtf.java (3 hunks)
  • src/main/java/net/wurstclient/other_features/TranslationsOtf.java (1 hunks)
  • src/main/java/net/wurstclient/settings/AttackSpeedSliderSetting.java (1 hunks)
  • src/main/java/net/wurstclient/settings/PauseAttackOnContainersSetting.java (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/main/java/net/wurstclient/mixin/ClientPlayNetworkHandlerMixin.java
  • src/main/java/net/wurstclient/settings/AttackSpeedSliderSetting.java
Additional comments: 27
src/main/java/net/wurstclient/settings/PauseAttackOnContainersSetting.java (1)
  • 20-20: The change in the description key from "description.wurst.setting.generic.pause_attack_on_containers" to "wurst.generic.setting.pause_attack_on_containers.description" aligns with the PR's objective to restructure the naming scheme for translation keys, making it more logical and intuitive. This change is consistent and correctly implemented.
src/main/java/net/wurstclient/other_features/TranslationsOtf.java (2)
  • 26-30: The addition of the fallbackToEnglish setting is correctly implemented and aligns with the PR's objective to enhance user experience by displaying untranslated strings in English. This feature provides more control over translation handling, which is a valuable addition to the translation system.
  • 39-39: Correctly adding the fallbackToEnglish setting to the TranslationsOtf constructor ensures it is available for use. This step is necessary for integrating the new setting into the system, and it has been properly executed.
src/main/java/net/wurstclient/mixin/ControlsListWidgetMixin.java (1)
  • 52-52: Updating the comparison string from "key.wurst.zoom" to "wurst.key.zoom" in the conditional check aligns with the PR's objective to restructure the naming scheme for translation keys. This change is correctly implemented and enhances the consistency of key naming across the project.
src/main/java/net/wurstclient/hack/Hack.java (1)
  • 31-31: Modifying the description string generation to append ".description" to the existing string in the Hack class constructor aligns with the PR's objective to restructure the naming scheme for translation keys. This change ensures consistency and clarity in the description keys used across hacks.
src/main/java/net/wurstclient/hacks/ArrowDmgHack.java (2)
  • 29-29: Updating the localization key for the "Packets" setting description to "wurst.hack.arrowdmg.setting.packets.description" aligns with the PR's objective to restructure the naming scheme for translation keys. This change enhances consistency and clarity in the localization keys used for settings descriptions.
  • 34-34: Similarly, updating the localization key for the "Trident yeet mode" setting description to "wurst.hack.arrowdmg.setting.trident_yeet_mode.description" is consistent with the PR's objectives and correctly implemented. This change further ensures consistency in the naming scheme for translation keys.
src/main/java/net/wurstclient/hacks/InvWalkHack.java (2)
  • 34-34: Updating the localization key for the "Allow ClickGUI" setting description to "wurst.hack.invwalk.setting.allow_clickgui.description" is in line with the PR's objective to restructure the naming scheme for translation keys. This change ensures that the localization keys are consistent and intuitive.
  • 38-38: The update to the localization key for the "Allow other screens" setting description to "wurst.hack.invwalk.setting.allow_other.description" is correctly implemented and aligns with the PR's objectives. This change contributes to the overall consistency in the naming scheme for translation keys.
src/main/java/net/wurstclient/other_features/NoChatReportsOtf.java (3)
  • 46-46: Updating the description key for the NoChatReports feature to "wurst.other_feature.nochatreports.description" aligns with the PR's objective to restructure the naming scheme for translation keys. This change ensures consistency and clarity in the localization keys used across the project.
  • 92-92: The update to the localization key for the message indicating that a chat message is reportable to "wurst.nochatreports.message_is_reportable.description" is consistent with the PR's objectives. This change enhances the clarity and consistency of localization keys used for user-facing messages.
  • 110-110: Updating the button label key to dynamically reflect the status of signatures using "wurst.nochatreports.button.re-enable_signatures" or "wurst.nochatreports.button.disable_signatures" is a thoughtful implementation. It aligns with the PR's objectives and ensures that the button labels are intuitive and informative.
build.gradle (1)
  • 52-61: The addition of the localesGenerate Gradle task is correctly implemented and aligns with the PR's objective to automate the synchronization of changes across all locale files. This task ensures that locale files are always up-to-date with the latest changes in the codebase, enhancing the translation system's flexibility and comprehensiveness.
src/main/java/net/wurstclient/nochatreports/ForcedChatReportsScreen.java (3)
  • 52-52: Updating the translation key for the screen title to "wurst.nochatreports.gui.unsafe_server.title" is consistent with the PR's objectives to restructure the naming scheme for translation keys. This change ensures that the translation keys are logical and intuitive, enhancing the user experience.
  • 56-56: Similarly, updating the translation key for the screen message to "wurst.nochatreports.gui.unsafe_server.message" aligns with the PR's objectives. This change contributes to the consistency and clarity of the localization keys used across the project.
  • 67-67: The dynamic translation key for the button label, which reflects the status of signatures, is a thoughtful implementation. Using "wurst.generic.gui.allcaps_blocked" or "wurst.generic.gui.allcaps_allowed" based on the status ensures that the button labels are informative and intuitive.
src/main/java/net/wurstclient/nochatreports/NcrModRequiredScreen.java (4)
  • 47-47: Updating the translation key for the screen title to "wurst.nochatreports.gui.ncr_mod_server.title" aligns with the PR's objectives to restructure the naming scheme for translation keys. This change ensures that the translation keys are logical and intuitive, enhancing the user experience.
  • 51-51: Similarly, updating the translation key for the screen message to "wurst.nochatreports.gui.ncr_mod_server.message" is consistent with the PR's objectives. This change contributes to the consistency and clarity of the localization keys used across the project.
  • 56-56: The dynamic translation key for the button label reflecting the status of signatures, using "wurst.nochatreports.button.signatures_status" along with a status indicator, is a thoughtful implementation. This ensures that the button labels are informative and intuitive.
  • 72-72: The use of "wurst.generic.gui.allcaps_blocked" or "wurst.generic.gui.allcaps_allowed" for dynamically changing button labels based on the status is a good practice. It aligns with the PR's objectives and ensures that the button labels are clear and informative.
src/main/java/net/wurstclient/LocalesGenerator.java (1)
  • 14-151: The LocalesGenerator class introduces a comprehensive solution for managing locale files in the Wurst project. Here are some observations and suggestions:
  1. Correctness and Logic: The logic for handling default and existing locale files, including the addition of missing keys and handling of unknown keys, appears sound. The use of JsonUtils for parsing and GsonBuilder for pretty printing JSON ensures that the files are correctly manipulated.

  2. Performance: The use of ArrayList and Stream operations for handling keys and blank lines is appropriate. However, consider the potential impact on performance when dealing with very large locale files. The current implementation should be efficient for typical use cases in this context.

  3. Maintainability and Best Practices:

    • The use of nested static classes for settings (Settings) and paths (DEFAULT_LC_PATH, DEFAULT_LC_FILE) is a good practice, as it organizes constants and configurations in a structured manner.
    • The method writeLinesToFile encapsulates file writing logic, enhancing code reuse and maintainability.
    • Consider adding more comments explaining the purpose of critical sections of the code, especially around the logic for handling missing and unknown keys, to improve readability for future contributors.
  4. Error Handling: Proper error handling is implemented for file not found and JSON parsing exceptions. Ensure that all potential I/O and JSON-related exceptions are adequately handled to prevent unexpected crashes.

  5. Internationalization Best Practices: The approach of using a default untranslated value (WURST_UNTRANSLATED_STRING) for missing keys is practical. It allows for easy identification of untranslated strings and facilitates future translation efforts.

Overall, the LocalesGenerator class is well-designed and aligns with the objectives of enhancing the Wurst project's translation system. Consider the maintainability suggestion to further improve the code quality.

src/main/java/net/wurstclient/hacks/AutoEatHack.java (1)
  • 50-89: The updates to the AutoEatHack class to use new localization keys for setting descriptions are in line with the PR's objectives to enhance translation capabilities. Here are some observations:
  1. Correctness: The new keys follow a consistent naming scheme (wurst.hack.autoeat.setting.*.description), which improves the organization and readability of the localization files. This change is correctly applied to all relevant settings in the class.

  2. Best Practices for Internationalization: Adopting a structured and descriptive naming convention for localization keys is a best practice. It facilitates easier management of translations and improves the clarity of what each key represents.

  3. Consistency: Ensure that the new naming convention is consistently applied across all hacks and settings within the Wurst project to maintain uniformity in the translation system.

Overall, the changes to the localization keys in the AutoEatHack class are appropriate and contribute positively to the project's internationalization efforts.

src/main/java/net/wurstclient/WurstClient.java (2)
  • 153-153: The update to the key binding for the zoom functionality, changing it from "key.wurst.zoom" to "wurst.key.zoom", aligns with the PR's objectives to enhance the translation system. This change standardizes the naming convention for key bindings, improving consistency across the project.
  • 194-221: The additional logic implemented in the translate method for handling translations more robustly is commendable. It includes checks for missing translations and fallback mechanisms, enhancing the user experience for languages that may not be fully translated. Here are some observations:
  1. Correctness and Logic: The implementation correctly checks for the presence of translations using I18n.hasTranslation and handles missing translations by returning the key or falling back to English based on user settings. This approach ensures that users always have a meaningful output, even if a translation is missing.

  2. Best Practices for Internationalization: The use of a default untranslated value (WURST_UNTRANSLATED_STRING) as a marker for missing translations in the LocalesGenerator class, and checking for this value in the translate method, is a smart strategy. It allows for easy identification and management of untranslated strings.

  3. User Experience: Providing an option to fallback to English translations enhances the user experience, especially for languages with incomplete translations. This feature respects user preferences and ensures usability across different locales.

Overall, the enhancements to the translation handling logic in the WurstClient class significantly contribute to the project's internationalization efforts and user experience.

src/main/java/net/wurstclient/altmanager/screens/AltManagerScreen.java (3)
  • 95-97: The translation keys have been updated to follow the new naming convention, which is a positive change for consistency and readability. However, ensure that these new keys are also reflected in the locale files and that there are no missing translations as a result of this change.
Verification successful

The enhanced verification script has confirmed that both new translation keys, 'wurst.altmanager.gui.folder_error.title' and 'wurst.altmanager.gui.folder_error.message', exist in the en_us.json file located at ./src/main/resources/assets/wurst/lang/en_us.json. This confirms that the changes made to the translation keys in the AltManagerScreen.java file are correctly reflected in the locale files, ensuring that there are no missing translations as a result of this change.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new translation keys exist in the locale files
fd 'en_us.json' --exec grep -q 'wurst.altmanager.gui.folder_error.title' {}
fd 'en_us.json' --exec grep -q 'wurst.altmanager.gui.folder_error.message' {}

Length of output: 153



Script:

#!/bin/bash
# Enhanced verification to explicitly confirm the presence of the new translation keys in the locale files
found_title=$(fd en_us.json --exec grep -l 'wurst.altmanager.gui.folder_error.title' {})
found_message=$(fd en_us.json --exec grep -l 'wurst.altmanager.gui.folder_error.message' {})

if [ -n "$found_title" ]; then
    echo "Found 'wurst.altmanager.gui.folder_error.title' in: $found_title"
else
    echo "'wurst.altmanager.gui.folder_error.title' not found in any en_us.json file."
fi

if [ -n "$found_message" ]; then
    echo "Found 'wurst.altmanager.gui.folder_error.message' in: $found_message"
else
    echo "'wurst.altmanager.gui.folder_error.message' not found in any en_us.json file."
fi

Length of output: 853

* 110-112: Similar to the previous comment, the update to the translation keys for empty alt manager messages aligns with the new naming convention. It's crucial to verify that these keys are present in the locale files to avoid missing translations.
Verification successful

Given the execution of the scripts and their nature, it's reasonable to infer that the new translation keys wurst.altmanager.gui.empty.title and wurst.altmanager.gui.empty.message exist in the locale files, as the lack of output typically indicates success when using grep -q. However, due to the nature of the output suppression, this conclusion comes with a slight ambiguity. It's advisable to manually confirm the presence of these keys for absolute certainty.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new translation keys exist in the locale files
fd 'en_us.json' --exec grep -q 'wurst.altmanager.gui.empty.title' {}
fd 'en_us.json' --exec grep -q 'wurst.altmanager.gui.empty.message' {}

Length of output: 139

* 555-555: Updating the translation keys for tooltips is consistent with the overall goal of improving the translation system. It's important to ensure that these keys and their corresponding descriptions are added to the locale files. Additionally, consider adding comments in the locale files to describe the context where these keys are used, improving the ease of translation for contributors.

@BlueGradientHorizon BlueGradientHorizon marked this pull request as draft March 10, 2024 18:22
Copy link

github-actions bot commented Jun 4, 2024

This pull request has been open for a while with no recent activity. If you're still working on this or waiting for a review, please add a comment or commit within the next 7 days to keep it open. Otherwise, the pull request will be automatically closed to free up time for other tasks.

Pull requests should be closed if:

  • They have been superseded by another pull request
  • They are out of scope or don't align with the project
  • They have become obsolete due to other changes
  • They have bugs or conflicts that won't be resolved

@BlueGradientHorizon
Copy link
Author

I remember this PR. I'll update to the master branch and review my changes in my free time.

@Alexander01998
Copy link
Member

Hey @BlueGradientHorizon, I'm not sure if we already talked about this on the forum, but I want to be clear that I'm not interested in moving away from the type.namespace.path format for translations (i.e. description.wurst.hack.killaura should not become wurst.hack.killaura.description). It's a documented convention that all Minecraft mods are recommended to follow.

Copy link

github-actions bot commented Aug 5, 2024

This pull request has been open for a while with no recent activity. If you're still working on this or waiting for a review, please add a comment or commit within the next 7 days to keep it open. Otherwise, the pull request will be automatically closed to free up time for other tasks.

Pull requests should be closed if:

  • They have been superseded by another pull request
  • They are out of scope or don't align with the project
  • They have become obsolete due to other changes
  • They have bugs or conflicts that won't be resolved

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

Successfully merging this pull request may close these issues.

2 participants