Skip to content

Commit 5568739

Browse files
committed
initial i18n for dsc_lib
1 parent 34c4453 commit 5568739

File tree

6 files changed

+167
-86
lines changed

6 files changed

+167
-86
lines changed

dsc_lib/locales/en-us.toml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
11
_version = 1
22

3+
[configure.constraints]
4+
minLengthIsNull = "Parameter '#{name}' has minimum length constraint but is null"
5+
notMinLength = "Parameter '#{name}' has minimum length constraint of #{min_length} but is #{length}"
6+
minLengthNotStringOrArray = "Parameter '#{name}' has minimum length constraint but is not a string or array"
7+
8+
maxLengthIsNull = "Parameter '#{name}' has maximum length constraint but is null"
9+
maxLengthExceeded = "Parameter '#{name}' has maximum length constraint of #{max_length} but is #{length}"
10+
maxLengthNotStringOrArray = "Parameter '#{name}' has maximum length constraint but is not a string or array"
11+
12+
minValueIsNull = "Parameter '#{name}' has minimum value constraint but is null"
13+
notMinValue = "Parameter '#{name}' has minimum value constraint of #{min_value} but is #{value}"
14+
minValueNotInteger = "Parameter '#{name}' has minimum value constraint but is not an integer"
15+
maxValueIsNull = "Parameter '#{name}' has maximum value constraint but is null"
16+
notMaxValue = "Parameter '#{name}' has maximum value constraint of #{max_value} but is #{value}"
17+
maxValueNotInteger = "Parameter '#{name}' has maximum value constraint but is not an integer"
18+
19+
allowedValuesIsNull = "Parameter '#{name}' has allowed values constraint but is null"
20+
notAllowedValue = "Parameter '#{name}' has allowed values constraint but is not in the list of allowed values"
21+
allowedValuesNotStringOrInteger = "Parameter '#{name}' has allowed values constraint but is not a string or integer"
22+
23+
[configure.dependsOn]
24+
duplicateResource = "Resource named '#{name}' is specified more than once in the configuration"
25+
syntaxIncorrect = "'dependsOn' syntax is incorrect: #{dependency}"
26+
dependencyNotFound = "'dependsOn' resource name '#{dependency_name}' does not exist for resource named '#{resource_name}'"
27+
dependencyTypeMismatch = "'dependsOn' resource type '#{resource_type}' does not match resource type '#{dependency_type}' for resource named '#{resource_name}'"
28+
resourceNotInOrder = "Resource not found in order"
29+
dependencyNotInOrder = "Dependency not found in order"
30+
circularDependency = "Circular dependency detected for resource named '#{resource}'"
31+
invocationOrder = "Resource invocation order"
32+
33+
[configure.mod]
34+
escapePropertyValues = "Escape returned property values"
35+
nestedArraysNotSupported = "Nested arrays not supported"
36+
arrayElementCouldNotTransformAsString = "Array element could not be transformed as string"
37+
valueCouldNotBeTransformedAsString = "Property value '#{value}' could not be transformed as string"
38+
elevationRequired = "Elevated security context required"
39+
restrictedRequired = "Restricted security context required"
40+
desired = "Desired state: #{state}"
41+
handlesExist = "Resource handles _exist or _exist is true"
42+
whatIfNotSupportedForDelete = "What-if execution not supported for delete"
43+
implementsDelete = "Resource implements delete and _exist is false"
44+
groupNotSupportedForDelete = "Group resources not supported for delete"
45+
deleteNotSupported = "Resource '#{resource}' does not support `delete` and does not handle `_exist` as false"
46+
expectedState = "Expected state: #{state}"
47+
exportInput = "Export input: #{input}"
48+
noParameters = "No parameters defined in configuration and no parameters input"
49+
noParametersDefined = "No parameters defined in configuration"
50+
processingParameter = "Processing parameter '#{name}'"
51+
setDefaultParameter = "Set default parameter '#{name}'"
52+
defaultStringNotDefined = "Default value as string is not defined"
53+
noParametersInput = "No parameters input"
54+
setSecureParameter = "Set secure parameter '#{name}'"
55+
setParameter = "Set parameter '#{name}' to '#{value}'"
56+
parameterNotDefined = "Parameter '#{name}' is not defined in configuration"
57+
noVariables = "No variables defined in configuration"
58+
setVariable = "Set variable '#{name}' to '#{value}'"
59+
parameterNotString = "Parameter '#{name}' is not a string"
60+
parameterNotInteger = "Parameter '#{name}' is not an integer"
61+
parameterNotBoolean = "Parameter '#{name}' is not a boolean"
62+
parameterNotArray = "Parameter '#{name}' is not an array"
63+
parameterNotObject = "Parameter '#{name}' is not an object"
64+
invokePropertyExpressions = "Invoke property expressions"
65+
invokeExpression = "Invoke property expression for #{name}: #{value}"
66+
67+
[discovery.commandDiscovery]
68+
couldNotReadSetting = "Could not read 'resourcePath' setting"
69+
appendingEnvPath = "Appending PATH to resourcePath"
70+
originalPath = "Original PATH: #{path}"
71+
failedGetEnvPath = "Failed to get PATH environment variable"
72+
exeHomeAlreadyInPath = "Exe home is already in path: #{path}"
73+
addExeHomeToPath = "Adding exe home to path: #{path}"
74+
usingResourcePath = "Using Resource Path: #{path}"
75+
discoverResources = "Discovering resources using filter: #{filter}"
76+
invalidAdapterFilter = "Could not build Regex filter for adapter name"
77+
progressSearching = "Searching for resources"
78+
foundResourceManifest = "Found resource manifest: #{path}"
79+
adapterFound = "Resource adapter '#{adapter}' found"
80+
resourceFound = "Resource '#{resource}' found"

