Skip to content

๐ŸŒ Makes internationalization in .NET just a little bit easier with a set of helper classes and methods.

License

Notifications You must be signed in to change notification settings

dimesoftware/i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Logo - provided by Freepik

i18n

This repo aims to make internationalization in .NET just a little bit easier with a set of helper classes and methods.

Getting Started

  • You must have Visual Studio 2019 Community or higher.
  • The dotnet cli is also highly recommended.

About this project

This repository is split it in several projects. Each one has a specific focus:

  • Dime.i18n.Date is there to convert DateTime objects from UTC to the local (i.e. user-defined) time zone to UTC and vice versa.
  • Dime.i18n.Countries provides some capabilities to retrieve a list of the world's countries.

Build and Test

  • Run dotnet restore
  • Run dotnet build
  • Run dotnet test

Installation

Use the package manager NuGet to install Dime.i18n:

dotnet add package Dime.i18n.{SubProjectName}

Usage

using System.Globalization;

[HttpGet]
public IEnumerable<Customer> Get()
{
     string timezone = CurrentUser.GetTimeZone(); // Fetch time zone from HTTP Context
     IEnumerable<Customer> customers = MyDbContext.Customers.ToList(); // Dates are stored in UTC

     UtcDateTimeConverter converter = new UtcDateTimeConverter(timezone);

     // Use custom extension called Tap to iterate through each item without changing the return type and object
     // The code inside the tap method is not necessarily a good practice but it shows the power of this library
     return customers.Tap(x => x.Date = converter.ConvertToLocalTime(x.Date));
}

[HttpGet]
public IEnumerable<Customer> GetWithExtension()
{
     string timezone = CurrentUser.GetTimeZone(); // Fetch time zone from HTTP Context
     IEnumerable<Customer> customers = MyDbContext.Customers.ToList(); // Dates in database should be stored in UTC

     // Use custom extension called Tap to iterate through each item without changing the return type and object
     // The code inside the tap method is not necessarily a good practice but it shows the power of this library
     return customers.Tap(x => x.Date = x.Date.ToLocal("America/New_York"));
}

Contributing

PRs Welcome

Pull requests are welcome. Please check out the contribution and code of conduct guidelines.

License

About

๐ŸŒ Makes internationalization in .NET just a little bit easier with a set of helper classes and methods.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages