Files
Sleep-Multi-functionality/Data/LanguageManager.cs
2026-05-09 10:14:24 +08:00

30 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace .Data
{
public static class LanguageManager
{
// 私有静态变量,只在首次访问时初始化一次
private static readonly string _currentLanguage;
// 静态构造函数:程序启动时自动执行一次,读取配置
static LanguageManager()
{
// 读取配置文件的Language值没有的话默认zh-CN
_currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
}
// 对外只读的全局属性,项目任何地方都能直接调用
public static string CurrentLanguage => _currentLanguage;
// 可选:给个更方便的判断属性,不用每次都写==判断
public static bool IsEnglish => _currentLanguage == "en-US";
public static bool IsChinese => _currentLanguage == "zh-CN";
}
}