Skip to content

Fix for explicit AbbreviationsWithPrefixes not lining up with the pre… #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": [ "мкН", "мН", "даН", "кН", "МН" ]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to update these yesterday and it messed up the localization. I added a error in the script file for these situations and also found torque had the same issue.

}
]
},
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