Skip to content

Commit 8e0bd62

Browse files
Merge pull request #442 from NeoCoderMatrix86/440-change-language-not-working-on-linux
Change language not working on linux
2 parents 73b81a4 + 94964a9 commit 8e0bd62

67 files changed

Lines changed: 114 additions & 33 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build & Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- development
7+
- master
8+
workflow_dispatch:
9+
10+
jobs:
11+
run-tests:
12+
uses: ./.github/workflows/run_tests.yml
13+
build:
14+
needs: run-tests
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
# version can be found here https://dotnet.microsoft.com/en-us/download/dotnet/9.0
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: 9.0.x
25+
26+
- name: Install wasm-tools
27+
run: dotnet workload install wasm-tools
28+
29+
- name: Build release
30+
run: dotnet publish AudioCuesheetEditor --configuration Release --output release
31+
32+
- name: Upload Build Artifact
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: AudioCuesheetEditor-Release
36+
path: ./release
37+
38+
deploy:
39+
needs: build
40+
runs-on: ubuntu-latest
41+
environment: |-
42+
${{
43+
github.ref_name == 'master' && 'Production'
44+
|| 'Preview'
45+
}}
46+
steps:
47+
- name: Download Build Artifact
48+
uses: actions/download-artifact@v4
49+
with:
50+
name: AudioCuesheetEditor-Release
51+
- name: Deploy to Netlify
52+
uses: nwtgck/actions-netlify@v3
53+
with:
54+
publish-dir: './wwwroot'
55+
production-deploy: true
56+
fails-without-credentials: true
57+
env:
58+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
59+
NETLIFY_SITE_ID: ${{ vars.NETLIFY_SITE_ID }}

.github/workflows/run_tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
name: Run tests
1+
name: Run Tests
22

33
on:
4+
workflow_call:
45
pull_request:
56

67
jobs:

