Skip to content

Commit

Permalink
Translate the startup language select page (#336)
Browse files Browse the repository at this point in the history
* Translate the startup language select page

* Revert to u2006 for existing keys

* Other changes

* Cleanup usings
  • Loading branch information
shatyuka authored Dec 17, 2023
1 parent 12fe2f0 commit a4cd1ca
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 30 deletions.
17 changes: 15 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public void InitializeWindowSettings()
var incps = InputNonClientPointerSource.GetForWindowId(m_windowID);
incps.SetRegionRects(NonClientRegionKind.Close, null);
incps.SetRegionRects(NonClientRegionKind.Minimize, null);
var safeArea = new RectInt32[] { new(m_appWindow.Size.Width - (int)((144 + 12) * m_appDPIScale), 0, (int)((144 + 12) * m_appDPIScale), (int)(48 * m_appDPIScale)) };
incps.SetRegionRects(NonClientRegionKind.Passthrough, safeArea);
EnableNonClientArea();
}
else
{
Expand All @@ -173,6 +172,20 @@ public void InitializeWindowSettings()
m_oldWndProc = SetWindowLongPtr(m_windowHandle, GWLP_WNDPROC, pWndProc);
}

public void EnableNonClientArea()
{
var incps = InputNonClientPointerSource.GetForWindowId(m_windowID);
var safeArea = new RectInt32[] { new(m_appWindow.Size.Width - (int)((144 + 12) * m_appDPIScale), 0, (int)((144 + 12) * m_appDPIScale), (int)(48 * m_appDPIScale)) };
incps.SetRegionRects(NonClientRegionKind.Passthrough, safeArea);
}

public void DisableNonClientArea()
{
var incps = InputNonClientPointerSource.GetForWindowId(m_windowID);
var safeArea = new RectInt32[] { new(0, 0, m_appWindow.Size.Width, (int)(48 * m_appDPIScale)) };
incps.SetRegionRects(NonClientRegionKind.Passthrough, safeArea);
}

private delegate IntPtr WndProcDelegate(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr lParam);

