Merge pull request #33 from nventive/dev/dr/LocalizationPatches

Mixed workaround to get Date calc and Converters to work with Uno
This commit is contained in:
David 2019-05-24 09:58:22 -04:00 committed by GitHub
commit 00ecbbf090
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 88 additions and 54 deletions

View file

@ -55,7 +55,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Uno.UI" Version="1.45.0-dev.1533" />
<PackageReference Include="Uno.UI" Version="1.45.0-dev.1550" />
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.32" />
</ItemGroup>
<ItemGroup>

View file

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using Windows.ApplicationModel.Resources.Core;
using Windows.Globalization;
@ -366,14 +367,15 @@ namespace CalculatorApp.Common
// as configured by running intl.cpl.
public static DecimalFormatter GetRegionalSettingsAwareDecimalFormatter()
{
IEnumerable<String> languageIdentifiers = GetLanguageIdentifiers();
if (languageIdentifiers != null)
{
return new DecimalFormatter(languageIdentifiers, GlobalizationPreferences.HomeGeographicRegion);
}
IEnumerable<String> languageIdentifiers = GetLanguageIdentifiers();
// TODO UNO
//if (languageIdentifiers != null)
//{
// return new DecimalFormatter(languageIdentifiers, GlobalizationPreferences.HomeGeographicRegion);
//}
return new DecimalFormatter();
}
return new DecimalFormatter();
}
// If successful, returns a formatter that respects the user's regional format settings,
// as configured by running intl.cpl.
@ -400,13 +402,16 @@ namespace CalculatorApp.Common
languageIdentifiers = ApplicationLanguages.Languages;
}
return new DateTimeFormatter(format, languageIdentifiers, GlobalizationPreferences.HomeGeographicRegion, calendarIdentifier, clockIdentifier);
}
//TODO UNO: return new DateTimeFormatter(format, languageIdentifiers, GlobalizationPreferences.HomeGeographicRegion, calendarIdentifier, clockIdentifier);
return new DateTimeFormatter(format, languageIdentifiers);
}
public static CurrencyFormatter GetRegionalSettingsAwareCurrencyFormatter()
{
string userCurrency =
(GlobalizationPreferences.Currencies.Count > 0) ? GlobalizationPreferences.Currencies[0] : DefaultCurrencyCode;
// TOOD UNO
//string userCurrency =
// (GlobalizationPreferences.Currencies.Count > 0) ? GlobalizationPreferences.Currencies[0] : DefaultCurrencyCode;
string userCurrency = DefaultCurrencyCode;
IEnumerable<string> languageIdentifiers = GetLanguageIdentifiers();
if (languageIdentifiers == null)
@ -414,7 +419,8 @@ namespace CalculatorApp.Common
languageIdentifiers = ApplicationLanguages.Languages;
}
var currencyFormatter = new CurrencyFormatter(userCurrency, languageIdentifiers, GlobalizationPreferences.HomeGeographicRegion);
// TODO UNO: var currencyFormatter = new CurrencyFormatter(userCurrency, languageIdentifiers, GlobalizationPreferences.HomeGeographicRegion);
var currencyFormatter = new CurrencyFormatter(userCurrency);
int fractionDigits = LocalizationSettings.GetInstance().GetCurrencyTrailingDigits();
currencyFormatter.FractionDigits = fractionDigits;
@ -424,7 +430,8 @@ namespace CalculatorApp.Common
static IEnumerable<String> GetLanguageIdentifiers()
{
return GlobalizationPreferences.Languages;
// TODO UNO: return GlobalizationPreferences.Languages;
return new[] { CultureInfo.CurrentCulture.IetfLanguageTag };
}
// Resources for the engine use numbers as keys. It's inconvenient, but also difficult to

View file

