[Bug] Windows compatibility issue in locale directory parsing (get_languages)

Open Beginner friendly
#1,582 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
localization

Research direction

Start in nettacker/core/messages.py at get_languages() and inspect the locale_dir.glob("*.yaml") loop. Verify that the resulting language list contains short codes such as en, fa, and fr across Windows, Linux, and macOS, so language selection no longer falls back to English.

Written by the indexing model from the issue text.

Description

Describe the bug

On Windows systems, the language discovery helper get_languages() fails to extract the short language codes (such as en, fa, fr) from the locale directory paths. Instead, it extracts the full absolute path of the directory along with the language code. This prevents the application from matching and switching languages on Windows, locking the UI and logs to default English.

Where is the problem?

In nettacker/core/messages.py at lines 35-37 :-

for language in Config.path.locale_dir.glob("*.yaml"):
    languages_list.append(str(language).split("/")[-1].split(".")[0])
Why it happens?

On Windows, path separators are backslashes (\). Converting the pathlib.Path object to a string results in a path such as :-

D:\path\to\locale\en.yaml

Since the code splits the string using a forward slash (/), it fails to find any matching separator on Windows :-

str(language).split("/")

As a result, split("/")[-1] returns the entire path string instead of only the filename. The subsequent .split(".")[0] removes the file extension but leaves the drive letter and directory path attached :-

D:\path\to\locale\en

instead of the expected :-

en

Because the extracted value does not match valid language identifiers, language selection fails and the application falls back to the default English locale on Windows.

Proposed Fix

Use pathlib.Path.stem, which is platform-independent and directly returns the filename without its extension :-

def get_languages():
    languages_list = []
    for language in Config.path.locale_dir.glob("*.yaml"):
        languages_list.append(language.stem)
    return list(set(languages_list))

This approach works consistently across Windows, Linux, and macOS while eliminating brittle string-based path parsing.

Dominant language
Python
Stars
5.6k
Forks
1.2k
Avg merge
1d 21h
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OWASP/Nettacker

All issues in OWASP/Nettacker

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.