Skip to content

Allow dictionaries as translation sources#173

Merged
aaltat merged 3 commits into
robotframework:mainfrom
csvtuda:main
May 14, 2026
Merged

Allow dictionaries as translation sources#173
aaltat merged 3 commits into
robotframework:mainfrom
csvtuda:main

Conversation

@csvtuda

@csvtuda csvtuda commented May 14, 2026

Copy link
Copy Markdown
Contributor

This PR allows plain dictionaries as translation sources for libraries, skipping the file handling entirely.

It also adds support for YAML instead of JSON and all encodings that are out there.

class SmallLibrary(DynamicCore):
    """Library documentation."""

    def __init__(self):
        """__init__ documentation."""
        translation_data = {
          # translation data acquired from somewhere
        }
        DynamicCore.__init__(self, [], translation=translation_data)

Motivation

We've recently added translation support for a lot of our Robot Framework libraries. Unfortunately, due to translation tool restrictions, we get all translations in a single gigantic JSON like this:

{
  "lib_1": {
    "en_US": {
      "keyword_1": {},
      "keyword_2": {},
    },
    "de_DE": {
      "keyword_1": {},
      "keyword_2": {},
    }
    // more locales
  },
  "lib_2": {
    "en_US": {
      "keyword_1": {},
      "keyword_2": {},
    },
    "fi_FI": {
      "keyword_1": {},
      "keyword_2": {},
    }
    // more locales
  },
  // other libraries ...
}

Therefore, we currently need to:

  1. parse the JSON
  2. split the JSON into library/locale chunks
  3. write the chunks to files
  4. pass the file paths to the libraries

It would be a lot easier (and also somewhat more performant regarding startup times of RobotCode IDE plugins etc.) if we could simply skip steps 2 and 3:

  1. parse the JSON
  2. pass the JSON to the libraries

If you have more questions or suggestions, feel free to ask!

@aaltat

aaltat commented May 14, 2026

Copy link
Copy Markdown
Contributor

I like your idea. Can you rebase with main, I just dropped Python 3.8 and 3.9 support from the project.

@aaltat

aaltat commented May 14, 2026

Copy link
Copy Markdown
Contributor

Make also example int the README about the new feature.

@csvtuda csvtuda force-pushed the main branch 2 times, most recently from 047b392 to 22a64c5 Compare May 14, 2026 13:42
@csvtuda

csvtuda commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@aaltat thanks for the heads up, I rebased and updated the README.

@aaltat aaltat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small thing to fix

Comment thread atest/SmallLibrary.py Outdated
@aaltat

aaltat commented May 14, 2026

Copy link
Copy Markdown
Contributor

Robocop complains about style. Can you run robocop (with default settings) and let it fix test data

@aaltat

aaltat commented May 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #176

@aaltat aaltat merged commit fa5f7f4 into robotframework:main May 14, 2026
4 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