Humanizer Localization Issue in Xamarin Forms

599 Views Asked by At

In a Xamarin.Forms app, I calling Humanizer from the Core (.Net Standard project) I'm using the Nugets Humanizer.Core and Humanizer.Core.ru package for Russian And calling it
DateTime.UtcNow.AddMinutes(-3).Humanize(culture: new CultureInfo("ru-Ru"));

And always I get english like 3 minutes ago

I tried apply:

CultureInfo ci = new CultureInfo("ru-Ru"); 
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;

And these not infleunt on a result, I get again english.

2

There are 2 best solutions below

0
On BEST ANSWER

I resolved the issue with the workaround.

  1. I removed from Nuget all Humanize packages.
  2. Follow to the packages directory: C:\Users\USERNAME\.nuget\packages
  3. Need to copy files Humanize dll's from next's folders:
  • humanizer.core\2.8.26\lib\netstandard2.0 (Humanizer.dll, Humanizer.xml)
  • humanizer.core.ru\2.8.26\lib\netstandard2.0 (copy folder "ru" with file - ru\Humanizer.resources.dll)
  1. Into my project folder I created CommonResources folder. Then I created Humanize folder into CommonResources and pasted 2 files and "ru" folder to my Humanize.

enter image description here

  1. Add references to PCL project yourProject.csproj file on these dll's.
  <ItemGroup> 
    .......
    <Reference Include="Humanizer.Core">
    <HintPath>..\..\CommonResources\Humanizer\Humanizer.dll</HintPath>
  </Reference> 
    <Reference Include="Humanizer.Core.ru">
    <HintPath>..\..\CommonResources\Humanizer\ru\Humanizer.resources.dll</HintPath>
  </Reference>
     ....... 
  <PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" /> 
</ItemGroup> 

enter image description here

After the dll files were added I got localized text into my project.

enter image description here

0
On

Thx @polyariz, I can confirm this still works with .NET MAUI, just copy the .dlls to the Resources folder... Manually added .dlls

and add them to the project via right-click on Dependencies and "Add Project Reference..." enter image description here