Browse Source

Localized title's of Window class

CPKreuz 2 years ago
parent
commit
08874e8b9a

+ 3 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -556,5 +556,7 @@
   "SOURCE_NEWER": "Source newer",
   "SOURCE_UP_TO_DATE": "Source is up to date",
   "SOURCE_OLDER": "Cloud newer",
-  "LOCALIZATION_DEBUG_WINDOW_TITLE": "Localization Debug Window"
+  "LOCALIZATION_DEBUG_WINDOW_TITLE": "Localization Debug Window",
+  "COMMAND_DEBUG_WINDOW_TITLE": "Command Debug Window",
+  "SHORTCUTS_TITLE": "Shortcuts"
 }

+ 3 - 2
src/PixiEditor/Views/Dialogs/AboutPopup.xaml

@@ -11,7 +11,8 @@
         xmlns:views="clr-namespace:PixiEditor.Views"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         mc:Ignorable="d" WindowStyle="None"
-        Title="About" WindowStartupLocation="CenterScreen"
+        views:Translator.Key="ABOUT"
+        WindowStartupLocation="CenterScreen"
         Height="510" Width="400" Name="aboutPopup" MinWidth="100" MinHeight="100"
         FlowDirection="{helpers:Localization FlowDirection}">
     <Window.CommandBindings>
@@ -30,7 +31,7 @@
         </b:Interaction.Behaviors>
 
         <local:DialogTitleBar DockPanel.Dock="Top"
-                             TitleKey="{Binding ElementName=aboutPopup, Path=Title}" 
+                             TitleKey="ABOUT" 
                              CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"/>
         <StackPanel DataContext="{Binding ElementName=aboutPopup}" Orientation="Vertical" DockPanel.Dock="Bottom" Margin="10">
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top">

+ 1 - 0
src/PixiEditor/Views/Dialogs/ConfirmationPopup.xaml

@@ -14,6 +14,7 @@
         Name="popup" WindowStartupLocation="CenterScreen" 
         Height="180" Width="400" MinHeight="180" MinWidth="400"
         WindowStyle="None"
+        views:Translator.Key="{Binding ElementName=popup, Path=Title}"
         FlowDirection="{helpers:Localization FlowDirection}"
         d:DataContext="{d:DesignInstance dial:ConfirmationPopup}">
 

+ 4 - 2
src/PixiEditor/Views/Dialogs/DebugDialogs/CommandDebugPopup.xaml

@@ -9,11 +9,13 @@
         xmlns:command="clr-namespace:PixiEditor.Models.Commands"
         xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.XAML" xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
+        xmlns:views="clr-namespace:PixiEditor.Views"
         WindowStyle="None"
         mc:Ignorable="d"
         x:Name="uc"
         Foreground="White"
-        Title="Command Debug" Height="450" Width="800"
+        views:Translator.Key="COMMAND_DEBUG_WINDOW_TITLE"
+        Height="450" Width="800"
         FlowDirection="{helpers:Localization FlowDirection}">
 
     <Window.CommandBindings>
@@ -33,7 +35,7 @@
 
         <local:DialogTitleBar DockPanel.Dock="Top"
                               CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"
-                              TitleKey="Command Debug" />
+                              TitleKey="COMMAND_DEBUG_WINDOW_TITLE" />
 
         <Grid>
             <Grid.RowDefinitions>

+ 1 - 1
src/PixiEditor/Views/Dialogs/DebugDialogs/Localization/LocalizationDebugWindow.xaml

@@ -17,7 +17,7 @@
         x:Name="popup"
         mc:Ignorable="d"
         Foreground="White"
-        Title="LocalizationDebugWindow"
+        views:Translator.Key="LOCALIZATION_DEBUG_WINDOW_TITLE"
         MinHeight="240" MinWidth="465"
         Height="350" Width="465"
         FlowDirection="{helpers:Localization FlowDirection}"

+ 2 - 1
src/PixiEditor/Views/Dialogs/ExportFilePopup.xaml

@@ -11,7 +11,8 @@
         xmlns:userControls="clr-namespace:PixiEditor.Views.UserControls"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         mc:Ignorable="d" BorderBrush="Black" BorderThickness="1"
-        Title="SaveFilePopup" WindowStyle="None" MinHeight="330" MinWidth="310" Width="310"
+        WindowStyle="None" MinHeight="330" MinWidth="310" Width="310"
+        local:Translator.Key="EXPORT_IMAGE"
         SizeToContent="Height"
         WindowStartupLocation="CenterScreen" Name="saveFilePopup"
         FlowDirection="{helpers:Localization FlowDirection}">

+ 3 - 2
src/PixiEditor/Views/Dialogs/ImportFilePopup.xaml

@@ -12,11 +12,12 @@
         xmlns:userControls="clr-namespace:PixiEditor.Views.UserControls"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         mc:Ignorable="d" BorderBrush="Black" BorderThickness="1"
-        Title="ImportFilePopup" ShowInTaskbar="False" 
+        ShowInTaskbar="False" 
         MinHeight="250" MinWidth="300" Height="250" Width="300" 
         WindowStyle="None" 
         WindowStartupLocation="CenterScreen" 
         Name="importFilePopup"
+        local:Translator.Key="IMPORT_FILE_TITLE"
         DataContext="{DynamicResource ImportFilePopupViewModel}"
         FlowDirection="{helpers:Localization FlowDirection}">
     <Window.Resources>
@@ -38,7 +39,7 @@
         </i:Interaction.Behaviors>
 
         <dial:DialogTitleBar DockPanel.Dock="Top"
-            TitleKey="Import image" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"/>
+            TitleKey="IMPORT_FILE_TITLE" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"/>
         <Button DockPanel.Dock="Bottom" Width="70" HorizontalAlignment="Center" IsDefault="True"
                     Margin="15" Style="{StaticResource DarkRoundButton}" Content="Import" Command="{Binding OkCommand}"
                     CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />

+ 3 - 32
src/PixiEditor/Views/Dialogs/ImportShortcutTemplatePopup.xaml

@@ -5,9 +5,9 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:diag="clr-namespace:PixiEditor.Views.Dialogs"
-        xmlns:xaml="clr-namespace:PixiEditor.Models.Commands.XAML"
         xmlns:userControls="clr-namespace:PixiEditor.Views.UserControls"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
+        xmlns:views="clr-namespace:PixiEditor.Views"
         mc:Ignorable="d"
         Title="Import from template" Foreground="White"
         WindowStartupLocation="CenterOwner"
@@ -15,7 +15,8 @@
         SizeToContent="WidthAndHeight" WindowStyle="None"
         Background="{StaticResource AccentColor}"
         x:Name="window"
-        FlowDirection="{helpers:Localization FlowDirection}">
+        FlowDirection="{helpers:Localization FlowDirection}"
+        views:Translator.Key="IMPORT_FROM_TEMPLATE">
 
     <Window.CommandBindings>
         <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute"
@@ -48,36 +49,6 @@
                         Logo="{Binding LogoPath}" Cursor="Hand" 
                         MouseLeftButtonUp="OnTemplateCardLeftMouseButtonDown"
                         HoverLogo="{Binding Path=HoverLogoPath}"/>
