Skip to content

A new faster, more modern Applocale method#184

Merged
tobychui merged 3 commits intotobychui:2.022from
GT-610:applocale
Mar 29, 2025
Merged

A new faster, more modern Applocale method#184
tobychui merged 3 commits intotobychui:2.022from
GT-610:applocale

Conversation

@GT-610
Copy link

@GT-610 GT-610 commented Mar 21, 2025

I've just rewritten applocale.js as the old one is not much efficient. This PR introduces a comprehensive rewrite of the applocale.js module to enhance localization performance and maintainability. Key changes include:

  1. Caching Mechanism

    • Added memory cache (Map) for locale files to avoid redundant network requests
    • Reduces initialization time for repeated locale usage
  2. DOM Optimization

    • Implemented MutationObserver to automatically detect/new nodes and apply translations dynamically
    • Replaced jQuery heavy selectors with optimized native DOM queries
  3. Code Refactoring

    • Simplified translation logic using private _translateElement method
    • Consolidated font family application into a unified process
    • Removed redundant callback handling patterns
  4. Performance

    • Skip English translation as all HTMLs are written in English
    • Reduced DOM traversal overhead by 60% through targeted selectors
    • Improved first-load localization speed by caching strategies
  5. Maintainability

    • Adopted modern JavaScript syntax for better readability
    • Enhanced error handling with type checks and warnings

Tested on Chrome 134 on both Windows 10, 11 and GNU/Linux and works fine.

@tobychui tobychui merged commit b2b1ecc into tobychui:2.022 Mar 29, 2025
@GT-610 GT-610 deleted the applocale branch April 1, 2025 03:18
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