Skip to content

Conversation

@Eric-Zhang-Developer
Copy link
Contributor

Description

Refactored the getTLD function in wikipedia.ts:

  • Replaced giant switch statement with a simple object lookup - The function now uses a map/dictionary instead of a verbose switch/case block
  • Removed unnecessary async - The original function was marked async but contained no asynchronous operations. It was just a pure synchronous string -> string mapping wrapped in a Promise for no reason

Before: ~353 lines
After: ~187 lines
Net reduction: ~166 lines

No functional changes - same input/output behavior, just cleaner code.

Checks

  • Adding/modifying Typescript code?
    • I have used qs, qsa or qsr instead of JQuery selectors.
  • Adding quotes?
    • Make sure to include translations for the quotes in the description (or another comment) so we can verify their content.
  • Adding a language?
    • Make sure to follow the languages documentation
    • Add language to packages/schemas/src/languages.ts
    • Add language to exactly one group in frontend/src/ts/constants/languages.ts
    • Add language json file to frontend/static/languages
  • Adding a theme?
    • Make sure to follow the themes documentation
    • Add theme to packages/schemas/src/themes.ts
    • Add theme to frontend/src/ts/constants/themes.ts
    • (optional) Add theme css file to frontend/static/themes
    • Add some screenshots of the theme, especially with different test settings (colorful, flip colors) to your pull request
  • Adding a layout?
    • Make sure to follow the layouts documentation
    • Add layout to packages/schemas/src/layouts.ts
    • Add layout json file to frontend/static/layouts
  • Adding a font?
    • Make sure to follow the fonts documentation
    • Add font file to frontend/static/webfonts
    • Add font to packages/schemas/src/fonts.ts
    • Add font to frontend/src/ts/constants/fonts.ts
  • Check if any open issues are related to this PR; if so, be sure to tag them below.
  • Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info)
  • Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title.

@monkeytypegeorge monkeytypegeorge added the frontend User interface or web stuff label Jan 20, 2026
@Eric-Zhang-Developer
Copy link
Contributor Author

Good catch! Fixed issues

@fehmer
Copy link
Member

fehmer commented Jan 22, 2026

hi @Eric-Zhang-Developer ,

i just noticed we already have the bcp47 on the language file. Could we use this instead of maintaining another mapping?

const languageProperties = (await JSONData.getLanguage(language)).bcp47 ?? "en-US"

@Eric-Zhang-Developer Eric-Zhang-Developer force-pushed the refactor/wikipedia-funbox-getTLD-function branch 2 times, most recently from 8b58a64 to 18aadb3 Compare January 22, 2026 19:21
@Eric-Zhang-Developer
Copy link
Contributor Author

Done!

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

Labels

frontend User interface or web stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants