-
Notifications
You must be signed in to change notification settings - Fork 63
213 lines (173 loc) · 6.26 KB
/
Copy pathtest-localization.yml
File metadata and controls
213 lines (173 loc) · 6.26 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# For more information see:
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Test localization
on:
push:
branches: ["main"]
pull_request:
branches: ["*"]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
localization:
strategy:
matrix:
include:
# Windows tests
- os: windows-latest
locale: 'fr_FR.UTF-8'
- os: windows-latest
locale: 'ru_RU.UTF-8'
# Ubuntu tests
- os: ubuntu-latest
locale: 'fr_FR.UTF-8'
- os: ubuntu-latest
locale: 'ru_RU.UTF-8'
# macOS tests
- os: macos-latest
locale: 'fr_FR.UTF-8'
- os: macos-latest
locale: 'de_DE.UTF-8'
name: "${{ matrix.locale }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
env:
PYTHONPATH: ${{ github.workspace }}
LC_NUMERIC: ${{ matrix.locale }}
LC_MONETARY: ${{ matrix.locale }}
LANG: ${{ matrix.locale }}
LC_ALL: ${{ matrix.locale }}
PYTHONIOENCODING: utf-8
steps:
- name: Checkout source
uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.x
dotnet-quality: ga
- uses: actions/setup-python@v6
with:
python-version: 3.13
cache: "pip"
- name: Configure Linux locale
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y locales locales-all
# Generate and configure locales
sudo locale-gen ${{ matrix.locale }}
sudo update-locale LANG=${{ matrix.locale }}
# Set locale in multiple ways to ensure it takes effect
export LANG=${{ matrix.locale }}
export LANGUAGE=${{ matrix.locale }}
export LC_ALL=${{ matrix.locale }}
# Verify locale installation
locale -a
locale
- name: Configure Windows locale
if: runner.os == 'Windows'
shell: pwsh
run: |
$locale = "${{ matrix.locale }}".Split('.')[0].Replace('_', '-')
# Set system level culture
Set-WinSystemLocale -SystemLocale $locale
# Set .NET cultures
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo($locale)
[System.Threading.Thread]::CurrentThread.CurrentUICulture = [System.Globalization.CultureInfo]::GetCultureInfo($locale)
# Set default AppContext switch for .NET
[AppContext]::SetSwitch('System.Globalization.UseNls', $true)
# Set environment variables
$env:DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = 'false'
$env:DOTNET_RUNTIME_IDENTIFIER = "win-x64"
# Verify culture settings
Write-Host "Current Culture: $([System.Threading.Thread]::CurrentThread.CurrentCulture)"
Write-Host "Current UI Culture: $([System.Threading.Thread]::CurrentThread.CurrentUICulture)"
- name: Configure macOS locale
if: runner.os == 'macOS'
run: |
# List available locales
locale -a
# Try to set the locale
export LANG=${{ matrix.locale }}
export LC_ALL=${{ matrix.locale }}
# Verify locale
locale
# Create temporary project directory
TEMP_DIR=$(mktemp -d)
pushd $TEMP_DIR
# Create project file
cat > LocaleSetup.csproj << 'EOF'
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
</Project>
EOF
# Create program file
cat > Program.cs << 'EOF'
using System;
using System.Globalization;
using System.Threading;
class Program {
static void Main() {
var locale = Environment.GetEnvironmentVariable("LC_ALL")?.Split('.')[0].Replace("_", "-");
try {
var culture = new CultureInfo(locale);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
Console.WriteLine($"Set culture to: {culture.Name}");
} catch (Exception e) {
Console.WriteLine($"Failed to set culture: {e.Message}");
}
}
}
EOF
# Build and run
dotnet run
# Cleanup
popd
rm -rf $TEMP_DIR
- name: Install dependencies
run: |
pip install -U --upgrade-strategy=only-if-needed pip
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Verify locale
shell: bash
run: |
echo "Current locale settings:"
locale
echo -e "\nPython locale test:"
python -c "
import locale
import sys
print(f'Default encoding: {sys.getdefaultencoding()}')
print(f'Filesystem encoding: {sys.getfilesystemencoding()}')
print(f'Locale: {locale.getlocale()}')
# Try setting the locale explicitly
try:
locale.setlocale(locale.LC_ALL, '')
print(f'Set locale successful: {locale.getlocale()}')
except locale.Error as e:
print(f'Failed to set locale: {e}')
# Test number formatting
try:
print(f'Number formatting: {locale.format_string(\"%.2f\", 1234.56)}')
except Exception as e:
print(f'Number formatting failed: {e}')
# Test currency formatting
try:
print(f'Currency formatting: {locale.currency(1234.56)}')
except Exception as e:
print(f'Currency formatting failed: {e}')
"
- name: Run locale tests
run: pytest -m "localization" -vr A tests --junitxml=test-results.xml
- uses: test-summary/action@v2
if: always()
with:
paths: test-results.xml