Match LocaleCountry with LocaleLanguage
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 30 Jul 2020 10:46:14 +0000 (12:46 +0200)
committerLukasz Stanislawski <lukasz.stanislawski@gmail.com>
Thu, 30 Jul 2020 23:12:45 +0000 (01:12 +0200)
When setting language the LocaleLanguage and LocaleCountry should be
equal. Use custom setting to represent selected country.

Change-Id: I5322d6f7688ef8c29b4e729a78b30dfb6dc89aa3

Oobe/Oobe.Common/Services/Settings.cs [new file with mode: 0644]
Oobe/Oobe.Language/Model/LanguageManger.cs
Oobe/Oobe.Region/Model/RegionManager.cs
Oobe/Oobe.Region/res/regions_OOBE.xml
Oobe/Oobe.Terms/Model/TermsProvider.cs
Oobe/Oobe.Terms/res/terms/GB.txt [moved from Oobe/Oobe.Terms/res/terms/en_GB.txt with 100% similarity]
Oobe/Oobe.Terms/res/terms/KR.txt [moved from Oobe/Oobe.Terms/res/terms/ko_KR.txt with 100% similarity]
Oobe/Oobe.Terms/res/terms/PL.txt [moved from Oobe/Oobe.Terms/res/terms/pl_PL.txt with 100% similarity]

diff --git a/Oobe/Oobe.Common/Services/Settings.cs b/Oobe/Oobe.Common/Services/Settings.cs
new file mode 100644 (file)
index 0000000..d7e8ddb
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using Tizen.System;
+using Tizen.Applications;
+
+namespace Oobe.Common.Services
+{
+    public static class Settings
+    {
+        private const string CountryCodeKey = "country_code";
+
+        /// <summary>
+        /// Current device language
+        /// in <LANGUAGE>_<REGION> syntax. The country setting is in the ISO 639-2 format, and the region setting is in the ISO 3166-1 alpha-2 format
+        /// </summary>
+        public static string Language
+        {
+            get
+            {
+                return SystemSettings.LocaleLanguage;
+            }
+
+            set
+            {
+                SystemSettings.LocaleLanguage = value;
+                SystemSettings.LocaleCountry = value;
+            }
+        }
+
+        /// <summary>
+        /// Country code in ISO 3166-1 alpha-2.
+        /// </summary>
+        public static string Country
+        {
+            get
+            {
+                if (Preference.Contains(CountryCodeKey))
+                {
+                    return Preference.Get<string>(CountryCodeKey);
+                }
+                return String.Empty;
+            }
+
+            set
+            {
+                Preference.Set(CountryCodeKey, value);
+            }
+        }
+    }
+}
index c347b17..1f760ac 100644 (file)
  */
 
 using System.Collections.Generic;
-using Tizen.System;
 using System.Linq;
 using System.IO;
 using System.Xml.Serialization;
+using Oobe.Common.Services;
 
 namespace Oobe.Language.Model
 {
@@ -42,13 +42,13 @@ namespace Oobe.Language.Model
         {
             get
             {
-                return Languages.FirstOrDefault(s => s.Code == SystemSettings.LocaleLanguage) ?? Languages.FirstOrDefault();
+                return Languages.FirstOrDefault(s => s.Code == Settings.Language) ?? Languages.FirstOrDefault();
             }
             set
             {
                 if (value != null)
                 {
-                    SystemSettings.LocaleLanguage = value.Code;
+                    Settings.Language = value.Code;
                 }
             }
         }
index 46e004c..c40cf7c 100644 (file)
@@ -18,7 +18,6 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Xml.Serialization;
-using Tizen.System;
 using Oobe.Common.Services;
 using System;
 
@@ -44,13 +43,13 @@ namespace Oobe.Region.Model
         {
             get
             {
-                return Regions.FirstOrDefault(s => s.CountryCode == SystemSettings.LocaleCountry) ?? Regions.FirstOrDefault();
+                return Regions.FirstOrDefault(s => s.CountryCode == Settings.Country) ?? Regions.FirstOrDefault();
             }
             set
             {
                 if (value != null)
                 {
-                    SystemSettings.LocaleCountry = value.CountryCode;
+                    Settings.Country = value.CountryCode;
                 }
             }
         }
index 86dc33f..3003dd7 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
 <regions>
-  <region code="en_GB" name_en="UNITED_KINGDOM" />
-  <region code="ko_KR" name_en="SOUTH_KOREA" />
+  <region code="GB" name_en="UNITED_KINGDOM" />
+  <region code="KR" name_en="SOUTH_KOREA" />
 </regions>
index 1e5e830..b97d4f2 100644 (file)
@@ -16,7 +16,7 @@
 
 using System;
 using System.IO;
-using Tizen.System;
+using Oobe.Common.Services;
 
 namespace Oobe.Terms.Model
 {
@@ -30,7 +30,7 @@ namespace Oobe.Terms.Model
         public string LoadTerms()
         {
             string terms = null;
-            var locale = SystemSettings.LocaleCountry;
+            var locale = Settings.Country;
             var filename = Path.Combine(Tizen.Applications.CoreApplication.Current.DirectoryInfo.Resource , "terms" , locale + ".txt");
 
             try {