Skip to content

Specify UTF-8 encoding for translation file opening#165

Merged
aaltat merged 1 commit intorobotframework:mainfrom
yuriverweij:bugfix/specify-encoding-when-loading-translation-json
Apr 7, 2026
Merged

Specify UTF-8 encoding for translation file opening#165
aaltat merged 1 commit intorobotframework:mainfrom
yuriverweij:bugfix/specify-encoding-when-loading-translation-json

Conversation

@yuriverweij
Copy link
Copy Markdown
Member

Fix: Open translation JSON files with explicit UTF-8 encoding

Problem

I found this issue when trying to run the unit tests for seleniumlibrary on my Windows machine.

Translation files containing non-ASCII characters (e.g. Finnish ä, ö) are read incorrectly on Windows. The _translation() function in utils/translations.py opens the file without specifying an encoding, so Python falls back to the system locale encoding (cp1252 on Windows). This silently corrupts keyword names and documentation containing multi-byte UTF-8 characters.

For example, a translated keyword name hallinnoi_hälytys is stored as hallinnoi_hälytys in keywords_spec, making it impossible to look up by its correct name.

This does not affect CI pipelines running on Linux, where the default encoding is already UTF-8, which explains why the bug only reproduces locally on Windows.

Fix

Pass encoding="utf-8" explicitly when opening the translation file in utils/translations.py:

# Before
with translation.open("r") as file:

# After
with translation.open("r", encoding="utf-8") as file:

Add UTF-8 encoding when opening translation files.
Copilot AI review requested due to automatic review settings April 7, 2026 15:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Windows-specific bug where translation JSON files containing non-ASCII characters were decoded using the system default encoding instead of UTF-8, corrupting translated keyword names and documentation.

Changes:

  • Open translation JSON files with an explicit encoding="utf-8" in _translation() to ensure consistent decoding across platforms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aaltat aaltat merged commit ac29a9a into robotframework:main Apr 7, 2026
7 of 8 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.

3 participants