Ver código fonte

Palette browser localization wip

Krzysztof Krysiński 2 anos atrás
pai
commit
8cee1c7648

+ 26 - 0
src/PixiEditor/Data/Localization/Languages/en.json

@@ -427,6 +427,32 @@
 
   "RESTART": "Restart",
 
+  "SORT_BY": "Sort by",
+  "NAME": "Name",
+  "COLORS": "Colors",
+  "DEFAULT": "Default",
+  "ALPHABETICAL": "Alphabetical",
+  "COLOR_COUNT": "Color count",
+
+  "ANY": "Any",
+  "MAX": "Max",
+  "MIN": "Min",
+  "EXACT": "Exact",
+
+  "ASCENDING": "Ascending",
+  "DESCENDING": "Descending",
+
+  "FAVORITES": "Favorites",
+  "ADD_FROM_CURRENT_PALETTE": "Add from current palette",
+  "OPEN_PALETTES_DIR_TOOLTIP": "Open palettes directory in explorer",
+  "BROWSE_ON_LOSPEC_TOOLTIP": "Browse palettes on Lospec",
+  "IMPORT_FROM_FILE_TOOLTIP": "Import from file",
+
+  "COULD_NOT_LOAD_PALETTE": "Couldn't fetch palettes",
+  "NO_PALETTES_FOUND": "No palettes found.",
+  "LOSPEC_LINK_TEXT": "I heard you can find some here: lospec.com/palette-list",
+  "PALETTE_BROWSER": "Palette Browser",
+
   "ERROR": "Error",
   "INTERNAL_ERROR": "Internal error",
   "ERROR_SAVE_LOCATION": "Couldn't save the file to the specified location",

+ 21 - 21
src/PixiEditor/Views/Dialogs/PalettesBrowser.xaml

@@ -14,7 +14,6 @@
     xmlns:dialogs="clr-namespace:PixiEditor.Views.Dialogs"
     x:Class="PixiEditor.Views.Dialogs.PalettesBrowser"
     mc:Ignorable="d"
-    Title="Palettes Browser" 
     WindowStartupLocation="CenterScreen" 
     MinWidth="200" 
     Height="600" Width="850" 
@@ -40,15 +39,15 @@
             <RowDefinition Height="1*"/>
         </Grid.RowDefinitions>
 
-        <dialogs:DialogTitleBar TitleText="Palette Browser" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"/>
+        <dialogs:DialogTitleBar TitleText="PALETTE_BROWSER" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"/>
 
         <DockPanel Background="{StaticResource MainColor}" Grid.Row="1">
             <StackPanel HorizontalAlignment="Left" Margin="10" Orientation="Horizontal" VerticalAlignment="Center">
-                <Label Content="Sort by:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center"/>
+                <Label views:Translator.Key="SORT_BY" Style="{StaticResource BaseLabel}" VerticalAlignment="Center"/>
                 <ComboBox x:Name="sortingComboBox" VerticalAlignment="Center" SelectionChanged="SortingComboBox_SelectionChanged">
-                    <ComboBoxItem IsSelected="True" Content="Default"/>
-                    <ComboBoxItem Content="Alphabetical"/>
-                    <ComboBoxItem Content="Color Count"/>
+                    <ComboBoxItem IsSelected="True" views:Translator.Key="DEFAULT"/>
+                    <ComboBoxItem views:Translator.Key="ALPHABETICAL"/>
+                    <ComboBoxItem views:Translator.Key="COLOR_COUNT"/>
                 </ComboBox>
                 <ToggleButton Margin="10 0 0 0" x:Name="toggleBtn"
                               IsChecked="{Binding SortAscending, ElementName=palettesBrowser}"
@@ -74,40 +73,40 @@
                         </Image.Style>
                     </Image>
                 </ToggleButton>
-                <Label Margin="10 0 0 0" Content="Name:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center"/>
+                <Label Margin="10 0 0 0" views:Translator.Key="NAME" Style="{StaticResource BaseLabel}" VerticalAlignment="Center"/>
                 <usercontrols:InputBox
                                        Text="{Binding NameFilter, Delay=100, ElementName=palettesBrowser, UpdateSourceTrigger=PropertyChanged}"
                                        VerticalAlignment="Center"
                                        Style="{StaticResource DarkTextBoxStyle}" Width="150" />
 