AudioCuesheetEditor.End2EndTests/Pages/AboutTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace AudioCuesheetEditor.End2EndTests.Pages
77
public class AboutTest : PageTest
88
{
99
[TestInitialize]
10-
public async Task TestInitialize()
10+
public async Task TestInitializeAsync()
1111
{
1212
await Context.Tracing.StartAsync(new()
1313
{
@@ -19,7 +19,7 @@ await Context.Tracing.StartAsync(new()
1919
}
2020

2121
[TestCleanup]
22-
public async Task TestCleanup()
22+
public async Task TestCleanupAsync()
2323
{
2424
var failed = new[] { UnitTestOutcome.Failed, UnitTestOutcome.Error, UnitTestOutcome.Timeout, UnitTestOutcome.Aborted }.Contains(TestContext.CurrentTestOutcome);
2525

@@ -34,7 +34,7 @@ await Context.Tracing.StopAsync(new()
3434
}
3535

3636
[TestMethod]
37-
public async Task HasTitle()
37+
public async Task HasTitleAsync()
3838
{
3939
await Page.GotoAsync("http://localhost:5132/about");
4040
await Expect(Page).ToHaveTitleAsync("AudioCuesheetEditor");

AudioCuesheetEditor.End2EndTests/Pages/IndexTest.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace AudioCuesheetEditor.End2EndTests.Pages
88
public class IndexTest : PageTest
99
{
1010
[TestInitialize]
11-
public async Task TestInitialize()
11+
public async Task TestInitializeAsync()
1212
{
1313
await Context.Tracing.StartAsync(new()
1414
{
@@ -20,7 +20,7 @@ await Context.Tracing.StartAsync(new()
2020
}
2121

2222
[TestCleanup]
23-
public async Task TestCleanup()
23+
public async Task TestCleanupAsync()
2424
{
2525
var failed = new[] { UnitTestOutcome.Failed, UnitTestOutcome.Error, UnitTestOutcome.Timeout, UnitTestOutcome.Aborted }.Contains(TestContext.CurrentTestOutcome);
2626

@@ -35,15 +35,15 @@ await Context.Tracing.StopAsync(new()
3535
}
3636

3737
[TestMethod]
38-
public async Task HasTitle()
38+
public async Task HasTitleAsync()
3939
{
4040
await Page.GotoAsync("http://localhost:5132/");
4141
await Expect(Page).ToHaveTitleAsync("AudioCuesheetEditor");
4242
await Expect(Page.GetByRole(AriaRole.Button, new() { Name = "AudioCuesheetEditor" })).ToBeVisibleAsync();
4343
}
4444

4545
[TestMethod]
46-
public async Task CheckSettings()
46+
public async Task CheckSettingsAsync()
4747
{
4848
await Page.GotoAsync("http://localhost:5132/");
4949
await Page.GetByRole(AriaRole.Toolbar).GetByRole(AriaRole.Button).Filter(new() { HasTextRegex = new Regex("^$") }).Nth(3).ClickAsync();
@@ -52,7 +52,7 @@ public async Task CheckSettings()
5252
}
5353

5454
[TestMethod]
55-
public async Task Record()
55+
public async Task RecordAsync()
5656
{
5757
await Page.GotoAsync("http://localhost:5132/");
5858
await Page.GetByText("Record view").ClickAsync();
@@ -76,7 +76,7 @@ public async Task Record()
7676
}
7777

7878
[TestMethod]
79-
public async Task Import()
79+
public async Task ImportAsync()
8080
{
8181
await Page.GotoAsync("http://localhost:5132/");
8282
await Page.GetByText("Import view").ClickAsync();
@@ -88,5 +88,18 @@ public async Task Import()
8888
await Page.GetByRole(AriaRole.Textbox, new() { Name = "Cuesheet title" }).ClickAsync();
8989
await Expect(Page.GetByRole(AriaRole.Group).Filter(new() { HasText = "AudiofileAudiofile Search" }).Locator("input[type=\"file\"]")).ToBeEmptyAsync();
9090
}
91+
92+
[TestMethod]
93+
public async Task ChangeLanguageAsync()
94+
{
95+
await Page.GotoAsync("http://localhost:5132/");
96+
await Page.GetByRole(AriaRole.Button, new() { Name = "Change language" }).ClickAsync();
97+
await Page.GetByText("German (Germany)").ClickAsync();
98+
await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Abschnitte" })).ToBeVisibleAsync();
99+
await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Allgemeine Informationen" })).ToBeVisibleAsync();
100+
await Expect(Page.GetByText("Aufnahmeansicht")).ToBeVisibleAsync();
101+
await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Titel" })).ToBeVisibleAsync();
102+
await Expect(Page.GetByRole(AriaRole.Heading, new() { Name = "Wiedergabe" })).ToBeVisibleAsync();
103+
}
91104
}
92105
}

AudioCuesheetEditor/Program.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
using Microsoft.AspNetCore.Components.Web;
2727
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
2828
using MudBlazor.Services;
29+
using System.Globalization;
30+
using System.Reflection;
2931
using Toolbelt.Blazor.Extensions.DependencyInjection;
3032

3133
var builder = WebAssemblyHostBuilder.CreateDefault(args);
@@ -64,6 +66,27 @@
6466

6567
builder.Services.AddHotKeys2();
6668

69+
// TODO: Remove this when https://github.com/dotnet/aspnetcore/issues/56824 is fixed
70+
71+
// Get current localization culture
72+
var currentCulture = CultureInfo.DefaultThreadCurrentCulture;
73+
74+
// Get WASM culture provider via reflection
75+
var type = Assembly.GetAssembly(typeof(WebAssemblyHost))!.GetType("Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyCultureProvider");
76+
var instance = type
77+
!.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static)
78+
?.GetValue(null);
79+
80+
// Swap out the "current culture" for the UI (localization) culture
81+
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("de-DE");
82+
// Load the satellite assemblies
83+
await (ValueTask)instance!
84+
.GetType()
85+
.GetMethod("LoadCurrentCultureResourcesAsync", BindingFlags.Public | BindingFlags.Instance)!
86+
.Invoke(instance, [])!;
87+
// Swap the culture back
88+
CultureInfo.DefaultThreadCurrentCulture = currentCulture;
89+
6790
var host = builder.Build();
6891

6992
await host.SetCultureFromConfigurationAsync();

AudioCuesheetEditor/Services/UI/LocalizationService.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static IReadOnlyCollection<CultureInfo> AvailableCultures
4040

4141
public event EventHandler? LocalizationChanged;
4242

43-
public CultureInfo SelectedCulture { get; private set; } = CultureInfo.DefaultThreadCurrentUICulture ?? CultureInfo.CurrentUICulture;
43+
public CultureInfo SelectedCulture => CultureInfo.DefaultThreadCurrentUICulture ?? CultureInfo.CurrentUICulture;
4444

4545
public async Task SetCultureFromConfigurationAsync()
4646
{
@@ -58,14 +58,13 @@ public async Task ChangeLanguageAsync(string name)
5858
}
5959
}
6060

61-
private Boolean ChangeLanguage(string name)
61+
private static Boolean ChangeLanguage(string name)
6262
{
6363
var newCulture = AvailableCultures.SingleOrDefault(c => c.Name == name);
6464
if (newCulture != null)
6565
{
66-
SelectedCulture = newCulture;
67-
CultureInfo.DefaultThreadCurrentUICulture = SelectedCulture;
68-
CultureInfo.CurrentUICulture = SelectedCulture;
66+
CultureInfo.DefaultThreadCurrentUICulture = newCulture;
67+
CultureInfo.CurrentUICulture = newCulture;
6968
}
7069
return newCulture != null;
7170
}
-52.4 KB
Binary file not shown.
-44.9 KB
Binary file not shown.
-50.7 KB
Binary file not shown.
-48.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)