@ -23,29 +23,34 @@ namespace CalculatorApp
public NetworkManager()
{
NetworkInformation.NetworkStatusChanged += new NetworkStatusChangedEventHandler(OnNetworkStatusChange);
// TODO: UNO (Not implemented)
//NetworkInformation.NetworkStatusChanged += new NetworkStatusChangedEventHandler(OnNetworkStatusChange);
}
~NetworkManager()
{
NetworkInformation.NetworkStatusChanged -= OnNetworkStatusChange;
// TODO: UNO (Not implemented)
//NetworkInformation.NetworkStatusChanged -= OnNetworkStatusChange;
}
public static NetworkAccessBehavior GetNetworkAccessBehavior()
{
NetworkAccessBehavior behavior = NetworkAccessBehavior.Offline;
ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
if (connectionProfile != null)
{
NetworkConnectivityLevel connectivityLevel = connectionProfile.GetNetworkConnectivityLevel();
if (connectivityLevel == NetworkConnectivityLevel.InternetAccess || connectivityLevel == NetworkConnectivityLevel.ConstrainedInternetAccess)
{
ConnectionCost connectionCost = connectionProfile.GetConnectionCost();
behavior = ConvertCostInfoToBehavior(connectionCost);
}
}
// TODO: UNO (Not implemented)
return NetworkAccessBehavior.Normal;
return behavior;
//NetworkAccessBehavior behavior = NetworkAccessBehavior.Offline;
//ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
//if (connectionProfile != null)
//{
// NetworkConnectivityLevel connectivityLevel = connectionProfile.GetNetworkConnectivityLevel();
// if (connectivityLevel == NetworkConnectivityLevel.InternetAccess || connectivityLevel == NetworkConnectivityLevel.ConstrainedInternetAccess)
// {
// ConnectionCost connectionCost = connectionProfile.GetConnectionCost();
// behavior = ConvertCostInfoToBehavior(connectionCost);
// }
//}
//return behavior;
}
void OnNetworkStatusChange(object sender)

View file