dsc_lib/src/configure/constraints.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use crate::configure::config_doc::Parameter;
55
use crate::DscError;
6+
use rust_i18n::t;
67
use serde_json::Value;
78

89
/// Checks that the given value matches the given parameter length constraints.
@@ -25,48 +26,48 @@ pub fn check_length(name: &str, value: &Value, constraint: &Parameter) -> Result
2526
if let Some(min_length) = constraint.min_length {
2627
if value.is_string() {
2728
let Some(value) = value.as_str() else {
28-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum length constraint but is null")));
29+
return Err(DscError::Validation(t!("configure.constraints.minLengthIsNull", name = name).to_string()));
2930
};
3031

3132
if value.len() < usize::try_from(min_length)? {
32-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum length constraint of {min_length} but is {0}", value.len())));
33+
return Err(DscError::Validation(t!("configure.constraints.notMinLength", name = name, min_length = min_length, length = value.len()).to_string()));
3334
}
3435
}
3536
else if value.is_array() {
3637
let Some(value) = value.as_array() else {
37-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum length constraint but is null")));
38+
return Err(DscError::Validation(t!("configure.constraints.minLengthIsNull", name = name).to_string()));
3839
};
3940

4041
if value.len() < usize::try_from(min_length)? {
41-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum length constraint of {min_length} but is {0}", value.len())));
42+
return Err(DscError::Validation(t!("configure.constraints.notMinLength", name = name, min_length = min_length, length = value.len()).to_string()));
4243
}
4344
}
4445
else {
45-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum length constraint but is not a string or array")));
46+
return Err(DscError::Validation(t!("configure.constraints.minLengthNotStringOrArray", name = name).to_string()));
4647
}
4748
}
4849

4950
if let Some(max_length) = constraint.max_length {
5051
if value.is_string() {
5152
let Some(value) = value.as_str() else {
52-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum length constraint but is null")));
53+
return Err(DscError::Validation(t!("configure.constraints.maxLengthIsNull", name = name).to_string()));
5354
};
5455

5556
if value.len() > usize::try_from(max_length)? {
56-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum length constraint of {max_length} but is {0}", value.len())));
57+
return Err(DscError::Validation(t!("configure.constraints.maxLengthExceeded", name = name, max_length = max_length, length = value.len()).to_string()));
5758
}
5859
}
5960
else if value.is_array() {
6061
let Some(value) = value.as_array() else {
61-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum length constraint but is null")));
62+
return Err(DscError::Validation(t!("configure.constraints.maxLengthIsNull", name = name).to_string()));
6263
};
6364

6465
if value.len() > usize::try_from(max_length)? {
65-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum length constraint of {max_length} but is {0}", value.len())));
66+
return Err(DscError::Validation(t!("configure.constraints.maxLengthExceeded", name = name, max_length = max_length, length = value.len()).to_string()));
6667
}
6768
}
6869
else {
69-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum length constraint but is not a string or array")));
70+
return Err(DscError::Validation(t!("configure.constraints.maxLengthNotStringOrArray", name = name).to_string()));
7071
}
7172
}
7273

