forked from actions/runner-images
-
Notifications
You must be signed in to change notification settings - Fork 1
83 lines (67 loc) · 2.65 KB
/
Globalization.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: .NET 8 Globalization Example
on:
push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Create the .NET 8 Console Application
run: |
# Create a new .NET 8 console application
dotnet new console -n GlobalizationDemo
cd GlobalizationDemo
# Install Localization NuGet package
dotnet add package Microsoft.Extensions.Localization
# Create Resources folder and add localization files
mkdir Resources
echo '<?xml version="1.0" encoding="utf-8"?>' > Resources/Messages.resx
echo '<root><data name="Greeting" xml:space="preserve"><value>Hello!</value></data></root>' >> Resources/Messages.resx
echo '<?xml version="1.0" encoding="utf-8"?>' > Resources/Messages.es.resx
echo '<root><data name="Greeting" xml:space="preserve"><value>¡Hola!</value></data></root>' >> Resources/Messages.es.resx
# Create Program.cs with globalization logic
echo 'using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using System;
using System.Globalization;
class Program
{
static void Main(string[] args)
{
// Set the culture to Spanish for this example
var culture = new CultureInfo("es-ES");
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
// Setup dependency injection (DI)
var serviceProvider = new ServiceCollection()
.AddLocalization()
.BuildServiceProvider();
// Get localization service
var localizer = serviceProvider.GetRequiredService<IStringLocalizer<Program>>();
// Print the localized greeting
Console.WriteLine(localizer["Greeting"]);
}
}' > Program.cs
- name: Build the .NET Project
run: |
cd GlobalizationDemo
dotnet build --configuration Release
- name: Run the .NET Project
run: |
cd GlobalizationDemo
dotnet run --configuration Release
- name: Validate Output
run: |
# Check the output for localized greeting
OUTPUT=$(dotnet run --configuration Release)
if [[ "$OUTPUT" != "¡Hola!" ]]; then
echo "Test failed. Expected '¡Hola!' but got '$OUTPUT'."
exit 1
else
echo "Test passed. Output is correct."
fi