private IntPtr WndProc(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr lParam)
Expand Down
49 changes: 27 additions & 22 deletions CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,36 @@
<StackPanel x:Name="MenuPanel" CornerRadius="16"
Margin="0,32,64,32" Padding="32" Shadow="{ThemeResource SharedShadow}" Background="{ThemeResource DialogAcrylicBrush}">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock Text="Select your language"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectLang}"
TextAlignment="Left"
HorizontalAlignment="Left" Margin="0,0,0,8"
TextWrapping="Wrap" Style="{ThemeResource BodyStrongTextBlockStyle}" FontSize="18"/>
<TextBlock Text="Please select your language to start this launcher for the first time!"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectLangDesc}"
TextAlignment="Left"
HorizontalAlignment="Left"
TextWrapping="Wrap"/>
<ComboBox PlaceholderText="Select your language"
<ComboBox Name="SelectLang" SelectedIndex="{x:Bind SelectedLangIndex, Mode=TwoWay}"
Margin="0,16"
HorizontalAlignment="Left" VerticalAlignment="Center"
SelectionChanged="ComboBox_SelectionChanged" ItemsSource="{x:Bind LangList, Mode=OneTime}"/>
ItemsSource="{x:Bind LangList}"
MaxDropDownHeight="1000"
DropDownOpened="SelectLang_OnDropDownOpened"
DropDownClosed="SelectLang_OnDropDownClosed"/>
</StackPanel>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock Text="Select your preferred window size"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectWindowSize}"
TextAlignment="Left"
HorizontalAlignment="Left"
TextWrapping="Wrap" Style="{ThemeResource BodyStrongTextBlockStyle}" FontSize="18"/>
<ComboBox SelectedIndex="{x:Bind SelectedWindowSizeProfile, Mode=TwoWay}"
Margin="0,16">
<ComboBoxItem Content="Normal"/>
<ComboBoxItem Content="Small"/>
<ComboBox SelectedIndex="{x:Bind SelectedWindowSizeProfile, Mode=TwoWay}"
Margin="0,16" Name="SelectWindowSize">
<ComboBoxItem Content="{x:Bind helper:Locale.Lang._SettingsPage.AppWindowSize_Normal}"/>
<ComboBoxItem Content="{x:Bind helper:Locale.Lang._SettingsPage.AppWindowSize_Small}"/>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Select your preferred CDN"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectCDN}"
TextAlignment="Left"
HorizontalAlignment="Left"
TextWrapping="Wrap" Style="{ThemeResource BodyStrongTextBlockStyle}" FontSize="18"/>
Expand All @@ -61,18 +64,20 @@
</Button.Content>
<Button.Flyout>
<Flyout>
<StackPanel>
<StackPanel MaxWidth="380">
<TextBlock>
<Run Text="What is a CDN?" FontWeight="Bold" FontSize="20"/>
<Run Text="short for" FontSize="12"/>
<Run Text="Content Delivery Network" FontWeight="Bold" FontSize="12"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_1}" FontWeight="Bold" FontSize="20"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_2}" FontSize="12"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_3}" FontWeight="Bold" FontSize="12"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_4}" FontSize="12"/>
</TextBlock>
<TextBlock TextWrapping="Wrap" MaxWidth="380" Margin="0,8,0,0">
<Run Text="CDN" FontWeight="Bold"/>
<Run Text="is a system used to make launcher files available to a larger audience, quickly and efficiently." TextDecorations="None"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_1}"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_2}" FontWeight="Bold"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_3}"/>
</TextBlock>
<TextBlock Text="Collapse selects GitHub as the default provider."/>
<TextBlock Text="CDNs available:" FontWeight="Bold" FontSize="20" Margin="0,12,0,0"/>
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_4}"/>
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.CDNsAvailable}" FontWeight="Bold" FontSize="20" Margin="0,12,0,0"/>
<ItemsControl ItemsSource="{x:Bind innerConfig:LauncherConfig.CDNList}" MaxWidth="380" Margin="0,0,0,-8">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="innerConfig:CDNURLProperty">
Expand All @@ -88,7 +93,7 @@
</Button.Flyout>
</Button>
</StackPanel>
<RadioButtons SelectedIndex="{x:Bind SelectedCDN, Mode=TwoWay}" ItemsSource="{x:Bind innerConfig:LauncherConfig.CDNList}" MaxColumns="3">
<RadioButtons Name="SelectCDN" SelectedIndex="{x:Bind SelectedCDN, Mode=TwoWay}" ItemsSource="{x:Bind innerConfig:LauncherConfig.CDNList}" MaxColumns="3">
<RadioButtons.ItemTemplate>
<DataTemplate x:DataType="innerConfig:CDNURLProperty">
<RadioButton>
Expand All @@ -100,14 +105,14 @@
</RadioButtons.ItemTemplate>
</RadioButtons>
</StackPanel>
<Button x:Name="NextBtn" Content="Next" HorizontalAlignment="Left" IsEnabled="False" Width="128" Margin="0,16,0,0"
<Button x:Name="NextBtn" Content="{x:Bind helper:Locale.Lang._Misc.Next}" HorizontalAlignment="Left" Width="128" Margin="0,16,0,0"
VerticalAlignment="Bottom" Style="{ThemeResource AccentButtonStyle}" Click="NextBtn_Click"/>
</StackPanel>
</StackPanel>
<TextBlock Grid.Column="1" Margin="8" VerticalAlignment="Bottom" TextAlignment="Right"
HorizontalAlignment="Right" Opacity="0.50" Foreground="{ThemeResource DefaultFGColorAccentBrush}">
<Run Text="The splash art is a property of"/><LineBreak/>
<Run Text="miHoYo / HoYoverse" FontSize="18" FontWeight="Medium"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.SplashArt_1}"/><LineBreak/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.SplashArt_2}" FontSize="18" FontWeight="Medium"/>
</TextBlock>
</Grid>
</Page>
81 changes: 75 additions & 6 deletions CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using static CollapseLauncher.InnerLauncherConfig;
using static CollapseLauncher.WindowSize.WindowSize;
Expand Down Expand Up @@ -31,12 +32,79 @@ public StartupLanguageSelect()
}
}

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
private static Dictionary<string, string> LangFallbackDict = new()
{
string LangID = LanguageIDIndex[(sender as ComboBox).SelectedIndex];
SetAppConfigValue("AppLanguage", LangID);
LoadLocale(LangID);
NextBtn.IsEnabled = true;
{ "en", "en-us" },
{ "zh", "zh-cn" },
{ "de", "de-de" },
{ "es", "es-419" },
{ "id", "id-id" },
{ "ja", "ja-jp" },
{ "ko", "ko-kr" },
{ "pl", "pl-pl" },
{ "pt", "pt-br" },
{ "ru", "ru-ru" },
{ "th", "th-th" },
{ "vi", "vi-vn" },
};

