From f43d281d34058b29406a6430ebf69b97822f89e2 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Tue, 30 Oct 2018 11:54:10 -0400 Subject: [PATCH 1/4] Fix for explicit AbbreviationsWithPrefixes not lining up with the prefixes. --- Common/UnitDefinitions/Force.json | 2 +- Common/UnitDefinitions/Torque.json | 2 +- UnitsNet/GeneratedCode/UnitSystem.Default.g.cs | 12 ++++++------ UnitsNet/Scripts/GenerateUnits.ps1 | 9 +++++++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Common/UnitDefinitions/Force.json b/Common/UnitDefinitions/Force.json index 792461c8cb..f378fa0528 100644 --- a/Common/UnitDefinitions/Force.json +++ b/Common/UnitDefinitions/Force.json @@ -70,7 +70,7 @@ { "Culture": "ru-RU", "Abbreviations": [ "Н" ], - "AbbreviationsWithPrefixes": [ "даН", "кН" ] + "AbbreviationsWithPrefixes": [ "мкН", "мН", "даН", "кН", "МН" ] } ] }, diff --git a/Common/UnitDefinitions/Torque.json b/Common/UnitDefinitions/Torque.json index c6d0a9197c..5666ce2052 100644 --- a/Common/UnitDefinitions/Torque.json +++ b/Common/UnitDefinitions/Torque.json @@ -48,7 +48,7 @@ { "Culture": "ru-RU", "Abbreviations": [ "Н·м" ], - "AbbreviationsWithPrefixes": [ "кН·м" ] + "AbbreviationsWithPrefixes": [ "кН·м", "МН·м" ] } ] }, diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index cd97f6af65..1ca9d8afe5 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -1526,7 +1526,7 @@ private static readonly ReadOnlyCollection DefaultLocalization new[] { new AbbreviationsForCulture("en-US", "daN"), - new AbbreviationsForCulture("ru-RU", ""), + new AbbreviationsForCulture("ru-RU", "даН"), }), new CulturesForEnumValue((int) ForceUnit.Dyn, new[] @@ -1544,7 +1544,7 @@ private static readonly ReadOnlyCollection DefaultLocalization new[] { new AbbreviationsForCulture("en-US", "kN"), - new AbbreviationsForCulture("ru-RU", ""), + new AbbreviationsForCulture("ru-RU", "кН"), }), new CulturesForEnumValue((int) ForceUnit.KiloPond, new[] @@ -1556,19 +1556,19 @@ private static readonly ReadOnlyCollection DefaultLocalization new[] { new AbbreviationsForCulture("en-US", "MN"), - new AbbreviationsForCulture("ru-RU", ""), + new AbbreviationsForCulture("ru-RU", "МН"), }), new CulturesForEnumValue((int) ForceUnit.Micronewton, new[] { new AbbreviationsForCulture("en-US", "µN"), - new AbbreviationsForCulture("ru-RU", "даН"), + new AbbreviationsForCulture("ru-RU", "мкН"), }), new CulturesForEnumValue((int) ForceUnit.Millinewton, new[] { new AbbreviationsForCulture("en-US", "mN"), - new AbbreviationsForCulture("ru-RU", "кН"), + new AbbreviationsForCulture("ru-RU", "мН"), }), new CulturesForEnumValue((int) ForceUnit.Newton, new[] @@ -4318,7 +4318,7 @@ private static readonly ReadOnlyCollection DefaultLocalization new[] { new AbbreviationsForCulture("en-US", "MN·m"), - new AbbreviationsForCulture("ru-RU", ""), + new AbbreviationsForCulture("ru-RU", "МН·м"), }), new CulturesForEnumValue((int) TorqueUnit.MeganewtonMillimeter, new[] diff --git a/UnitsNet/Scripts/GenerateUnits.ps1 b/UnitsNet/Scripts/GenerateUnits.ps1 index f51a88ad15..3215a6f3ba 100644 --- a/UnitsNet/Scripts/GenerateUnits.ps1 +++ b/UnitsNet/Scripts/GenerateUnits.ps1 @@ -169,6 +169,14 @@ function Add-PrefixUnits { foreach ($unit in $quantity.Units) { + foreach ($localization in $unit.Localization){ + if($localization.AbbreviationsWithPrefixes.Count -gt 0){ + if($unit.Prefixes.Count -ne $localization.AbbreviationsWithPrefixes.Count){ + Write-Error "The prefix count ($($unit.Prefixes.Count)) does not match the abbreviations with prefixes count ($($unit.Localization.AbbreviationsWithPrefixes.Count)) for $($quantity.Name).$($unit.SingularName)" + } + } + } + $prefixIndex = 0 foreach ($prefix in $unit.Prefixes) { @@ -215,6 +223,7 @@ function Add-PrefixUnits { PluralName=$prefix + $(ToCamelCase $unit.PluralName) FromUnitToBaseFunc="("+$unit.FromUnitToBaseFunc+") * $prefixFactor" FromBaseToUnitFunc="("+$unit.FromBaseToUnitFunc+") / $prefixFactor" + Localization=$unit.Localization | % { $abbrev = $prefixAbbreviation + $_.Abbreviations[0] if ($_.AbbreviationsWithPrefixes) { From 6f66664cb0f106105e339b398fd4cbfbe0b35674 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Tue, 30 Oct 2018 13:38:23 -0400 Subject: [PATCH 2/4] Abort build when AbbreviationsWithPrefixes mismatches prefixes count. Will remove incorrect json after testing failure on AppVeyor. --- Common/UnitDefinitions/Force.json | 2 +- UnitsNet/Scripts/GenerateUnits.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/UnitDefinitions/Force.json b/Common/UnitDefinitions/Force.json index f378fa0528..7f1e95f946 100644 --- a/Common/UnitDefinitions/Force.json +++ b/Common/UnitDefinitions/Force.json @@ -70,7 +70,7 @@ { "Culture": "ru-RU", "Abbreviations": [ "Н" ], - "AbbreviationsWithPrefixes": [ "мкН", "мН", "даН", "кН", "МН" ] + "AbbreviationsWithPrefixes": [ "мкН", "мН", "даН", "кН" ] } ] }, diff --git a/UnitsNet/Scripts/GenerateUnits.ps1 b/UnitsNet/Scripts/GenerateUnits.ps1 index 3215a6f3ba..c89ee20556 100644 --- a/UnitsNet/Scripts/GenerateUnits.ps1 +++ b/UnitsNet/Scripts/GenerateUnits.ps1 @@ -172,7 +172,7 @@ function Add-PrefixUnits { foreach ($localization in $unit.Localization){ if($localization.AbbreviationsWithPrefixes.Count -gt 0){ if($unit.Prefixes.Count -ne $localization.AbbreviationsWithPrefixes.Count){ - Write-Error "The prefix count ($($unit.Prefixes.Count)) does not match the abbreviations with prefixes count ($($unit.Localization.AbbreviationsWithPrefixes.Count)) for $($quantity.Name).$($unit.SingularName)" + Write-Error "The prefix count ($($unit.Prefixes.Count)) does not match the abbreviations with prefixes count ($($unit.Localization.AbbreviationsWithPrefixes.Count)) for $($quantity.Name).$($unit.SingularName)" -ErrorAction Stop } } } From afae24cb54fa0bbf1697216a340c96999978b979 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Tue, 30 Oct 2018 14:03:43 -0400 Subject: [PATCH 3/4] Build fails properly. Putting missing abbreviation back. --- Common/UnitDefinitions/Force.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/UnitDefinitions/Force.json b/Common/UnitDefinitions/Force.json index 7f1e95f946..f378fa0528 100644 --- a/Common/UnitDefinitions/Force.json +++ b/Common/UnitDefinitions/Force.json @@ -70,7 +70,7 @@ { "Culture": "ru-RU", "Abbreviations": [ "Н" ], - "AbbreviationsWithPrefixes": [ "мкН", "мН", "даН", "кН" ] + "AbbreviationsWithPrefixes": [ "мкН", "мН", "даН", "кН", "МН" ] } ] }, From 4ece0874772f7b526d6ef3897f3748018d3fda32 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Tue, 30 Oct 2018 14:06:02 -0400 Subject: [PATCH 4/4] Fix for count output --- UnitsNet/Scripts/GenerateUnits.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitsNet/Scripts/GenerateUnits.ps1 b/UnitsNet/Scripts/GenerateUnits.ps1 index c89ee20556..b588817d2c 100644 --- a/UnitsNet/Scripts/GenerateUnits.ps1 +++ b/UnitsNet/Scripts/GenerateUnits.ps1 @@ -172,7 +172,7 @@ function Add-PrefixUnits { foreach ($localization in $unit.Localization){ if($localization.AbbreviationsWithPrefixes.Count -gt 0){ if($unit.Prefixes.Count -ne $localization.AbbreviationsWithPrefixes.Count){ - Write-Error "The prefix count ($($unit.Prefixes.Count)) does not match the abbreviations with prefixes count ($($unit.Localization.AbbreviationsWithPrefixes.Count)) for $($quantity.Name).$($unit.SingularName)" -ErrorAction Stop + Write-Error "The prefix count ($($unit.Prefixes.Count)) does not match the abbreviations with prefixes count ($($localization.AbbreviationsWithPrefixes.Count)) for $($quantity.Name).$($unit.SingularName)" -ErrorAction Stop } } }