Skip to content

Commit

Permalink
Fix for explicit AbbreviationsWithPrefixes not lining up with the pre… (
Browse files Browse the repository at this point in the history
#542)

* Fix for explicit AbbreviationsWithPrefixes not lining up with the prefixes.

* Abort build when AbbreviationsWithPrefixes mismatches prefixes count. Will remove incorrect json after testing failure on AppVeyor.

* Build fails properly. Putting missing abbreviation back.

* Fix for count output
  • Loading branch information
tmilnthorp authored and angularsen committed Oct 31, 2018
1 parent 157b288 commit 28f0989
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Common/UnitDefinitions/Force.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{
"Culture": "ru-RU",
"Abbreviations": [ "Н" ],
"AbbreviationsWithPrefixes": [ "даН", "кН" ]
"AbbreviationsWithPrefixes": [ "мкН", "мН", "даН", "кН", "МН" ]
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion Common/UnitDefinitions/Torque.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
"Culture": "ru-RU",
"Abbreviations": [ "Н·м" ],
"AbbreviationsWithPrefixes": [ "кН·м" ]
"AbbreviationsWithPrefixes": [ "кН·м", "МН·м" ]
}
]
},
Expand Down
12 changes: 6 additions & 6 deletions UnitsNet/GeneratedCode/UnitSystem.Default.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new[]
{
new AbbreviationsForCulture("en-US", "daN"),
new AbbreviationsForCulture("ru-RU", ""),
new AbbreviationsForCulture("ru-RU", "даН"),
}),
new CulturesForEnumValue((int) ForceUnit.Dyn,
new[]
Expand All @@ -1544,7 +1544,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new[]
{
new AbbreviationsForCulture("en-US", "kN"),
new AbbreviationsForCulture("ru-RU", ""),
new AbbreviationsForCulture("ru-RU", "кН"),
}),
new CulturesForEnumValue((int) ForceUnit.KiloPond,
new[]
Expand All @@ -1556,19 +1556,19 @@ private static readonly ReadOnlyCollection<UnitLocalization> 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[]
Expand Down Expand Up @@ -4318,7 +4318,7 @@ private static readonly ReadOnlyCollection<UnitLocalization> DefaultLocalization
new[]
{
new AbbreviationsForCulture("en-US", "MN·m"),
new AbbreviationsForCulture("ru-RU", ""),
new AbbreviationsForCulture("ru-RU", "МН·м"),
}),
new CulturesForEnumValue((int) TorqueUnit.MeganewtonMillimeter,
new[]
Expand Down
9 changes: 9 additions & 0 deletions UnitsNet/Scripts/GenerateUnits.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 ($($localization.AbbreviationsWithPrefixes.Count)) for $($quantity.Name).$($unit.SingularName)" -ErrorAction Stop
}
}
}

$prefixIndex = 0
foreach ($prefix in $unit.Prefixes)
{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 28f0989

Please sign in to comment.