private string LanguageFallback(string tag)
{
tag = tag.ToLower();
// Traditional Chinese
if (tag == "zh-hant" || tag == "zh-hk" || tag == "zh-mo" || tag == "zh-tw") return "zh-tw";
// Portuguese, Portugal
if (tag == "pt-pt") return "pt-pt";
if (tag.Length < 2) return "en-us";
tag = tag.Substring(0, 2);
return LangFallbackDict.GetValueOrDefault(tag, "en-us");
}

private void RefreshSelection()
{
SelectLang.SelectedIndex = -1;
SelectLang.SelectedIndex = SelectedLangIndex;
SelectWindowSize.SelectedIndex = -1;
SelectWindowSize.SelectedIndex = SelectedWindowSizeProfile;
SelectCDN.UpdateLayout();
SelectCDN.SelectedIndex = SelectedCDN;
}

private int SelectedLangIndex
{
get
{
var langID = GetAppConfigValue("AppLanguage").ToString() ?? LanguageFallback(CultureInfo.InstalledUICulture.Name);
return LanguageNames[langID.ToLower()].LangIndex;
}
set
{
if (value < 0) return;
var langID = LanguageIDIndex[value].ToLower();
if (langID == GetAppConfigValue("AppLanguage").ToString().ToLower()) return;
SetAppConfigValue("AppLanguage", langID);
LoadLocale(langID);

// Update the view
LogWriteLine("Updating the view...");
Bindings.Update();
LogWriteLine("Update bindings done.");
RefreshSelection();
LogWriteLine("Refresh controls done.");
}
}

private void SelectLang_OnDropDownOpened(object sender, object e)
{
// The dropdown panel collides with non-client area, making the first item not clickable.
// Use this to disable whole non-client area temporarily.
(m_window as MainWindow).DisableNonClientArea();
}

private void SelectLang_OnDropDownClosed(object sender, object e)
{
// And restore the nc area to normal state.
(m_window as MainWindow).EnableNonClientArea();
}

