Update Create Workset For Linked Element#3031
Update Create Workset For Linked Element#3031jmcouffin merged 10 commits intopyrevitlabs:developfrom
Conversation
Update Create Workset For Linked Element - config.py: - Added translations - Reverted the "ZL_" prefix to the name of created Worksets
Update Create Workset For Linked Element: - Added translations
Update Create Workset For Linked Element - script.py: - Translations for both scripts saved to the translations.json file.
Update Create Workset For Linked Element - config.py: - Translations for both scripts have been saved to the translations.json file. - Fixed a bug I introduced earlier in the variable names.
Create translations.json for Create Workset For Linked Element (script, config)
|
Unable to trigger custom agent "Code Reviewer"You have run out of credits 😔 |
Fix russian translation
|
Thanks @Denver-22 , I appreciate the effort. Details
Implementation Strategy for LocalizationThe forms module already has a foundation for localization through the 1. Localization Architecture OverviewThe existing pattern already supports:
2. Implementation DetailsFile Naming Convention (Already in use)For any XAML file, create language-specific ResourceDictionary files: Base XAML Structure (Non-breaking)```xml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource WindowTitle}">
<StackPanel>
<TextBlock Text="{DynamicResource WelcomeMessage}" />
<Button Content="{DynamicResource OkButton}" />
</StackPanel>
</Window>
```English ResourceDictionary (Default)```xml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- Window Properties -->
<system:String x:Key="WindowTitle">Example Window</system:String>
<!-- UI Strings -->
<system:String x:Key="WelcomeMessage">Welcome to pyRevit!</system:String>
<system:String x:Key="OkButton">OK</system:String>
<!-- Tooltips -->
<system:String x:Key="OkButton.Tooltip">Click to confirm</system:String>
</ResourceDictionary>
```French ResourceDictionary```xml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="WindowTitle">Fenêtre d'exemple</system:String>
<system:String x:Key="WelcomeMessage">Bienvenue sur pyRevit!</system:String>
<system:String x:Key="OkButton">OK</system:String>
<system:String x:Key="OkButton.Tooltip">Cliquez pour confirmer</system:String>
</ResourceDictionary>
```3. How the Existing System Works (No changes needed)The def _determine_xaml(self, xaml_source):
# ... existing code ...
# Gets user_config.user_locale (e.g., "fr_fr")
localized_xaml_resfile = xaml_file.replace(
".xaml", ".ResourceDictionary.{}.xaml".format(user_config.user_locale)
)
# Tries localized, then English, then base
if os.path.isfile(localized_xaml_resfile):
self.merge_resource_dict(localized_xaml_resfile)
elif os.path.isfile(english_xaml_resfile):
self.merge_resource_dict(english_xaml_resfile)
return xaml_file4. Migration Guide for Existing Forms (Non-breaking)Step 1: Extract hardcoded strings from existing XAML Before (hardcoded): <Button Content="Select All" />After (localized): <Button Content="{DynamicResource SelectAllButton}" />5. Accessing Localized Strings in Python CodeThe class MyWindow(forms.WPFWindow):
def __init__(self):
forms.WPFWindow.__init__(self, 'MyWindow.xaml')
# Get localized string programmatically
ok_text = self.get_locale_string("OkButton")
# Use it
self.status_tb.Text = ok_text6. Best Practices
7. Backwards Compatibility ✅No breaking changes because:
8. Example: Migrating SelectFromList.xamlCreate localization files based on the ColorSplasher pattern (which already exists in the codebase): ```xml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="SelectButton">Select</system:String>
<system:String x:Key="CheckAllButton">Check All</system:String>
<system:String x:Key="UncheckAllButton">Uncheck All</system:String>
<system:String x:Key="ToggleAllButton">Toggle All</system:String>
<system:String x:Key="ResetButton">Reset</system:String>
<system:String x:Key="SearchPlaceholder">Search...</system:String>
</ResourceDictionary>
```SummaryThe forms module already supports localization through the existing
Yes, the localization system works for all forms module helpers including How Localization Works for Forms Module HelpersPerfect! Now I can give you a complete answer. Yes, the localization system works perfectly for the forms module helpers like
|
| Component | Localization Method | Non-Breaking? |
|---|---|---|
| Static XAML text | {DynamicResource KeyName} |
✅ Yes - base XAML still works if no ResourceDict |
| Dynamic Python text | self.get_locale_string("KeyName") |
✅ Yes - can add try/except or default fallback |
| User-provided text | Pass through kwargs |
✅ Yes - user text always takes precedence |
| File loading | Automatic via _determine_xaml() |
✅ Yes - already implemented! |
The forms module already has everything needed to support localization. You just need to:
- Create the
.ResourceDictionary.{locale}.xamlfiles - Update XAML to use
{DynamicResource}instead of hardcoded text - Update Python code to use
self.get_locale_string()for dynamic text - No breaking changes - everything falls back gracefully!
Renamed keys in translations.json to comply with convention.
- Renamed keys in translations.json to comply with convention. - Some optimizations.
- Renamed keys in translations.json to comply with convention. - Some optimizations.
|
@jmcouffin |
|
@Denver-22 thks, |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26025+1418-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26030+2037-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26030+2039-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26030+2101-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26030+2136-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26030+2147-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26030+2212-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1043-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1111-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1304-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1323-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1433-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1538-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1543-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1553-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1612-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1624-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1738-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1743-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1829-wip |
|
📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1937-wip |
|
📦 New work-in-progress (wip) builds are available for 6.0.0.26032+1956-wip |
|
📦 New work-in-progress (wip) builds are available for 6.0.0.26032+2005-wip |
|
📦 New work-in-progress (wip) builds are available for 6.0.0.26032+2008-wip |
|
📦 New public release are available for 6.0.0.26032+2040 |
|
📦 New public release are available for 6.0.0.26032+2040 |
Update Create Workset For Linked Element
Description
About translations:
In earlier commits, I added translations to the scripts themselves. However, this is not an optimal solution.
Then I moved the translations to the translations.json file. If this approach to translating messages in the script suits you and can be used as a template for translations in other scripts, I suggest moving the get_translations() function to the pyrevitlib\pyrevit\script.py script.
P.S.:
Sync with pyRevit has been added to the commit list. I hope this won't be a problem.