Create Workset For Linked Element - translation

@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.