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";
34 public static void Initialize()
36 if (File.Exists(_pathCultureInfoXml))
40 ParseCultureInfoXml();
44 Log.Warn(LogTag, "Failed to parse CultureInfo.xml");
51 private static void ParseCultureInfoXml()
53 XmlDocument doc = new XmlDocument();
54 doc.Load(_pathCultureInfoXml);
55 XmlElement root = doc.DocumentElement;
56 foreach (XmlElement node in root.ChildNodes)
58 if (node.Name != "name" && node.FirstChild == null)
63 string lang = node.GetAttribute("xml:lang");
64 string cultureName = node.FirstChild.Value;
65 if (!string.IsNullOrEmpty(lang) && !string.IsNullOrEmpty(cultureName))
69 _cultureNames.Add(lang, cultureName);
71 catch (ArgumentException e)
73 Log.Error(LogTag, "ArgumentException: " + e.Message);
79 public static string GetCultureName(string locale)
88 if (_cultureNames.TryGetValue(locale.ToLowerInvariant(), out string cultureName))