2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.Globalization;
24 namespace Tizen.Applications
26 internal static class CultureInfoHelper
28 private const string LogTag = "Tizen.Applications";
29 private static bool _initialized = false;
30 private static readonly Dictionary<string, string> _cultureNames = new Dictionary<string, string>();
31 private static readonly object _lock = new object();
32 private const string _pathCultureInfoXml = "/usr/share/dotnet.tizen/framework/i18n/CultureInfo.xml";
33 private static readonly CultureInfo _cultureInfo = new CultureInfo("en-US");
35 public static void Initialize()
37 if (File.Exists(_pathCultureInfoXml))
41 ParseCultureInfoXml();
45 Log.Warn(LogTag, "Failed to parse CultureInfo.xml");
52 private static void ParseCultureInfoXml()
54 XmlDocument doc = new XmlDocument();
55 doc.Load(_pathCultureInfoXml);
56 XmlElement root = doc.DocumentElement;
57 foreach (XmlElement node in root.ChildNodes)
59 if (node.Name != "name" && node.FirstChild == null)
64 string lang = node.GetAttribute("xml:lang");
65 string cultureName = node.FirstChild.Value;
66 if (!string.IsNullOrEmpty(lang) && !string.IsNullOrEmpty(cultureName))
70 _cultureNames.Add(lang, cultureName);
72 catch (ArgumentException e)
74 Log.Error(LogTag, "ArgumentException: " + e.Message);
80 public static string GetCultureName(string locale)
89 if (_cultureNames.TryGetValue(locale.ToLower(_cultureInfo), out string cultureName))