using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
namespace UAS_MES_NEW.I18n
{
///
/// 多语言管理器(全球化基础设施,支持 中文/英文/越南文/印度文)。
/// 设计要点:
/// 1) 字典的 key 直接使用「中文源文」,因此无需为每个控件手工起名;
/// 2) T(key) 查询当前语言→默认语言(zh)→原文(带回退),缺失时显示原文,界面永不空白;
/// 3) Localize(Form/Control) 递归遍历控件树(含菜单、页签、网格列头、DevExpress Caption),
/// 并记录每个控件首次的中文文本,使运行时切换语言可正确来回还原。
///
public static class LanguageManager
{
// 嵌入资源逻辑名:根命名空间.I18n.Lang.xml
private static readonly string ResourceName =
typeof(LanguageManager).Namespace + ".Lang.xml";
// 嵌入资源逻辑名:根命名空间.I18n.Templates.xml
private static readonly string TemplatesResourceName =
typeof(LanguageManager).Namespace + ".Templates.xml";
// code -> (中文源文 -> 译文)
private static readonly Dictionary> _dict =
new Dictionary>();
// 动态错误模板列表(中文正则 -> 各语言模板)
private static readonly List _templates =
new List();
// code -> 显示名(如 中文 / English)
private static readonly Dictionary _langNames =
new Dictionary();
private static string _currentCulture = "zh";
private static string _defaultCulture = "zh";
/// 支持的语言:code -> 显示名。顺序与 Lang.xml 中一致。
public static Dictionary SupportedLanguages { get; private set; }
/// 语言切换后触发,供已打开的窗体重新本地化自身。
public static event EventHandler LanguageChanged;
// 记录控件/菜单项首次出现的中文文本,用于语言来回切换时还原源文
private static readonly Dictionary