Skip to content

Commit

Permalink
localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
vlada-shubina committed Oct 4, 2022
1 parent 917045b commit f33940e
Show file tree
Hide file tree
Showing 20 changed files with 911 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static ConditionStringEvaluator SelectStringEvaluator(string? name, Con
"C++" => CppStyleEvaluatorDefinition.EvaluateFromString,
"MSBUILD" => MSBuildStyleEvaluatorDefinition.EvaluateFromString,
"VB" => VisualBasicStyleEvaluatorDefintion.EvaluateFromString,
_ => throw new TemplateAuthoringException($"Unrecognized evaluator: '{evaluatorName}'."),
_ => throw new TemplateAuthoringException(string.Format(LocalizableStrings.EvaluatorSelector_Exception_UnknownEvaluator, evaluatorName)),
};
return evaluator;
}
Expand All @@ -43,7 +43,7 @@ internal static ConditionEvaluator Select(string? name, ConditionEvaluator? @def
"C++" => CppStyleEvaluatorDefinition.Evaluate,
"MSBUILD" => MSBuildStyleEvaluatorDefinition.Evaluate,
"VB" => VisualBasicStyleEvaluatorDefintion.Evaluate,
_ => throw new TemplateAuthoringException($"Unrecognized evaluator: '{evaluatorName}'."),
_ => throw new TemplateAuthoringException(string.Format(LocalizableStrings.EvaluatorSelector_Exception_UnknownEvaluator, evaluatorName)),
};
return evaluator;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,53 @@ Details: {1}</value>
{1} - the comma separated list of sources (localized values) which define the binding
{2} - the comma separated list of prefixes that can be used to define the source of the value</comment>
</data>
<data name="EvaluatorSelector_Exception_UnknownEvaluator" xml:space="preserve">
<value>Unrecognized evaluator: '{0}'.</value>
<comment>{0} - invalid evaluator value</comment>
</data>
<data name="JoinMacroConfig_Exception_ValuePropertyIsEmpty" xml:space="preserve">
<value>Generated symbol '{0}': array '{1}' should contain JSON objects with property non-empty '{2}' when '{3}' is '{4}'.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name; {2}, {3}, {4} - the property names and values.</comment>
</data>
<data name="LocalizationModelDeserializer_Error_FailedToParse" xml:space="preserve">
<value>Failed to read parse localization file {0}, it will be skipped from further processing.</value>
</data>
<data name="MacroConfig_Exception_ArrayShouldContainObjects" xml:space="preserve">
<value>Generated symbol '{0}': array '{1}' should contain JSON objects.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name.</comment>
</data>
<data name="MacroConfig_Exception_InvalidJSON" xml:space="preserve">
<value>Generated symbol '{0}': '{1}' is not a valid JSON.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name.</comment>
</data>
<data name="MacroConfig_Exception_InvalidRegex" xml:space="preserve">
<value>Generated symbol '{0}': the pattern '{1}' is invalid.</value>
<comment>{0} - name of generated symbol, {1} - the invalid regex pattern</comment>
</data>
<data name="MacroConfig_Exception_MissingMandatoryProperty" xml:space="preserve">
<value>Generated symbol '{0}' of type '{1}' should have '{2}' property defined.</value>
<comment>{0} - name of generated symbol, {1} - the generated symbol type, {2} - the missing property.</comment>
</data>
<data name="MacroConfig_Exception_MissingValueProperty" xml:space="preserve">
<value>Generated symbol '{0}': array '{1}' should contain JSON objects with property '{2}'.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name; {2} - the missing property.</comment>
</data>
<data name="MacroConfig_Exception_ValueShouldBeArray" xml:space="preserve">
<value>Generated symbol '{0}': '{1}' should be a valid JSON array.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name.</comment>
</data>
<data name="MacroConfig_Exception_ValueShouldBeBoolean" xml:space="preserve">
<value>Generated symbol '{0}': '{1}' should be a boolean value.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name.</comment>
</data>
<data name="MacroConfig_Exception_ValueShouldBeInteger" xml:space="preserve">
<value>Generated symbol '{0}': '{1}' should be an integer value.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name.</comment>
</data>
<data name="MacroConfig_Exception_ValueShouldBeString" xml:space="preserve">
<value>Generated symbol '{0}': '{1}' should be a string value.</value>
<comment>{0} - name of generated symbol, {1} - the invalid property name.</comment>
</data>
<data name="RunnableProjectGenerator_CannotAddImplicitChoice" xml:space="preserve">
<value>Variable [{0}] already added with value [{1}]. Cannot add it as implicit variable with value of self.</value>
<comment>{0} is the choiceKey, {1} is the existing conflict value</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ protected static bool ConvertJTokenToBool(string token, IGeneratedSymbolConfig c
var jToken = JToken.Parse(token);
if (jToken.Type is not JTokenType.Boolean and not JTokenType.String)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' should be a boolean value.", config.VariableName);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_ValueShouldBeBoolean, config.VariableName, parameterName), config.VariableName);
}
if (bool.TryParse(jToken.ToString(), out bool result))
{
return result;
}
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' should be a boolean value.", config.VariableName);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_ValueShouldBeBoolean, config.VariableName, parameterName), config.VariableName);
}
catch (TemplateAuthoringException)
{
throw;
}
catch (Exception ex)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' is not a valid JSON.", config.VariableName, ex);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_InvalidJSON, config.VariableName, parameterName), config.VariableName, ex);
}
}

