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

Refactor _() function to improve translation handling and case preservation #4476

Merged
merged 5 commits into from
Mar 6, 2025

Conversation

Ashrafmuhmed
Copy link
Contributor

What does this PR do?

This PR refactors the _() function to improve its translation handling and case preservation logic. Key changes include:

  • Replaced loop-based character removal with a single regex for better performance.
  • Added a helper function (getTranslationWithCase) to simplify translation logic and handle case variations.
  • Improved the order of translation attempts to prioritize exact matches and preserve the case of the input text.

Why is this change needed?

The existing function had repetitive logic and lacked a structured approach to handling translations with case variations. This refactor makes the code more readable, maintainable, and efficient.

Copy link

github-actions bot commented Mar 1, 2025

✅ All Jest tests passed! This PR is ready to merge.

if (!translated || translated === text) {
translated = document.webL10n.get(text.toLowerCase());
}
// Helper function to get translation with case matching
Copy link
Member

Choose a reason for hiding this comment

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

Please fix indent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh sorry about that, fixed!

Copy link

github-actions bot commented Mar 6, 2025

✅ All Jest tests passed! This PR is ready to merge.

@walterbender walterbender merged commit 83e9fe1 into sugarlabs:master Mar 6, 2025
5 checks passed
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