Skip to content
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
47 changes: 47 additions & 0 deletions DATA-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Data Licenses

This project includes or derives data from the following sources.

---

## Unicode Common Locale Data Repository (CLDR)

This project includes data derived from the **Unicode Common Locale Data Repository (CLDR)**.

Unicode CLDR data is licensed under the **Unicode License Agreement**.

Copyright © Unicode, Inc.
All rights reserved.

Unicode, Inc. hereby grants to any person obtaining a copy of the Unicode data
files and any associated documentation (the "Data Files") a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable license to use,
copy, modify, merge, publish, distribute, and/or sell copies of the Data Files,
and to permit persons to whom the Data Files are furnished to do so, provided
that the above copyright notice(s) and this permission notice appear with all
copies of the Data Files or substantial portions thereof.

THE DATA FILES ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

Unicode License Agreement:
https://www.unicode.org/license.html

---

## ISO 4217 Currency Codes Dataset

This project also uses data derived from the **ISO 4217 currency codes dataset**
provided by the `datasets/currency-codes` project.

Source repository:
https://github.com/datasets/currency-codes

The dataset is licensed under the **Open Database License (ODbL) v1.0**.

You are free to share, create, and adapt the data, provided that you attribute
the source and comply with the terms of the ODbL.

Open Database License (ODbL) v1.0:
https://opendatacommons.org/licenses/odbl/1-0/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2025 Nikolay Selyutin
Copyright (c) 2026 Nikolay Selyutin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
27 changes: 27 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
NOTICE

HawkN.Iso.Currencies
Copyright © 2026 Nikolay Selyutin (HawkN113)

This product includes software developed by the HawkN.Iso.Currencies project.

---

THIRD-PARTY DATA ATTRIBUTIONS

This product includes or derives data from the following third-party sources:

1. Unicode Common Locale Data Repository (CLDR)
Copyright © Unicode, Inc.
Licensed under the Unicode License Agreement.
https://www.unicode.org/license.html

2. ISO 4217 Currency Codes Dataset
Provided by the datasets/currency-codes project.
Licensed under the Open Database License (ODbL) v1.0.
https://opendatacommons.org/licenses/odbl/1-0/

---

The above notices must be included in all copies or substantial portions of
the software where required by the applicable licenses.
368 changes: 201 additions & 167 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ protected void AddStubIfErrors(SourceProductionContext spc, string hintName, str
spc.AddSource(hintName, SourceText.From(stubSource, Encoding.UTF8));
}

protected static (string original, string replacement, string historical) LoadJsonResources(Assembly assembly)
protected static (string original, string translations, string replacement, string currencyCodesCsv) LoadResources(Assembly assembly)
{
return (
ReadResource("HawkN.Iso.Currencies.Generators.Content.SupplementalData.xml"),
ReadResource("HawkN.Iso.Currencies.Generators.Content.Translations.EN.xml"),
ReadResource("HawkN.Iso.Currencies.Generators.Content.list-replacement-currency-names.json"),
ReadResource("HawkN.Iso.Currencies.Generators.Content.СurrencyСodes.csv")
);
string ReadResource(string name)
{
using var stream = assembly.GetManifestResourceStream(name)
?? throw new InvalidOperationException($"{name} not found.");
using var reader = new StreamReader(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
return reader.ReadToEnd();
}

return (
ReadResource("HawkN.Iso.Currencies.Generators.Content.list-original-currencies.json"),
ReadResource("HawkN.Iso.Currencies.Generators.Content.list-replacement-currency-names.json"),
ReadResource("HawkN.Iso.Currencies.Generators.Content.list-historical-currencies.json")
);
}

protected void GenerateSourceOutput((string, string, string) tuple, SourceProductionContext spc)
{
ErrorFactory.Create(new ErrorDescription
{
DiagnosticDescriptor = new DiagnosticDescriptor(
id: DiagnosticDescriptors.UnexpectedErrorId,
id: CreateDescriptorId("0"),
title: Constants.DiagnosticsTitle,
messageFormat: "Unexpected exception: Unexpected error",
category: string.Empty,
Expand All @@ -52,11 +52,23 @@ protected void GenerateSourceOutput((string, string, string) tuple, SourceProduc
ErrorFactory.ShowDiagnostics(spc, GeneratorType.Factory);
}

internal static StringBuilder CreateSourceBuilder(string generatorName, string @namespace, string[]? references = null)
internal static string CreateDescriptorId(string number)
{
return string.Concat(Constants.ErrorPrefixName, number.PadLeft(3, '0'));
}

internal static StringBuilder CreateSourceBuilder(string generatorName, string @namespace, string[] extendedSourceData, string[]? references = null)
{
var sb = new StringBuilder();
sb.AppendLine("// <auto-generated>");
sb.AppendLine($"// This file was generated by {generatorName}");

if (extendedSourceData.Any())
{
foreach (var sourceData in extendedSourceData)
sb.AppendLine($"// {sourceData}");
}

sb.AppendLine("// Do not modify this file manually.");
sb.AppendLine("// </auto-generated>");
sb.AppendLine("#nullable enable");
Expand Down
7 changes: 7 additions & 0 deletions src/packages/HawkN.Iso.Currencies.Generators/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ internal static class Constants
public const string DiagnosticsTitle = "Generator error";
public const string ErrorMark = "#ERROR:";
public const string GeneratorName = "HawkN.Iso.Currencies.Generators source generator";
public const string ErrorPrefixName = "CURRENCY_";
public static readonly string[] ExtendedSourceData =
[
"Release: release-48",
"CLDR URL: https://github.com/unicode-org/cldr",
"Currency codes URL: https://raw.githubusercontent.com/datasets/currency-codes/main/data/codes-all.csv"
];
}
Loading