@ -21,6 +21,7 @@ using SelectedUnits = System.Collections.Generic.KeyValuePair<string, string>;
using CategorySelectionInitializer = System.Tuple<CalculatorApp.CalculatorList<UnitConversionManager.Unit>, UnitConversionManager.Unit, UnitConversionManager.Unit>;
using UnitToUnitToConversionDataMap = System.Collections.Generic.Dictionary<UnitConversionManager.Unit, System.Collections.Generic.Dictionary<UnitConversionManager.Unit, UnitConversionManager.ConversionData>>;
using CategoryToUnitVectorMap = System.Collections.Generic.Dictionary<UnitConversionManager.Category, CalculatorApp.CalculatorList<UnitConversionManager.Unit>>;
using System.Globalization;
namespace CalculatorApp.ViewModel
{
@ -140,10 +141,12 @@ namespace CalculatorApp.ViewModel
this.m_meteredOverrideSet = false;
if (GlobalizationPreferences.Languages.Count > 0)
{
m_responseLanguage = GlobalizationPreferences.Languages[0];
}
// TODO UNO
//if (GlobalizationPreferences.Languages.Count > 0)
//{
// m_responseLanguage = GlobalizationPreferences.Languages[0];
//}
m_responseLanguage = CultureInfo.CurrentCulture.IetfLanguageTag;
if (m_client != null)
{
@ -151,11 +154,13 @@ namespace CalculatorApp.ViewModel
m_client.SetResponseLanguage(m_responseLanguage);
}
if (CoreWindow.GetForCurrentThread() != null)
{
// Must have a CoreWindow to access the resource context.
m_isRtlLanguage = LocalizationService.GetInstance().IsRtlLayout();
}
// TODO UNO
//if (CoreWindow.GetForCurrentThread() != null)
//{
// // Must have a CoreWindow to access the resource context.
// m_isRtlLanguage = LocalizationService.GetInstance().IsRtlLayout();
//}
m_isRtlLanguage = true;
m_ratioFormatter = LocalizationService.GetRegionalSettingsAwareDecimalFormatter();
m_ratioFormatter.IsGrouped = true;
@ -311,7 +316,8 @@ namespace CalculatorApp.ViewModel
double rounded = (int)(ratio * (int)(scale)) / scale;
string digitSymbol = LocalizationSettings.GetInstance().GetDigitSymbolFromEnUsDigit('1').ToString();
string roundedFormat = m_ratioFormatter.Format(rounded);
// TODO UNO: string roundedFormat = m_ratioFormatter.Format(rounded);
string roundedFormat = rounded.ToString(CultureInfo.CurrentCulture);
string ratioString = LocalizationStringUtil.GetLocalizedString(
m_ratioFormat,

View file

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using Windows.Globalization;
@ -114,7 +115,9 @@ namespace CalculatorApp.ViewModel
public UnitConverterDataLoader(GeographicRegion region)
{
m_currentRegionCode = region.CodeTwoLetter;
// TODO UNO
//m_currentRegionCode = region.CodeTwoLetter;
m_currentRegionCode = new RegionInfo(CultureInfo.CurrentCulture.LCID).TwoLetterISORegionName;
m_categoryList = new CalculatorList<UCM.Category>();
m_categoryToUnits = new CategoryToUnitVectorMap(EqualityComparer<UCM.Category>.Default);

View file

@ -13,6 +13,7 @@ using CalculatorApp.Common.DateCalculation;
using Windows.Foundation;
using System.Numerics;
using CalculatorApp;
using System.Globalization;
namespace CalculatorApp.ViewModel
{
@ -70,7 +71,7 @@ namespace CalculatorApp.ViewModel
m_dateCalcEngine = new DateCalculationEngine(localizationSettings.GetCalendarIdentifier());
// Initialize dates of DatePicker controls to today's date
var calendar = new Calendar();
var calendar = new Windows.Globalization.Calendar();
var today = calendar.GetDateTime().DateTime;
// FromDate and ToDate should be clipped (adjusted to a consistent hour in UTC)
@ -126,7 +127,7 @@ namespace CalculatorApp.ViewModel
PropertyChanged += (snd, e) => ((DateCalculatorViewModel)snd).OnPropertyChanged(e.PropertyName);
}
static void CheckClipTimeSameDay(Calendar reference)
static void CheckClipTimeSameDay(Windows.Globalization.Calendar reference)
{
}
@ -473,7 +474,8 @@ namespace CalculatorApp.ViewModel
else
{
// Display the resulting date in long format
StrDateResult = m_dateTimeFormatter.Format(DateResult);
//TODO UNO: StrDateResult = m_dateTimeFormatter.Format(DateResult);
StrDateResult = DateResult.ToString(CultureInfo.CurrentCulture);
}
}
}
@ -637,7 +639,7 @@ namespace CalculatorApp.ViewModel
private static DateTime ClipTime(DateTime dateTime)
{
var calendar = new Calendar();
var calendar = new Windows.Globalization.Calendar();
calendar.SetDateTime(dateTime);
calendar.Period = 1;
calendar.Hour = 12;

View file

@ -29,6 +29,7 @@ using UCM = UnitConversionManager;
using CategorySelectionInitializer = System.Tuple<CalculatorApp.CalculatorList<UnitConversionManager.Unit>, UnitConversionManager.Unit, UnitConversionManager.Unit>;
using UnitToUnitToConversionDataMap = System.Collections.Generic.Dictionary<UnitConversionManager.Unit, System.Collections.Generic.Dictionary<UnitConversionManager.Unit, UnitConversionManager.ConversionData>>;
using CategoryToUnitVectorMap = System.Collections.Generic.Dictionary<UnitConversionManager.Category, CalculatorApp.CalculatorList<UnitConversionManager.Unit>>;
using System.Globalization;
namespace CalculatorApp.ViewModel
{
@ -885,7 +886,8 @@ namespace CalculatorApp.ViewModel
m_currencyFormatter.IsGrouped = true;
m_currencyFormatter.Mode = CurrencyFormatterMode.UseCurrencyCode;
m_currencyFormatter.ApplyRoundingForCurrency(RoundingAlgorithm.RoundHalfDown);
m_currencyMaxFractionDigits = m_currencyFormatter.FractionDigits;
//TODO UNO: m_currencyMaxFractionDigits = m_currencyFormatter.FractionDigits;
m_currencyMaxFractionDigits = 2;
var resourceLoader = AppResourceProvider.GetInstance();
m_localizedValueFromFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys.ValueFromFormat);
@ -1086,8 +1088,11 @@ namespace CalculatorApp.ViewModel
if (IsCurrencyCurrentCategory)
{
string currencyResult = m_currencyFormatter.Format(System.Convert.ToDouble(stringToLocalize));
string currencyCode = m_currencyFormatter.Currency;
// TODO UNO:
// string currencyResult = m_currencyFormatter.Format(System.Convert.ToDouble(stringToLocalize));
// string currencyCode = m_currencyFormatter.Currency;
string currencyResult = System.Convert.ToDouble(stringToLocalize).ToString(CultureInfo.CurrentCulture);
string currencyCode = "TODO UNO";
// CurrencyFormatter always includes LangCode or Symbol. Make it include LangCode
// because this includes a non-breaking space. Remove the LangCode.
@ -1105,7 +1110,9 @@ namespace CalculatorApp.ViewModel
{
// Convert the input string to double using stod
// Then use the decimalFormatter to reformat the double to Platform String
result = m_decimalFormatter.Format(System.Convert.ToDouble(stringToLocalize));
// TODO UNO
//result = m_decimalFormatter.Format(System.Convert.ToDouble(stringToLocalize));
result = System.Convert.ToDouble(stringToLocalize).ToString(CultureInfo.CurrentCulture);
}
if (hasDecimal)
@ -1113,7 +1120,9 @@ namespace CalculatorApp.ViewModel
// Since the output from GetLocaleInfoEx() and DecimalFormatter are differing for decimal string
// we are adding the below work-around of editing the string returned by DecimalFormatter
// and replacing the decimal separator with the one returned by GetLocaleInfoEx()
String formattedSampleString = m_decimalFormatter.Format(System.Convert.ToDouble("1.1"));
// TODO UNO
//String formattedSampleString = m_decimalFormatter.Format(System.Convert.ToDouble("1.1"));
String formattedSampleString = 1.1.ToString(CultureInfo.CurrentCulture);
string formattedSampleWString = formattedSampleString;
string resultWithDecimal = result;

View file

@ -14,6 +14,7 @@ using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Controls;
using CalculatorApp.Common;
using CalculatorApp.ViewModel;
using System.Globalization;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
@ -50,7 +51,7 @@ namespace CalculatorApp
DateDiff_ToDate.Language = localizationSettings.GetLocaleName();
// Set Min and Max Dates according to the Gregorian Calendar(1601 & 9999)
var calendar = new Calendar();
var calendar = new Windows.Globalization.Calendar();
var today = calendar.GetDateTime();
calendar.ChangeCalendarSystem(CalendarIdentifiers.Gregorian);
@ -77,9 +78,10 @@ namespace CalculatorApp
DateDiff_FromDate.DateFormat = "day month year";
DateDiff_ToDate.DateFormat = "day month year";
var placeholderText = dateTimeFormatter.Format(today);
//TODO UNO: var placeholderText = dateTimeFormatter.Format(today);
var placeholderText = today.ToString("day month year", CultureInfo.CurrentCulture);
DateDiff_FromDate.PlaceholderText = placeholderText;
DateDiff_FromDate.PlaceholderText = placeholderText;
DateDiff_ToDate.PlaceholderText = placeholderText;
// TODO UNO

View file

@ -9,7 +9,7 @@
<Version>4.3.1</Version>
</PackageReference>
<PackageReference Include="Uno.UI">
<Version>1.45.0-dev.1533</Version>
<Version>1.45.0-dev.1550</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup>

View file

@ -36,7 +36,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
<PackageReference Include="Uno.UI" Version="1.45.0-dev.1533" />
<PackageReference Include="Uno.UI" Version="1.45.0-dev.1550" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="1.0.0-dev.278" />
<DotNetCliToolReference Include="Uno.Wasm.Bootstrap.Cli" Version="1.0.0-dev.276" />
</ItemGroup>

View file

@ -190,7 +190,7 @@
<BundleResource Include="Resources\Fonts\winjs-symbols.ttf" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Uno.UI" Version="1.45.0-dev.1533" />
<PackageReference Include="Uno.UI" Version="1.45.0-dev.1550" />
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'iPhoneSimulator' ">
<NativeReference Include="NativeReferences/x86_64/libCalcManager.a">