Skip to content

Commit d5f9541

Browse files
authored
Merge pull request #239 from ionite34/more-localize
2 parents 9a71855 + dd69f2b commit d5f9541

27 files changed

+2714
-687
lines changed

StabilityMatrix.Avalonia/App.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ private void ShowMainWindow()
204204
};
205205
mainWindow.Closed += (_, _) => Shutdown();
206206

207+
mainWindow.SetDefaultFonts();
208+
207209
VisualRoot = mainWindow;
208210
StorageProvider = mainWindow.StorageProvider;
209211

StabilityMatrix.Avalonia/Assets.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal static class Assets
1616
public static AvaloniaResource AppIconPng { get; } =
1717
new("avares://StabilityMatrix.Avalonia/Assets/Icon.png");
1818

19+
public static AvaloniaResource RegionalFontJapanese { get; } =
20+
new("avares://StabilityMatrix.Avalonia/Assets/Fonts/NotoSansJP-Variable.ttf");
21+
1922
/// <summary>
2023
/// Fixed image for models with no images.
2124
/// </summary>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'
2+
3+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
4+
This license is copied below, and is also available with a FAQ at:
5+
http://scripts.sil.org/OFL
6+
7+
8+
-----------------------------------------------------------
9+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10+
-----------------------------------------------------------
11+
12+
PREAMBLE
13+
The goals of the Open Font License (OFL) are to stimulate worldwide
14+
development of collaborative font projects, to support the font creation
15+
efforts of academic and linguistic communities, and to provide a free and
16+
open framework in which fonts may be shared and improved in partnership
17+
with others.
18+
19+
The OFL allows the licensed fonts to be used, studied, modified and
20+
redistributed freely as long as they are not sold by themselves. The
21+
fonts, including any derivative works, can be bundled, embedded,
22+
redistributed and/or sold with any software provided that any reserved
23+
names are not used by derivative works. The fonts and derivatives,
24+
however, cannot be released under any other type of license. The
25+
requirement for fonts to remain under this license does not apply
26+
to any document created using the fonts or their derivatives.
27+
28+
DEFINITIONS
29+
"Font Software" refers to the set of files released by the Copyright
30+
Holder(s) under this license and clearly marked as such. This may
31+
include source files, build scripts and documentation.
32+
33+
"Reserved Font Name" refers to any names specified as such after the
34+
copyright statement(s).
35+
36+
"Original Version" refers to the collection of Font Software components as
37+
distributed by the Copyright Holder(s).
38+
39+
"Modified Version" refers to any derivative made by adding to, deleting,
40+
or substituting -- in part or in whole -- any of the components of the
41+
Original Version, by changing formats or by porting the Font Software to a
42+
new environment.
43+
44+
"Author" refers to any designer, engineer, programmer, technical
45+
writer or other person who contributed to the Font Software.
46+
47+
PERMISSION & CONDITIONS
48+
Permission is hereby granted, free of charge, to any person obtaining
49+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
50+
redistribute, and sell modified and unmodified copies of the Font
51+
Software, subject to the following conditions:
52+
53+
1) Neither the Font Software nor any of its individual components,
54+
in Original or Modified Versions, may be sold by itself.
55+
56+
2) Original or Modified Versions of the Font Software may be bundled,
57+
redistributed and/or sold with any software, provided that each copy
58+
contains the above copyright notice and this license. These can be
59+
included either as stand-alone text files, human-readable headers or
60+
in the appropriate machine-readable metadata fields within text or
61+
binary files as long as those fields can be easily viewed by the user.
62+
63+
3) No Modified Version of the Font Software may use the Reserved Font
64+
Name(s) unless explicit written permission is granted by the corresponding
65+
Copyright Holder. This restriction only applies to the primary font name as
66+
presented to the users.
67+
68+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69+
Software shall not be used to promote, endorse or advertise any
70+
Modified Version, except to acknowledge the contribution(s) of the
71+
Copyright Holder(s) and the Author(s) or with their explicit written
72+
permission.
73+
74+
5) The Font Software, modified or unmodified, in part or in whole,
75+
must be distributed entirely under this license, and must not be
76+
distributed under any other license. The requirement for fonts to
77+
remain under this license does not apply to any document created
78+
using the Font Software.
79+
80+
TERMINATION
81+
This license becomes null and void if any of the above conditions are
82+
not met.
83+
84+
DISCLAIMER
85+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93+
OTHER DEALINGS IN THE FONT SOFTWARE.
9.09 MB
Binary file not shown.

StabilityMatrix.Avalonia/DialogHelper.cs

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using FluentAvalonia.UI.Controls;
1414
using Markdown.Avalonia;
1515
using StabilityMatrix.Avalonia.Controls;
16+
using StabilityMatrix.Avalonia.Languages;
1617

1718
namespace StabilityMatrix.Avalonia;
1819