-                <Label Margin="10 0 0 0" Content="Colors:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center"/>
+                <Label Margin="10 0 0 0" views:Translator.Key="COLORS" Style="{StaticResource BaseLabel}" VerticalAlignment="Center"/>
                 <ComboBox x:Name="colorsComboBox" VerticalAlignment="Center" SelectionChanged="ColorsComboBox_SelectionChanged">
-                    <ComboBoxItem IsSelected="True" Content="Any"/>
-                    <ComboBoxItem Content="Max"/>
-                    <ComboBoxItem Content="Min"/>
-                    <ComboBoxItem Content="Exact"/>
+                    <ComboBoxItem IsSelected="True" views:Translator.Key="ANY"/>
+                    <ComboBoxItem views:Translator.Key="MAX"/>
+                    <ComboBoxItem views:Translator.Key="MIN"/>
+                    <ComboBoxItem views:Translator.Key="EXACT"/>
                 </ComboBox>
                 <usercontrols:NumberInput Width="50" VerticalAlignment="Center" Margin="10 0 0 0"
                                    FocusNext="True"
                                    Value="{Binding ColorsNumber, ElementName=palettesBrowser, Mode=TwoWay}"/>
                 <CheckBox Margin="10 0 0 0" VerticalAlignment="Center"
-                          IsChecked="{Binding ShowOnlyFavourites, ElementName=palettesBrowser}" Content="Favorites"/>
+                          IsChecked="{Binding ShowOnlyFavourites, ElementName=palettesBrowser}" views:Translator.Key="FAVORITES"/>
             </StackPanel>
             <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0 0 10 0">
-                <Button ToolTip="Add from current palette" Click="AddFromPalette_OnClick" Cursor="Hand" Margin="10 0" Style="{StaticResource ImageButtonStyle}" Width="24" Height="24">
+                <Button views:Translator.TooltipKey="ADD_FROM_CURRENT_PALETTE" Click="AddFromPalette_OnClick" Cursor="Hand" Margin="10 0" Style="{StaticResource ImageButtonStyle}" Width="24" Height="24">
                     <Image Source="/Images/Plus-square.png"/>
                 </Button>
                 <Button Cursor="Hand" Click="OpenFolder_OnClick" Style="{StaticResource ImageButtonStyle}" Width="24" Height="24"
-                        ToolTip="Open palettes directory in explorer">
+                        views:Translator.TooltipKey="OPEN_PALETTES_DIR_TOOLTIP">
                     <Image Source="/Images/Folder.png"/>
                 </Button>
-                <Button HorizontalAlignment="Right" Margin="10 0 0 0" ToolTip="Browse palettes on Lospec"
+                <Button HorizontalAlignment="Right" Margin="10 0 0 0" views:Translator.TooltipKey="BROWSE_ON_LOSPEC_TOOLTIP"
                         Style="{StaticResource ImageButtonStyle}" Width="24" Height="24"
                         Click="BrowseOnLospec_OnClick"
                         CommandParameter="https://lospec.com/palette-list">
                     <Image Source="/Images/Globe.png"/>
                 </Button>
-                <Button HorizontalAlignment="Right" Margin="10 0 0 0" ToolTip="Import from file"
+                <Button HorizontalAlignment="Right" Margin="10 0 0 0" views:Translator.TooltipKey="IMPORT_FROM_FILE_TOOLTIP"
                         Style="{StaticResource ImageButtonStyle}" Width="24" Height="24"
                         Click="ImportFromFile_OnClick">
                     <Image Source="/Images/hard-drive.png"/>
@@ -115,13 +114,14 @@
             </StackPanel>
         </DockPanel>
         <Grid Grid.Row="2" Margin="10">
-            <TextBlock Text="Couldn't fetch palettes" Foreground="White" FontSize="20" HorizontalAlignment="Center" 
+            <TextBlock views:Translator.Key="COULD_NOT_LOAD_PALETTE" Foreground="White" FontSize="20" HorizontalAlignment="Center"
                        VerticalAlignment="Center" Visibility="{Binding Visibility, Converter={converters:OppositeVisibilityConverter}, ElementName=itemsControl}"/>
             <StackPanel Panel.ZIndex="10" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding ElementName=palettesBrowser, Path=SortedResults.Count, Converter={converters:CountToVisibilityConverter}}">
