Humanizr / Humanizer

Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TimeUnit.ToSymbol() don't take culture into account

abouroubi opened this issue · comments

I have a use case where need to humanize a number to and then append /hour or /day depending on a TimeUnit variable.
Unfortunately using timeUnit.ToSymbol(CultureInfo.GetCultureInfo("ja")) always return 'd' for day and 'h' for hour. Not taking into account the locale I use.

Is there a way to get the translated day hour from a TimeUnit variable ?

commented

It uses the culture, but doesn't have a lot of translations present for Japanese.

using System;
using System.Globalization;
using Humanizer;
using Humanizer.Localisation;
					
public class Program
{
	public static void Main()
	{
		var timeUnit = TimeUnit.Week;
		Console.WriteLine(timeUnit.ToSymbol());
		Console.WriteLine(timeUnit.ToSymbol(CultureInfo.GetCultureInfo("ja")));
		Console.WriteLine(timeUnit.ToSymbol(CultureInfo.GetCultureInfo("es")));
		Console.WriteLine(timeUnit.ToSymbol(CultureInfo.GetCultureInfo("de")));
	}
}

with the current Humanizer release outputs

week
week
semana
Woche

If you feel like it, you could add them to https://github.com/Humanizr/Humanizer/blob/23c4c2a526deb0f101b39fe060fca66f5e66c823/src/Humanizer/Properties/Resources.ja.resx based on the resource file for English: https://github.com/Humanizr/Humanizer/blob/1bdd7a1bad03fd001d04fc0e252d279b4e785818/src/Humanizer/Properties/Resources.resx#L714C1-L737
If you do so, it would be great if you could add some tests, for example based on https://github.com/Humanizr/Humanizer/blob/689802b55f94ccb8e4e8d33b121f36b85d9e7108/src/Humanizer.Tests.Shared/Localisation/de/TimeUnitToSymbolTests.cs, too. :)

OK I understand, I tried with few other languages and all of them don't have the translation.
I'll add the ones I know thanks.