@@ -93,30 +94,30 @@ pub fn check_number_limits(name: &str, value: &Value, constraint: &Parameter) ->
9394
if let Some(min_value) = constraint.min_value {
9495
if value.is_i64() && value.as_i64().is_some() {
9596
let Some(value) = value.as_i64() else {
96-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum value constraint but is null")));
97+
return Err(DscError::Validation(t!("configure.constraints.minValueIsNull", name = name).to_string()));
9798
};
9899

99100
if value < min_value {
100-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum value constraint of {min_value} but is {value}")));
101+
return Err(DscError::Validation(t!("configure.constraints.notMinValue", name = name, min_value = min_value, value = value).to_string()));
101102
}
102103
}
103104
else {
104-
return Err(DscError::Validation(format!("Parameter '{name}' has minimum value constraint but is not an integer")));
105+
return Err(DscError::Validation(t!("configure.constraints.minValueNotInteger", name = name).to_string()));
105106
}
106107
}
107108

108109
if let Some(max_value) = constraint.max_value {
109110
if value.is_i64() && value.as_i64().is_some() {
110111
let Some(value) = value.as_i64() else {
111-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum value constraint but is null")));
112+
return Err(DscError::Validation(t!("configure.constraints.maxValueIsNull", name = name).to_string()));
112113
};
113114

114115
if value > max_value {
115-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum value constraint of {max_value} but is {value}")));
116+
return Err(DscError::Validation(t!("configure.constraints.notMaxValue", name = name, max_value = max_value, value = value).to_string()));
116117
}
117118
}
118119
else {
119-
return Err(DscError::Validation(format!("Parameter '{name}' has maximum value constraint but is not an integer")));
120+
return Err(DscError::Validation(t!("configure.constraints.maxValueNotInteger", name = name).to_string()));
120121
}
121122
}
122123

@@ -143,24 +144,24 @@ pub fn check_allowed_values(name: &str, value: &Value, constraint: &Parameter) -
143144
if let Some(allowed_values) = &constraint.allowed_values {
144145
if value.is_string() && value.as_str().is_some(){
145146
let Some(value) = value.as_str() else {
146-
return Err(DscError::Validation(format!("Parameter '{name}' has allowed values constraint but is null")));
147+
return Err(DscError::Validation(t!("configure.constraints.allowedValuesIsNull", name = name).to_string()));
147148
};
148149

149150
if !allowed_values.contains(&Value::String(value.to_string())) {
150-
return Err(DscError::Validation(format!("Parameter '{name}' has value not in the allowed values list")));
151+
return Err(DscError::Validation(t!("configure.constraints.notAllowedValue", name = name).to_string()));
151152
}
152153
}
153154
else if value.is_i64() && value.as_i64().is_some() {
154155
let Some(value) = value.as_i64() else {
155-
return Err(DscError::Validation(format!("Parameter '{name}' has allowed values constraint but is null")));
156+
return Err(DscError::Validation(t!("configure.constraints.allowedValuesIsNull", name = name).to_string()));
156157
};
157158

158159
if !allowed_values.contains(&Value::Number(value.into())) {
159-
return Err(DscError::Validation(format!("Parameter '{name}' has value not in the allowed values list")));
160+
return Err(DscError::Validation(t!("configure.constraints.notAllowedValue", name = name).to_string()));
160161
}
161162
}
162163
else {
163-
return Err(DscError::Validation(format!("Parameter '{name}' has allowed values constraint but is not a string or integer")));
164+
return Err(DscError::Validation(t!("configure.constraints.allowedValuesNotStringOrInteger", name = name).to_string()));
164165
}
165166
}
166167

dsc_lib/src/configure/depends_on.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::configure::Configuration;
66
use crate::DscError;
77
use crate::parser::Statement;
88

9+
use rust_i18n::t;
910
use super::context::Context;
10-
11-
use tracing::{debug, trace};
11+
use tracing::debug;
1212