-                <TextBlock Text="No palettes found." Foreground="White" FontSize="20" TextAlignment="Center"/>
+                <TextBlock views:Translator.Key="NO_PALETTES_FOUND" Foreground="White" FontSize="20" TextAlignment="Center"/>
                 <TextBlock Margin="0 10 0 0">
-                    <Hyperlink Foreground="Gray" Cursor="Hand" FontSize="18" NavigateUri="https://lospec.com/palette-list" RequestNavigate="Hyperlink_OnRequestNavigate">
-                        I heard you can find some here: lospec.com/palette-list
+                    <Hyperlink Foreground="Gray" Cursor="Hand" FontSize="18" NavigateUri="https://lospec.com/palette-list"
+                               RequestNavigate="Hyperlink_OnRequestNavigate">
+                        <TextBlock views:Translator.Key="LOSPEC_LINK_TEXT"/>
                     </Hyperlink>
                 </TextBlock>
                 <Image Width="128" Height="128" Source="/Images/Search.png"/>

+ 13 - 8
src/PixiEditor/Views/Dialogs/PalettesBrowser.xaml.cs

@@ -7,6 +7,7 @@ using System.Windows.Navigation;
 using Microsoft.Win32;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.Helpers;
+using PixiEditor.Localization;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders.Palettes;
 using PixiEditor.Models.DataProviders;
@@ -124,7 +125,7 @@ internal partial class PalettesBrowser : Window
 
     public RelayCommand<Palette> ToggleFavouriteCommand { get; set; }
 
-    public string SortingType { get; set; } = "Default";
+    public int SortingIndex { get; set; } = 0;
     public ColorsNumberMode ColorsNumberMode { get; set; } = ColorsNumberMode.Any;
 
     private FilteringSettings filteringSettings;
@@ -134,7 +135,7 @@ internal partial class PalettesBrowser : Window
 
     private char[] separators = new char[] { ' ', ',' };
 
-    private SortingType InternalSortingType => (SortingType)Enum.Parse(typeof(SortingType), SortingType.Replace(" ", ""));
+    private SortingType InternalSortingType => (SortingType)SortingIndex;
     public WpfObservableRangeCollection<Color> CurrentEditingPalette { get; set; }
     public static PalettesBrowser Instance { get; internal set; }
 
@@ -151,6 +152,7 @@ internal partial class PalettesBrowser : Window
     public PalettesBrowser()
     {
         InitializeComponent();
+        Title = new LocalizedString("PALETTE_BROWSER");
         Instance = this;
         DeletePaletteCommand = new RelayCommand<Palette>(DeletePalette);
         ToggleFavouriteCommand = new RelayCommand<Palette>(ToggleFavourite, CanToggleFavourite);
@@ -388,22 +390,25 @@ internal partial class PalettesBrowser : Window
 
     private void SortingComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
     {
-        if (e.AddedItems is { Count: > 0 } && e.AddedItems[0] is ComboBoxItem { Content: string value })
+        if (e.AddedItems is { Count: > 0 } && e.AddedItems[0] is ComboBoxItem)
         {
-            SortingType = value;
+            var comboBox = (ComboBox)sender;
+            SortingIndex = comboBox.SelectedIndex;
             Sort();
-            scrollViewer.ScrollToHome();
+            scrollViewer?.ScrollToHome();
         }
     }
 
     private async void ColorsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
     {
-        if (e.AddedItems is { Count: > 0 } && e.AddedItems[0] is ComboBoxItem { Content: string value })
+        if (e.AddedItems is { Count: > 0 } && e.AddedItems[0] is ComboBoxItem)
         {
-            ColorsNumberMode = Enum.Parse<ColorsNumberMode>(value);
+            var comboBox = (ComboBox)sender;
+            ColorsNumberMode = (ColorsNumberMode)comboBox.SelectedIndex;
             Filtering.ColorsNumberMode = ColorsNumberMode;
             await UpdatePaletteList();
-            scrollViewer.ScrollToHome();
+
+            scrollViewer?.ScrollToHome();
         }
     }
 

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

@@ -4,6 +4,7 @@ using System.Windows.Data;
 using System.Windows.Documents;
 using AvalonDock.Layout;
 using PixiEditor.Localization;
+using PixiEditor.Views.Dialogs;
 
 namespace PixiEditor.Views;