Skip to content

Commit

Permalink
Merge pull request #3155 from ajpinedam/dev/anpi/add.localization
Browse files Browse the repository at this point in the history
feat: (macOS) Add support for Localization
  • Loading branch information
jeromelaban authored May 15, 2020
2 parents c6a9273 + a77611c commit 3643938
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Uno.UI/UI/Xaml/Application.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
using ObjCRuntime;
using Windows.Graphics.Display;
using Uno.UI.Services;
using System.Globalization;
using Uno.Extensions;
using Uno.Logging;
using System.Linq;

namespace Windows.UI.Xaml
{
Expand All @@ -18,6 +22,7 @@ public partial class Application : NSApplicationDelegate
public Application()
{
Current = this;
SetCurrentLanguage();
Windows.UI.Xaml.GenericStyles.Initialize();
ResourceHelper.ResourcesService = new ResourcesService(new[] { NSBundle.MainBundle });
}
Expand All @@ -33,8 +38,8 @@ static partial void StartPartial(ApplicationInitializationCallback callback)

public override void DidFinishLaunching(NSNotification notification)
{
InitializationCompleted();
OnLaunched(new LaunchActivatedEventArgs());
InitializationCompleted();
OnLaunched(new LaunchActivatedEventArgs());
}

/// <summary>
Expand Down Expand Up @@ -76,7 +81,23 @@ private ApplicationTheme GetDefaultSystemTheme()
else
{
return ApplicationTheme.Dark;
}
}
}

private void SetCurrentLanguage()
{
var language = NSLocale.PreferredLanguages.ElementAtOrDefault(0);

try
{
var cultureInfo = CultureInfo.CreateSpecificCulture(language);
CultureInfo.CurrentUICulture = cultureInfo;
CultureInfo.CurrentCulture = cultureInfo;
}
catch (Exception ex)
{
this.Log().Error($"Failed to set culture for language: {language}", ex);
}
}
}
}

0 comments on commit 3643938

Please sign in to comment.