Skip to content

Commit 92a40d9

Browse files
authored
Merge pull request #631 from SteveL-MSFT/dsclib-i18n
Internationalize dsc_lib
2 parents 481f758 + 0f8c7bb commit 92a40d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1474
-347
lines changed

dsc/Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsc/examples/brew_uninstall.dsc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resources:
99
- name: os_check
1010
type: Microsoft/OSInfo
1111
properties:
12-
family: MacOS
12+
family: macOS
1313
- name: brew
1414
type: DSC.PackageManagement/Brew
1515
properties:

dsc/locales/en-us.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ foundProcesses = "Found processes"
4242
failedToGetPid = "Could not get current process id"
4343
currentPid = "Current process id"
4444
failedToGetProcess = "Could not get current process"
45-
terminatingSubprocess ="Terminating subprocesses of process"
45+
terminatingSubprocess = "Terminating subprocesses of process"
4646
terminatingProcess = "Terminating process"
4747
failedTerminatingProcess = "Failed to terminate process"
4848
storeMessage = """DSC.exe is a command-line tool and cannot be run directly from the Windows Store or Explorer.
@@ -58,11 +58,11 @@ failedToOpenFile = "Failed to open included file"
5858
invalidFileContent = "Invalid UTF-8 sequence in included file"
5959
invalidFile = "Failed to read the configuration file as YAML or JSON"
6060
resolvingParameters = "Resolving parameters from file"
61-
failedParseParametersFile = "Failed to parse parameters file to JSON"
62-
failedResolveParametersFile = "Failed to resolve parameters file"
63-
noParametersFile = "No parameters file found"
61+
failedParseParametersFile = "Failed to parse parameters file or conetnt to JSON"
62+
couldNotReadParametersFile = "Could not read parameters file"
6463
invalidPath = "Include path must not contain '..'"
6564
failedGetCurrentDirectory = "Failed to get current directory"
65+
noParameters = "No parameters specified"
6666

6767
[resource_command]
6868
implementedAs = "implemented as"

dsc/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() {
4242
debug!("{}: {}", t!("main.usingDscVersion"), env!("CARGO_PKG_VERSION"));
4343

4444
let progress_format = args.progress_format.unwrap_or( ProgressFormat::Default );
45-
45+
4646
match args.subcommand {
4747
SubCommand::Completer { shell } => {
4848
info!("{} {:?}", t!("main.generatingCompleter"), shell);
@@ -55,7 +55,7 @@ fn main() {
5555
match std::fs::read_to_string(&file_name) {
5656
Ok(parameters) => subcommand::config(&subcommand, &Some(parameters), system_root.as_ref(), &as_group, &as_include, progress_format),
5757
Err(err) => {
58-
error!("{} '{file_name}': {err}", t!("main.failedToReadParametersFile"));
58+
error!("{} '{file_name}': {err}", t!("main.failedReadingParametersFile"));
5959
exit(util::EXIT_INVALID_INPUT);
6060
}
6161
}
@@ -111,7 +111,7 @@ fn terminate_subprocesses(sys: &System, process: &Process) {
111111

112112
info!("{}: {:?} {}", t!("main.terminatingProcess"), process.name(), process.pid());
113113
if !process.kill() {
114-
error!("{}: {:?} {}", t!("main.failedTerminateProcess"), process.name(), process.pid());
114+
error!("{}: {:?} {}", t!("main.failedTerminatingProcess"), process.name(), process.pid());
115115
}
116116
}
117117

dsc/src/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ pub fn get_contents(input: &str) -> Result<(Option<String>, String), String> {
126126
Some(parameters_json)
127127
},
128128
Err(err) => {
129-
return Err(format!("{} '{parameters_file:?}': {err}", t!("resolve.failedResolveParametersFile")));
129+
return Err(format!("{} '{parameters_file:?}': {err}", t!("resolve.couldNotReadParametersFile")));
130130
}
131131
}
132132
},
133133
Some(IncludeParametersKind::ParametersContent(text)) => {
134134
let parameters_json = match parse_input_to_json(&text) {
135135
Ok(json) => json,
136136
Err(err) => {
137-
return Err(format!("{}: {err}", t!("resolve.invalidParametersContent")));
137+
return Err(format!("{}: {err}", t!("resolve.failedParseParametersFile")));
138138
}
139139
};
140140
Some(parameters_json)

dsc/tests/dsc.exit_code.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Describe 'exit code tests' {
88
}
99
It 'non-zero exit code not in manifest has generic message' {
1010
dsc resource get -r Test/ExitCode --input "{ exitCode: 1 }" 2> $TestDrive/tracing.txt
11-
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Exit code 1'
11+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'exit code 1'
1212
}
1313
It 'success exit code executes without error' {
1414
$result = dsc resource get -r Test/ExitCode --input "{ exitCode: 0 }" | ConvertFrom-Json

dsc/tests/dsc_i18n.tests.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
BeforeDiscovery {
5+
$tomls = Get-ChildItem $PSScriptRoot/../../en-us.toml -Recurse -File
6+
$projects = @()
7+
$tomls | ForEach-Object {
8+
$projectName = (Split-Path $_ -Parent | Split-Path -Parent)
9+
$projects += @{ project = $projectName; toml = $_ }
10+
}
11+
}
12+
13+
Describe 'Internationalization tests' {
14+
It 'Project <project> uses i18n strings from <toml>' -TestCases $projects {
15+
param($project, $toml)
16+
17+
$i18n = [System.Collections.Hashtable]::new([System.StringComparer]::Ordinal)
18+
$prefix = ''
19+
Get-Content -Path $toml | ForEach-Object {
20+
if ($_ -match '\[(?<prefix>.*?)\]') {
21+
$prefix = $Matches['prefix']
22+
}
23+
elseif ($_ -match '^(?<key>\w+)\s?=\s?"(?<value>.*?)"') {
24+
$key = $prefix + '.' + $Matches['key']
25+
$i18n[$key] = 0
26+
}
27+
}
28+
29+
$missing = @()
30+
Get-ChildItem -Recurse -Path $project -Include *.rs -File | ForEach-Object {
31+
# Write-Verbose -Verbose "File: $_"
32+
$line = 0
33+
Get-Content -Path $_ | ForEach-Object {
34+
$line++
35+
($_ | Select-String -Pattern '[^\w]t\!\("(?<key>.*?)".*?\)' -AllMatches).Matches | ForEach-Object {
36+
# write-verbose -verbose "Line: $_"
37+
if ($null -ne $_) {
38+
$key = $_.Groups['key'].Value
39+
if ($i18n.ContainsKey($key)) {
40+
$i18n[$key] = 1
41+
# write-verbose -verbose "Found on line $line : $key"
42+
}
43+
else {
44+
$missing += $key
45+
# write-verbose -verbose "Missing: $key"
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
$missing | Should -BeNullOrEmpty -Because "The following i18n keys are missing from $toml :`n$($missing | Out-String)"
53+
$unused = $i18n.GetEnumerator() | Where-Object { $_.Value -eq 0 } | ForEach-Object { $_.Key }
54+
$unused | Should -BeNullOrEmpty -Because "The following i18n keys are unused in the project:`n$($unused | Out-String)"
55+
}
56+
}

dsc/tests/dsc_resource_list.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ Describe 'Tests for listing resources' {
8484
It 'Invalid adapter returns an error' {
8585
$out = dsc resource list --adapter 'foo*' 2>&1 | Out-String
8686
$LASTEXITCODE | Should -Be 0
87-
$out | Should -BeLike "*ERROR*Adapter 'foo`*' not found*"
87+
$out | Should -BeLike "*ERROR*Adapter not found: foo`*"
8888
}
8989
}

dsc/tests/dsc_settings.tests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Describe 'tests for dsc settings' {
4848
}
4949

5050
It 'ensure a new tracing value in settings has effect' {
51-
51+
5252
$script:dscDefaultv1Settings."tracing"."level" = "TRACE"
5353
$script:dscDefaultv1Settings | ConvertTo-Json -Depth 90 | Set-Content -Force -Path $script:dscSettingsFilePath
5454

@@ -57,11 +57,11 @@ Describe 'tests for dsc settings' {
5757
}
5858

5959
It 'ensure a new resource_path value in settings has effect' {
60-
60+
6161
$script:dscDefaultv1Settings."resourcePath"."directories" = @("TestDir1","TestDir2")
6262
$script:dscDefaultv1Settings | ConvertTo-Json -Depth 90 | Set-Content -Force -Path $script:dscSettingsFilePath
6363
dsc -l debug resource list 2> $TestDrive/tracing.txt
64-
$expectedString = 'Using Resource Path: "TestDir1'+[System.IO.Path]::PathSeparator+'TestDir2'
64+
$expectedString = 'Using Resource Path: TestDir1'+[System.IO.Path]::PathSeparator+'TestDir2'
6565
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly $expectedString
6666
}
6767

@@ -71,7 +71,7 @@ Describe 'tests for dsc settings' {
7171
Set-ItResult -Skip -Because "Setting policy requires sudo"
7272
return
7373
}
74-
74+
7575
$script:dscDefaultv1Settings."tracing"."level" = "TRACE"
7676
$script:dscDefaultv1Settings."resourcePath"."directories" = @("PolicyDir")
7777
$script:dscDefaultv1Settings | ConvertTo-Json -Depth 90 | Set-Content -Force -Path $script:policyFilePath
@@ -87,23 +87,23 @@ Describe 'tests for dsc settings' {
8787
# ensure policy overrides everything
8888
dsc -l debug resource list 2> $TestDrive/tracing.txt
8989
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Trace-level is Trace"
90-
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: "PolicyDir'
90+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: PolicyDir'
9191

9292
# without policy, command-line args have priority
9393
Remove-Item -Path $script:policyFilePath
9494
dsc -l debug resource list 2> $TestDrive/tracing.txt
9595
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Trace-level is Debug"
96-
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: "SettingsDir'
96+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: SettingsDir'
9797

9898
# without policy and command-line args, settings file is used
9999
dsc resource list 2> $TestDrive/tracing.txt
100100
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Trace-level is Trace"
101-
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: "SettingsDir'
101+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: SettingsDir'
102102

103103
# without policy and command-line args and settings file, the default settings file is used
104104
Remove-Item -Path $script:dscSettingsFilePath
105105
dsc resource list 2> $TestDrive/tracing.txt
106106
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Trace-level is Trace"
107-
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: "Defaultv1SettingsDir'
107+
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: Defaultv1SettingsDir'
108108
}
109109
}

0 commit comments

Comments
 (0)