private IEnumerable<string> LangList
Expand All @@ -55,6 +123,7 @@ private int SelectedWindowSizeProfile
}
set
{
if (value < 0) return;
CurrentWindowSizeName = WindowSizeProfilesKey[value];
}
}
Expand All @@ -69,4 +138,4 @@ private int SelectedCDN
}
}
}
}
}
15 changes: 15 additions & 0 deletions Hi3Helper.Core/Lang/Locale/LangStartupPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ public sealed partial class LocalizationParams
public LangStartupPage _StartupPage { get; set; } = LangFallback?._StartupPage;
public sealed class LangStartupPage
{
public string SelectLang { get; set; } = LangFallback?._StartupPage.SelectLang;
public string SelectLangDesc { get; set; } = LangFallback?._StartupPage.SelectLangDesc;
public string SelectWindowSize { get; set; } = LangFallback?._StartupPage.SelectWindowSize;
public string SelectCDN { get; set; } = LangFallback?._StartupPage.SelectCDN;
public string CDNHelpTitle_1 { get; set; } = LangFallback?._StartupPage.CDNHelpTitle_1;
public string CDNHelpTitle_2 { get; set; } = LangFallback?._StartupPage.CDNHelpTitle_2;
public string CDNHelpTitle_3 { get; set; } = LangFallback?._StartupPage.CDNHelpTitle_3;
public string CDNHelpTitle_4 { get; set; } = LangFallback?._StartupPage.CDNHelpTitle_4;
public string CDNHelpDetail_1 { get; set; } = LangFallback?._StartupPage.CDNHelpDetail_1;
public string CDNHelpDetail_2 { get; set; } = LangFallback?._StartupPage.CDNHelpDetail_2;
public string CDNHelpDetail_3 { get; set; } = LangFallback?._StartupPage.CDNHelpDetail_3;
public string CDNHelpDetail_4 { get; set; } = LangFallback?._StartupPage.CDNHelpDetail_4;
public string CDNsAvailable { get; set; } = LangFallback?._StartupPage.CDNsAvailable;
public string SplashArt_1 { get; set; } = LangFallback?._StartupPage.SplashArt_1;
public string SplashArt_2 { get; set; } = LangFallback?._StartupPage.SplashArt_2;
public string PageTitle { get; set; } = LangFallback?._StartupPage.PageTitle;
public string Title1 { get; set; } = LangFallback?._StartupPage.Title1;
public string Title2 { get; set; } = LangFallback?._StartupPage.Title2;
Expand Down
15 changes: 15 additions & 0 deletions Hi3Helper.Core/Lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
"Author": "neon-nyan, CryoTechnic",

"_StartupPage": {
"SelectLang": "Select your language",
"SelectLangDesc": "Please select your language to start this launcher for the first time!",
"SelectWindowSize": "Select your preferred window size",
"SelectCDN": "Select your preferred CDN",
"CDNHelpTitle_1": "What is a CDN?",
"CDNHelpTitle_2": "short for ",
"CDNHelpTitle_3": "Content Delivery Network",
"CDNHelpTitle_4": "\u200b",
"CDNHelpDetail_1": "\u200b",
"CDNHelpDetail_2": "CDN",
"CDNHelpDetail_3": " is a system used to make launcher files available to a larger audience, quickly and efficiently.",
"CDNHelpDetail_4": "Collapse selects GitHub as the default provider.",
"CDNsAvailable": "CDNs available:",
"SplashArt_1": "The splash art is a property of",
"SplashArt_2": "miHoYo / HoYoverse",
"ChooseFolderBtn": "Locate folder",
"ChooseFolderDialogCancel": "Cancel",
"ChooseFolderDialogPrimary": "Yes please!",
Expand Down
15 changes: 15 additions & 0 deletions Hi3Helper.Core/Lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
"Author": "misaka10843, imgradeone, SatoSouta",

"_StartupPage": {
"SelectLang": "选择您的语言",
"SelectLangDesc": "首次启动本启动器时,请选择您的语言!",
"SelectWindowSize": "选择您偏好的窗口尺寸",
"SelectCDN": "选择您偏好的 CDN",
"CDNHelpTitle_1": "什么是 CDN?",
"CDNHelpTitle_2": "",
"CDNHelpTitle_3": "内容分发网络",
"CDNHelpTitle_4": "的缩写",
"CDNHelpDetail_1": "",
"CDNHelpDetail_2": "CDN",
"CDNHelpDetail_3": " 是一种用于快速、高效地向更多受众提供启动器文件的系统。",
"CDNHelpDetail_4": "Collapse 选择 GitHub 作为默认提供商。",
"CDNsAvailable": "可用的 CDN:",
"SplashArt_1": "启动画面版权归属于",
"SplashArt_2": "miHoYo / HoYoverse",
"ChooseFolderBtn": "选择文件夹",
"ChooseFolderDialogCancel": "不想选",
"ChooseFolderDialogPrimary": "是的!",
Expand Down

0 comments on commit a4cd1ca

Please sign in to comment.