--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class LibIniParser
+ {
+ [DllImport(Libraries.IniParser, EntryPoint = "iniparser_getstring", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern IntPtr GetString(IntPtr d, string key, IntPtr def);
+
+ [DllImport(Libraries.IniParser, EntryPoint = "iniparser_load", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern IntPtr Load(string iniName);
+
+ [DllImport(Libraries.IniParser, EntryPoint = "iniparser_freedict", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern void FreeDict(IntPtr d);
+ }
+}
\ No newline at end of file
*/
using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Xml;
-using Tizen;
+using System.Runtime.InteropServices;
namespace Tizen.Applications
{
internal static class CultureInfoHelper
{
- private const string LogTag = "Tizen.Applications";
- private static bool _initialized = false;
- private static readonly Dictionary<string, string> _cultureNames = new Dictionary<string, string>();
- private static readonly object _lock = new object();
- private const string _pathCultureInfoXml = "/usr/share/dotnet.tizen/framework/i18n/CultureInfo.xml";
+ private const string _pathCultureInfoIni = "/usr/share/dotnet.tizen/framework/i18n/CultureInfo.ini";
- public static void Initialize()
- {
- if (File.Exists(_pathCultureInfoXml))
- {
- try
- {
- ParseCultureInfoXml();
- }
- catch
- {
- Log.Warn(LogTag, "Failed to parse CultureInfo.xml");
- }
- }
-
- _initialized = true;
- }
-
- private static void ParseCultureInfoXml()
+ public static string GetCultureName(string locale)
{
- XmlDocument doc = new XmlDocument();
- doc.Load(_pathCultureInfoXml);
- XmlElement root = doc.DocumentElement;
- foreach (XmlElement node in root.ChildNodes)
+ IntPtr dictionary = Interop.LibIniParser.Load(_pathCultureInfoIni);
+ if (dictionary == IntPtr.Zero)
{
- if (node.Name != "name" && node.FirstChild == null)
- {
- continue;
- }
-
- string lang = node.GetAttribute("xml:lang");
- string cultureName = node.FirstChild.Value;
- if (!string.IsNullOrEmpty(lang) && !string.IsNullOrEmpty(cultureName))
- {
- try
- {
- _cultureNames.Add(lang, cultureName);
- }
- catch (ArgumentException e)
- {
- Log.Error(LogTag, "ArgumentException: " + e.Message);
- }
- }
+ return string.Empty;
}
- }
- public static string GetCultureName(string locale)
- {
- lock (_lock)
+ string cultureName = string.Empty;
+ string key = "CultureInfo:" + locale.ToLowerInvariant();
+ IntPtr value = Interop.LibIniParser.GetString(dictionary, key, IntPtr.Zero);
+ if (value != IntPtr.Zero)
{
- if (!_initialized)
- {
- Initialize();
- }
-
- if (_cultureNames.TryGetValue(locale.ToLowerInvariant(), out string cultureName))
- {
- return cultureName;
- }
+ cultureName = Marshal.PtrToStringAnsi(value);
}
- return string.Empty;
+ Interop.LibIniParser.FreeDict(dictionary);
+ return cultureName;
}
}
}