-                    <!--<Grid Margin="0,5,0,0">
-                        <Grid.ColumnDefinitions>
-                            <ColumnDefinition Width="*"/>
-                            <ColumnDefinition Width="Auto"/>
-                        </Grid.ColumnDefinitions>
-                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center"
-                                   ToolTip="{Binding Description}"/>
-                        <Image Source="{Binding LogoPath}" Width="48" Height="48"/>
-                        <StackPanel Grid.Column="1" Orientation="Horizontal">
-                            <StackPanel.Resources>
-                                <Style TargetType="Button" BasedOn="{StaticResource DarkRoundButton}">
-                                    <Setter Property="Width" Value="120"/>
-                                    <Setter Property="Height" Value="Auto"/>
-                                    <Setter Property="Padding" Value="5"/>
-                                    <Setter Property="FontSize" Value="12"/>
-                                    <Setter Property="Margin" Value="5,0, 0, 0"/>
-                                </Style>
-                            </StackPanel.Resources>
-                            <Button Command="{xaml:Command PixiEditor.Shortcuts.Provider.ImportInstallation, UseProvided=True}"
-                                    CommandParameter="{Binding}" Content="From installed"
-                                    Visibility="{Binding ProvidesFromInstallation, Converter={BoolToVisibilityConverter}}"
-                                    IsEnabled="{Binding HasInstallationPresent}"/>
-                            <Button Command="{xaml:Command PixiEditor.Shortcuts.Provider.ImportFile, UseProvided=True}"
-                                    CommandParameter="{Binding}" Content="Import file"
-                                    Visibility="{Binding ProvidesImport, Converter={BoolToVisibilityConverter}}"/>
-                            <Button Command="{xaml:Command PixiEditor.Shortcuts.Provider.ImportDefault, UseProvided=True}"
-                                    CommandParameter="{Binding}" Content="Import defaults"
-                                    Visibility="{Binding HasDefaultShortcuts, Converter={BoolToVisibilityConverter}}"/>
-                        </StackPanel>
-                    </Grid>-->
                 </DataTemplate>
             </ItemsControl.ItemTemplate>
         </ItemsControl>

+ 2 - 1
src/PixiEditor/Views/Dialogs/NewFilePopup.xaml

@@ -19,7 +19,8 @@
         SizeToContent="Width"
         Name="newFilePopup" 
         BorderBrush="Black" BorderThickness="1"
-        FlowDirection="{helpers:Localization FlowDirection}">
+        FlowDirection="{helpers:Localization FlowDirection}"
+        local:Translator.Key="CREATE_NEW_IMAGE">
     <Window.Resources>
         <vm:NewFileMenuViewModel x:Key="NewFileMenuViewModel" />
     </Window.Resources>

+ 1 - 0
src/PixiEditor/Views/Dialogs/NoticePopup.xaml

@@ -14,6 +14,7 @@
         d:Title="Notice" Height="180" Width="400" MinHeight="180" MinWidth="400"
         WindowStartupLocation="CenterScreen"
         x:Name="popup"
+        views:Translator.Key="{Binding ElementName=popup, Path=Title}"
         FlowDirection="{helpers:Localization FlowDirection}">
 
     <WindowChrome.WindowChrome>

+ 3 - 1
src/PixiEditor/Views/Dialogs/OptionsPopup.xaml

@@ -7,12 +7,14 @@
         xmlns:local="clr-namespace:PixiEditor.Views.Dialogs"
         xmlns:uc="clr-namespace:PixiEditor.Views.UserControls"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
+        xmlns:views="clr-namespace:PixiEditor.Views"
         mc:Ignorable="d"
         WindowStartupLocation="CenterScreen"
         SizeToContent="WidthAndHeight"
         x:Name="popup"
         Background="{StaticResource AccentColor}" Foreground="White"
-        FlowDirection="{helpers:Localization FlowDirection}">
+        FlowDirection="{helpers:Localization FlowDirection}"
+        views:Translator.Key="{Binding Title, ElementName=popup}">
 
     <WindowChrome.WindowChrome>
         <WindowChrome CaptionHeight="32"  GlassFrameThickness="0.1"

+ 0 - 1
src/PixiEditor/Views/Dialogs/OptionsPopup.xaml.cs

