Create Workset For Linked Element - translation

Hi, @Jean-Marc
In the last PR for the “Create Workset For Linked Element” script, you outlined a translation direction consistent with the general approach.
I didn’t quite understand your last comment ))) and decided to discuss further steps here.
I’ll list the steps I’d like you to check:

  1. Extract the translation for forms.SelectFromList in ResourceDictionary files.
  2. Leave the translations for other cases—forms.alert(), the transaction name, and the if statement—in translations.json.

I might be very wrong. Please describe your vision.
This will be my first time doing this kind of work, but I’m interested.

I’ve figured out what you asked.
I’m currently trying to add translation support to SelectFromList.
I’ll return to this thread later with another question about this script.

1 Like

@Jean-Marc
Returning to the “Create Workset For Linked Element” script.

Since the plugin started translating all GUIs, messages outside of WPF/XAML also needed to be translated.

An example of such a translation is currently available in “Create Workset For Linked Element” using the translations.json file and the get_translations() function. But the function had to be added to both scripts – script.py and config.py.

What do you think about making this translation method universal (as a template)? At least as a basic version.
Then the get_translations() function would need to be moved to “pyrevitlib\pyrevit\script.py”.

I’ve prepared a more universal version of this function by adding an additional argument and default values ​​for the other arguments.

def get_translations(script_folder, script_type=“script”, locale=“en_us”, json_name=“translations.json”):

type: (str, str, str, str) → dict[str, str | list]

“”"
Get translation for a specific script type from a JSON file.

Examples:

# for script.py: 
get_translations(script.get_script_path(), locale=user_config.user_locale) 
# for config.py: 
get_translations(script.get_script_path(), "config", user_config.user_locale) 

Args:
script_folder (str): The folder containing the JSON file.
script_type (str, optional): The type of script for which translations are loaded.

“script”

“config”
locale (str, optional): The locale for which translations are loaded (“en_us”, “fr_fr” etc.).
json_name (str, optional): The name of the JSON file. Default: “translations.json”.

Returns:
dict[str, str | list]: A dictionary containing the translation.
“”"
json_path = os.path.join(script_folder, json_name)
with io.open(json_path, ‘r’, encoding=‘utf-8’) as f:
translations = json.load(f)
script_translations = translations.get(script_type, {})
return script_translations.get(locale, script_translations.get(“en_us”, {}))

If you approve of this idea, I will prepare a PR.

I’m not entirely convinced by the approach yet. And don’t have the bandwidth to set a clear plan.

Maybe @sanzoghenzo has an opinion/idea?

@Jean-Marc @sanzoghenzo
Okay.
Since the plugin is aimed at fully translating scripts, I suggest discussing the best way to translate messages not related to the XAML GUI:

  • messages in windows: forms.alert(), lists of options in forms.SelectFromList.show()
  • transaction names, etc.

I’m willing to participate in translating scripts using the accepted template.
It could be different from the one I’ve proposed.
Or, for example, split my version into separate files for different languages ​​(similar to XAML): translations.en-us.json, translations.fr_fr.json, etc. Or even split it up and link it to the script: translations.script.en-us.json, translations.config.en-us.json.