1313
/// Gets the invocation order of resources based on their dependencies
1414
///
@@ -29,25 +29,25 @@ pub fn get_resource_invocation_order(config: &Configuration, parser: &mut Statem
2929
for resource in &config.resources {
3030
// validate that the resource isn't specified more than once in the config
3131
if config.resources.iter().filter(|r| r.name == resource.name && r.resource_type == resource.resource_type).count() > 1 {
32-
return Err(DscError::Validation(format!("Resource named '{0}' is specified more than once in the configuration", resource.name)));
32+
return Err(DscError::Validation(t!("configure.dependsOn.duplicateResource", resource_name = resource.name).to_string()));
3333
}
3434

3535
let mut dependency_already_in_order = true;
3636
if let Some(depends_on) = resource.depends_on.clone() {
3737
for dependency in depends_on {
3838
let statement = parser.parse_and_execute(&dependency, context)?;
3939
let Some(string_result) = statement.as_str() else {
40-
return Err(DscError::Validation(format!("'dependsOn' syntax is incorrect: {dependency}")));
40+
return Err(DscError::Validation(t!("configure.dependsOn.syntaxIncorrect", dependency = dependency).to_string()));
4141
};
4242
let (resource_type, resource_name) = get_type_and_name(string_result)?;
4343

4444
// find the resource by name
4545
let Some(dependency_resource) = config.resources.iter().find(|r| r.name.eq(resource_name)) else {
46-
return Err(DscError::Validation(format!("'dependsOn' resource name '{resource_name}' does not exist for resource named '{0}'", resource.name)));
46+
return Err(DscError::Validation(t!("configure.dependsOn.dependencyNotFound", dependency_name = resource_name, resource_name = resource.name).to_string()));
4747
};
4848
// validate the type matches
4949
if dependency_resource.resource_type != resource_type {
50-
return Err(DscError::Validation(format!("'dependsOn' resource type '{resource_type}' does not match resource type '{0}' for resource named '{1}'", dependency_resource.resource_type, dependency_resource.name)));
50+
return Err(DscError::Validation(t!("configure.dependsOn.dependencyTypeMismatch", resource_type = resource_type, dependency_type = dependency_resource.resource_type, resource_name = resource.name).to_string()));
5151
}
5252
// see if the dependency is already in the order
5353
if order.iter().any(|r| r.name == resource_name && r.resource_type == resource_type) {
@@ -67,16 +67,16 @@ pub fn get_resource_invocation_order(config: &Configuration, parser: &mut Statem
6767
continue;
6868
};
6969
// check if the order has resource before its dependencies
70-
let resource_index = order.iter().position(|r| r.name == resource.name && r.resource_type == resource.resource_type).ok_or(DscError::Validation("Resource not found in order".to_string()))?;
70+
let resource_index = order.iter().position(|r| r.name == resource.name && r.resource_type == resource.resource_type).ok_or(DscError::Validation(t!("configure.dependsOn.resourceNotInOrder").to_string()))?;
7171
for dependency in depends_on {
7272
let statement = parser.parse_and_execute(dependency, context)?;
7373
let Some(string_result) = statement.as_str() else {
74-
return Err(DscError::Validation(format!("'dependsOn' syntax is incorrect: {dependency}")));
74+
return Err(DscError::Validation(t!("configure.dependsOn.syntaxIncorrect", dependency = dependency).to_string()));
7575
};
7676
let (resource_type, resource_name) = get_type_and_name(string_result)?;
77-
let dependency_index = order.iter().position(|r| r.name == resource_name && r.resource_type == resource_type).ok_or(DscError::Validation("Dependency not found in order".to_string()))?;
77+
let dependency_index = order.iter().position(|r| r.name == resource_name && r.resource_type == resource_type).ok_or(DscError::Validation(t!("configure.dependsOn.dependencyNotInOrder").to_string()))?;
7878
if resource_index < dependency_index {
79-
return Err(DscError::Validation(format!("Circular dependency detected for resource named '{0}'", resource.name)));
79+
return Err(DscError::Validation(t!("configure.dependsOn.circularDependency", resource_name = resource.name).to_string()));
8080
}
8181
}
8282
}
@@ -87,14 +87,14 @@ pub fn get_resource_invocation_order(config: &Configuration, parser: &mut Statem
8787
order.push(resource.clone());
8888
}
8989

90-
trace!("Resource invocation order: {0:?}", order);
90+
debug!("{}: {order:?}", t!("configure.dependsOn.invocationOrder"));
9191
Ok(order)
9292
}
9393

9494
fn get_type_and_name(statement: &str) -> Result<(&str, &str), DscError> {
9595
let parts: Vec<&str> = statement.split(':').collect();
9696
if parts.len() != 2 {
97-
return Err(DscError::Validation(format!("'dependsOn' syntax is incorrect: {statement}")));
97+
return Err(DscError::Validation(t!("configure.dependsOn.syntaxIncorrect", dependency = statement).to_string()));
9898
}
9999
Ok((parts[0], parts[1]))
100100
}

0 commit comments

Comments
 (0)