[Common] Set the current CultureInfo 27/159727/7
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 Nov 2017 09:56:18 +0000 (18:56 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Mon, 13 Nov 2017 07:13:35 +0000 (07:13 +0000)
Change-Id: Ice96cb50dd762f2888e7ea90e61fb74eaa4eca75
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 786f4d5..d21efb1
@@ -15,7 +15,7 @@
  */
 
 using System;
-
+using System.Globalization;
 using Tizen.Applications.CoreBackend;
 
 namespace Tizen.Applications
@@ -194,6 +194,7 @@ namespace Tizen.Applications
         /// <since_tizen> 3 </since_tizen>
         protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
         {
+            ChangeCurrentCultureInfo(e.Locale);
             LocaleChanged?.Invoke(this, e);
         }
 
@@ -235,5 +236,72 @@ namespace Tizen.Applications
             }
             base.Dispose(disposing);
         }
+
+        private void ChangeCurrentCultureInfo(string locale)
+        {
+            string languageCode = string.Empty;
+            string localeCode = string.Empty;
+            CultureInfo currentCultureInfo = null;
+
+            if (locale.Contains("."))
+            {
+                locale = locale.Substring(0, locale.IndexOf("."));
+            }
+
+            if (locale.Contains("_"))
+            {
+                locale = locale.Replace("_", "-");
+            }
+
+            var dashIndex = locale.IndexOf("-", StringComparison.Ordinal);
+            if (dashIndex > 0)
+            {
+                var parts = locale.Split('-');
+                languageCode = parts[0];
+                localeCode = parts[1];
+            }
+            else
+            {
+                languageCode = locale;
+                localeCode = "";
+            }
+
+            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
+            {
+                if (ci.TwoLetterISOLanguageName == languageCode)
+                {
+                    if (localeCode == "")
+                    {
+                        if (ci.Name == languageCode)
+                        {
+                            currentCultureInfo = new CultureInfo(ci.Name);
+                            break;
+                        }
+                    }
+                    else
+                    {
+                        if (ci.Name.Contains(localeCode.ToUpper()))
+                        {
+                            currentCultureInfo = new CultureInfo(ci.Name);
+                            break;
+                        }
+                    }
+                }
+            }
+
+            if (currentCultureInfo == null)
+            {
+                try
+                {
+                    currentCultureInfo = new CultureInfo(languageCode);
+                }
+                catch (CultureNotFoundException)
+                {
+                    currentCultureInfo = new CultureInfo("en");
+                }
+            }
+
+            CultureInfo.CurrentCulture = currentCultureInfo;
+        }
     }
 }