Expand All @@ -103,21 +103,21 @@ protected static int ConvertJTokenToInt(string token, IGeneratedSymbolConfig con
var jToken = JToken.Parse(token);
if (jToken.Type is not JTokenType.Integer and not JTokenType.String)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' should be an integer.", config.VariableName);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_ValueShouldBeInteger, config.VariableName, parameterName), config.VariableName);
}
if (int.TryParse(jToken.ToString(), out int result))
{
return result;
}
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' should be an integer.", config.VariableName);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_ValueShouldBeInteger, config.VariableName, parameterName), config.VariableName);
}
catch (TemplateAuthoringException)
{
throw;
}
catch (Exception ex)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' is not a valid JSON.", config.VariableName, ex);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_InvalidJSON, config.VariableName, parameterName), config.VariableName, ex);
}
}

Expand All @@ -128,7 +128,7 @@ protected static string ConvertJTokenToString(string token, IGeneratedSymbolConf
var jToken = JToken.Parse(token);
if (jToken.Type != JTokenType.String)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' should be a string.", config.VariableName);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_ValueShouldBeString, config.VariableName, parameterName), config.VariableName);
}
return jToken.ToString();
}
Expand All @@ -138,7 +138,7 @@ protected static string ConvertJTokenToString(string token, IGeneratedSymbolConf
}
catch (Exception ex)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' is not a valid JSON.", config.VariableName, ex);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_InvalidJSON, config.VariableName, parameterName), config.VariableName, ex);
}
}

Expand All @@ -149,7 +149,7 @@ protected static JArray ConvertJTokenToJArray(string token, IGeneratedSymbolConf
var jToken = JToken.Parse(token);
if (jToken.Type != JTokenType.Array)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' should be a JSON array.", config.VariableName);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_ValueShouldBeArray, config.VariableName, parameterName), config.VariableName);
}
return (JArray)jToken;
}
Expand All @@ -159,7 +159,7 @@ protected static JArray ConvertJTokenToJArray(string token, IGeneratedSymbolConf
}
catch (Exception ex)
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}': '{parameterName}' is not a valid JSON.", config.VariableName, ex);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_InvalidJSON, config.VariableName, parameterName), config.VariableName, ex);
}
}

Expand All @@ -173,7 +173,7 @@ protected static void IsValidRegex(string regex, IGeneratedSymbolConfig? generat
{
if (generatedSymbolConfig is not null)
{
throw new TemplateAuthoringException($"Generated symbol '{generatedSymbolConfig.VariableName}': the pattern '{regex}' is invalid.", generatedSymbolConfig.VariableName);
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_InvalidRegex, generatedSymbolConfig.VariableName, regex), generatedSymbolConfig.VariableName);
}
else
{
Expand All @@ -186,7 +186,7 @@ protected string GetMandatoryParameterValue(IGeneratedSymbolConfig config, strin
{
if (!config.Parameters.TryGetValue(parameterName, out string token))
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}' of type '{Type}' should have '{parameterName}' property defined.");
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_MissingMandatoryProperty, config.VariableName, Type, parameterName), config.VariableName);
}
return ConvertJTokenToString(token, config, parameterName);
}
Expand All @@ -195,7 +195,7 @@ protected TVal GetMandatoryParameterValue<TVal>(IGeneratedSymbolConfig config, s
{
if (!config.Parameters.TryGetValue(parameterName, out string token))
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}' of type '{Type}' should have '{parameterName}' property defined.");
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_MissingMandatoryProperty, config.VariableName, Type, parameterName), config.VariableName);
}
return converter(token, config, parameterName);
}
Expand All @@ -204,7 +204,7 @@ protected JArray GetMandatoryParameterArray(IGeneratedSymbolConfig config, strin
{
if (!config.Parameters.TryGetValue(parameterName, out string token))
{
throw new TemplateAuthoringException($"Generated symbol '{config.VariableName}' of type '{Type}' should have '{parameterName}' property defined.");
throw new TemplateAuthoringException(string.Format(LocalizableStrings.MacroConfig_Exception_MissingMandatoryProperty, config.VariableName, Type, parameterName), config.VariableName);
}
return ConvertJTokenToJArray(token, config, parameterName);
}
Expand Down
Loading

0 comments on commit f33940e

Please sign in to comment.