How should we implement localization for exception message with CsvHelper? #2309
jobouillon
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm wondering if there is a way to localize easily all message from csvhelper?
What is the recommended or a good way to do this?
Header with name 'Test'[0] was not found. Headers: 'Test2' If you are expecting some headers to be missing and want to ignore this validation, set the configuration HeaderValidated to null. You can also change the functionality to do something else, like logging the issue. IReader state: ColumnCount: 1 CurrentIndex: -1 HeaderRecord: ["Test2"] IParser state: ByteCount: 0 CharCount: 12 Row: 1 RawRow: 1 Count: 1 RawRecord: Test2 IReader state: ColumnCount: 1 CurrentIndex: -1 HeaderRecord: ["Test2"] IParser state: ByteCount: 0 CharCount: 12 Row: 1 RawRow: 1 Count: 1 RawRecord: Test2
After looking up online, I have implemented a wrapper around csv helper and was plannig to translate receiving exception message by using localization resx file but it's ratter fastidious to convert all possible error messages.
I'm wondering if someone has achieve or know a better way to do this.
public static class CsvWrapperExtension
{
public static IEnumerable Read<T, TMap>(string filepath, CsvConfiguration csvConfiguration)
where TMap : ClassMap
{
try
{
//ValidateColumnCount<T, TMap>(filepath, csvConfiguration);
using var reader = new StreamReader(filepath, csvConfiguration.Encoding);
using var csv = new CsvReader(reader, csvConfiguration);
}
Beta Was this translation helpful? Give feedback.
All reactions