@@ -22,26 +23,24 @@ public static class DialogHelper
2223
/// Create a generic textbox entry content dialog.
2324
/// </summary>
2425
public static BetterContentDialog CreateTextEntryDialog(
25-
string title,
26-
string description,
27-
IReadOnlyList<TextBoxField> textFields)
26+
string title,
27+
string description,
28+
IReadOnlyList<TextBoxField> textFields
29+
)
2830
{
2931
Dispatcher.UIThread.VerifyAccess();
3032

3133
var stackPanel = new StackPanel();
3234
var grid = new Grid
3335
{
34-
RowDefinitions =
36+
RowDefinitions =
3537
{
3638
new RowDefinition(GridLength.Auto),
3739
new RowDefinition(GridLength.Star)
3840
},
3941
Children =
4042
{
41-
new TextBlock
42-
{
43-
Text = description
44-
},
43+
new TextBlock { Text = description },
4544
stackPanel
4645
}
4746
};
@@ -52,33 +51,32 @@ public static BetterContentDialog CreateTextEntryDialog(
5251
firstTextBox.Focus();
5352
firstTextBox.CaretIndex = firstTextBox.Text?.LastIndexOf('.') ?? 0;
5453
};
55-
54+
5655
// Disable primary button if any textboxes are invalid
57-
var primaryCommand = new RelayCommand(delegate { },
56+
var primaryCommand = new RelayCommand(
57+
delegate { },
5858
() =>
5959
{
6060
var invalidCount = textFields.Count(field => !field.IsValid);
6161
Debug.WriteLine($"Checking can execute: {invalidCount} invalid fields");
6262
return invalidCount == 0;
63-
});
64-
63+
}
64+
);
65+
6566
// Create textboxes
6667
foreach (var field in textFields)
6768
{
68-
var label = new TextBlock
69-
{
70-
Text = field.Label
71-
};
69+
var label = new TextBlock { Text = field.Label };
7270
stackPanel.Children.Add(label);
73-
71+
7472
var textBox = new TextBox
7573
{
7674
[!TextBox.TextProperty] = new Binding("TextProperty"),
7775
Watermark = field.Watermark,
7876
DataContext = field,
7977
};
8078
stackPanel.Children.Add(textBox);
81-
79+
8280
// When IsValid property changes, update invalid count and primary button
8381
field.PropertyChanged += (_, args) =>
8482
{
@@ -87,10 +85,10 @@ public static BetterContentDialog CreateTextEntryDialog(
8785
primaryCommand.NotifyCanExecuteChanged();
8886
}
8987
};
90-
88+
9189
// Set initial value
9290
textBox.Text = field.Text;
93-
91+
9492
// See if initial value is valid
9593
try
9694
{
@@ -101,13 +99,13 @@ public static BetterContentDialog CreateTextEntryDialog(
10199
field.IsValid = false;
102100
}
103101
}
104-
102+
105103
return new BetterContentDialog
106104
{
107105
Title = title,
108106
Content = grid,
109-
PrimaryButtonText = "OK",
110-
CloseButtonText = "Cancel",
107+
PrimaryButtonText = Resources.Action_OK,
108+
CloseButtonText = Resources.Action_Cancel,
111109
IsPrimaryButtonEnabled = true,
112110
PrimaryButtonCommand = primaryCommand,
113111
DefaultButton = ContentDialogButton.Primary
@@ -121,44 +119,37 @@ public static BetterContentDialog CreateMarkdownDialog(string markdown, string?
121119
{
122120
Dispatcher.UIThread.VerifyAccess();
123121

124-
var viewer = new MarkdownScrollViewer
125-
{
126-
Markdown = markdown
127-
};
128-
122+
var viewer = new MarkdownScrollViewer { Markdown = markdown };
123+
129124
return new BetterContentDialog
130125
{
131126
Title = title,
132127
Content = viewer,
133-
CloseButtonText = "Close",
128+
CloseButtonText = Resources.Action_Close,
134129
IsPrimaryButtonEnabled = false,
135130
};
136131
}
137-
132+
138133
/// <summary>
139134
/// Create a simple title and description task dialog.
140135
/// Sets the XamlRoot to the current top level window.
141136
/// </summary>
142137
public static TaskDialog CreateTaskDialog(string title, string description)
143138
{
144139
Dispatcher.UIThread.VerifyAccess();
145-
140+
146141
var content = new StackPanel
147142
{
148143
Children =
149144
{
150145
new TextBlock
151146
{
152-
Margin = new Thickness(0,0,0,8),
147+
Margin = new Thickness(0, 0, 0, 8),
153148
FontSize = 16,
154149
Text = title,
155150
TextWrapping = TextWrapping.WrapWithOverflow,
156151
},
157-
new TextBlock
158-
{
159-
Text = description,
160-
TextWrapping = TextWrapping.WrapWithOverflow,
161-
}
152+
new TextBlock { Text = description, TextWrapping = TextWrapping.WrapWithOverflow, }
162153
}
163154
};
164155

@@ -176,16 +167,18 @@ public sealed class TextBoxField : INotifyPropertyChanged
176167
{
177168
// Label above the textbox
178169
public string Label { get; init; } = string.Empty;
170+
179171
// Actual text value
180172
public string Text { get; set; } = string.Empty;
173+
181174
// Watermark text
182175
public string Watermark { get; init; } = string.Empty;
183-
176+
184177
/// <summary>
185178
/// Validation action on text changes. Throw exception if invalid.
186179
/// </summary>
187180
public Action<string>? Validator { get; init; }
188-
181+
189182
public string TextProperty
190183
{
191184
get => Text;
@@ -206,7 +199,7 @@ public string TextProperty
206199
OnPropertyChanged();
207200
}
208201
}
209-
202+
210203
// Default to true if no validator is provided
211204
private bool isValid;
212205
public bool IsValid

0 commit comments

Comments
 (0)