@@ -39,7 +39,6 @@ internal partial class OptionPopup : Window
 
     public OptionPopup(string title, object content, ObservableCollection<object> options)
     {
-        Title = title;
         PopupContent = content;
         Options = options;
         CancelCommand = new RelayCommand(Cancel);

+ 2 - 1
src/PixiEditor/Views/Dialogs/PalettesBrowser.xaml

@@ -20,7 +20,8 @@
     Height="600" Width="850" 
     WindowStyle="None"
     x:Name="palettesBrowser"
-    FlowDirection="{helpers:Localization FlowDirection}">
+    FlowDirection="{helpers:Localization FlowDirection}"
+    views:Translator.Key="PALETTE_BROWSER">
     <Window.Resources>
         <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
     </Window.Resources>

+ 2 - 1
src/PixiEditor/Views/Dialogs/ResizeCanvasPopup.xaml

@@ -13,7 +13,8 @@
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         mc:Ignorable="d" 
         x:Name="window"
-        Title="ResizeCanvasPopup" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
+        ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
+        local:Translator.Key="RESIZE_CANVAS"
         Height="420" Width="320" MinHeight="420" MinWidth="320" 
         WindowStyle="None"
         FlowDirection="{helpers:Localization FlowDirection}">

+ 2 - 1
src/PixiEditor/Views/Dialogs/ResizeDocumentPopup.xaml

@@ -9,7 +9,8 @@
         xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
         xmlns:dial="clr-namespace:PixiEditor.Views.Dialogs"
         mc:Ignorable="d" x:Name="window"
-        Title="ResizeDocumentPopup" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
+        ShowInTaskbar="False" WindowStartupLocation="CenterScreen"
+        local:Translator.Key="RESIZE_IMAGE"
         Height="305" Width="310" MinHeight="305" MinWidth="310"
         xmlns:base="clr-namespace:PixiEditor.Views"
         xmlns:userControls="clr-namespace:PixiEditor.Views.UserControls"

+ 3 - 2
src/PixiEditor/Views/Dialogs/SettingsWindow.xaml

@@ -19,14 +19,15 @@
         xmlns:localization="clr-namespace:PixiEditor.Localization"
         xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         mc:Ignorable="d"
-        Title="Settings" Name="window" 
+        Name="window" 
         Height="688" Width="780"
         MinHeight="500" MinWidth="665"
         WindowStyle="None" DataContext="{DynamicResource SettingsWindowViewModel}"
         WindowStartupLocation="CenterScreen"
         BorderBrush="Black" BorderThickness="1"
         Background="{StaticResource AccentColor}"
-        FlowDirection="{helpers:Localization FlowDirection}">
+        FlowDirection="{helpers:Localization FlowDirection}"
+        views:Translator.Key="SETTINGS">
     <Window.Resources>
         <viewmodels:SettingsWindowViewModel x:Key="SettingsWindowViewModel"/>
         <BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>

+ 3 - 2
src/PixiEditor/Views/Dialogs/ShortcutPopup.xaml

@@ -16,7 +16,8 @@
         mc:Ignorable="d"
         WindowStartupLocation="CenterScreen"
         SizeToContent="Height"
-        Title="ShortcutPopup" WindowStyle="None"
+        WindowStyle="None"
+        views:Translator.Key="SHORTCUTS_TITLE"
         MinHeight="780" MinWidth="620" Topmost="{Binding IsTopmost}"
         Width="950" MaxHeight="1000"
         FlowDirection="{helpers:Localization FlowDirection}"
@@ -82,7 +83,7 @@
                           WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Makes this window always on top"/>
         </DockPanel>
 
-        <TextBlock Grid.Row="0" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center">Shortcuts</TextBlock>
+        <TextBlock Grid.Row="0" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" views:Translator.Key="SHORTCUTS_TITLE"/>
 
         <DockPanel Grid.Row="3">
             <TextBlock FontSize="14" Margin="10" Foreground="LightGray" HorizontalAlignment="Left" DockPanel.Dock="Bottom">

+ 16 - 0
src/PixiEditor/Views/Translator.cs

@@ -123,6 +123,16 @@ public class Translator : UIElement
         {
             run.SetBinding(Run.TextProperty, binding);
         }
+        else if (d is Window window)
+        {
+            window.SetBinding(Window.TitleProperty, binding);
+        }
+        #if DEBUG
+        else if (d is DialogTitleBar)
+        {
+            throw new ArgumentException($"Use {nameof(DialogTitleBar)}.{nameof(DialogTitleBar.TitleKey)} to set the localization key for the title");
+        }
+        #endif
         else if (d is ContentControl contentControl)
         {
             contentControl.SetBinding(ContentControl.ContentProperty, binding);
@@ -135,6 +145,12 @@ public class Translator : UIElement
         {
             layoutContent.SetValue(LayoutContent.TitleProperty, localizedString.Value);
         }
+        #if DEBUG
+        else
+        {
+            throw new ArgumentException($"'{d.GetType().Name}' does not support {nameof(Translator)}.Key");
+        }
+        #endif
 
         d.SetValue(ValueProperty, localizedString.Value);
     }