从卫星程序集中获取所有受支持的文化

发布于 2024-07-07 04:52:14 字数 105 浏览 7 评论 0原文

我正在使用卫星程序集来保存 C# 应用程序中的所有本地化资源。

我需要做的是在 GUI 中创建一个菜单,其中包含应用程序现有的所有可用语言。 有什么办法可以动态获取信息吗?

I am using a satellite assembly to hold all the localization resources in a C# application.

What I need to do is create a menu in the GUI with all the available languages that exists for the application. Is there any way to get information dynamically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的心境我的脸 2024-07-14 04:52:14

此函数返回 App_GlobalResources 文件夹中所有已安装区域性的数组 - 根据您的需要更改搜索路径。
对于不变的文化,它返回“auto”。

public static string[] GetInstalledCultures()
{
    List<string> cultures = new List<string>();
    foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath("/App_GlobalResources"), \\Change folder to search in if needed.
        "*.resx", SearchOption.TopDirectoryOnly))
    {
        string name = file.Split('\\').Last();
        name = name.Split('.')[1];

        cultures.Add(name != "resx" ? name : "auto"); \\Change "auto" to something else like "en-US" if needed.
    }
    return cultures.ToArray();
}

您还可以使用此功能来获取完整的 CultureInfo 实例的更多功能:

public static CultureInfo[] GetInstalledCultures()
{
    List<CultureInfo> cultures = new List<CultureInfo>();
    foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath("/App_GlobalResources"), "*.resx", SearchOption.TopDirectoryOnly))
    {
        string name = file.Split('\\').Last();
        name = name.Split('.')[1];

     string culture = name != "resx" ? name : "en-US";
     cultures.Add(new CultureInfo(culture));
    }
    return cultures.ToArray();
}

This function returns an array of all the installed cultures in the App_GlobalResources folder - change search path according to your needs.
For the invariant culture it returns "auto".

public static string[] GetInstalledCultures()
{
    List<string> cultures = new List<string>();
    foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath("/App_GlobalResources"), \\Change folder to search in if needed.
        "*.resx", SearchOption.TopDirectoryOnly))
    {
        string name = file.Split('\\').Last();
        name = name.Split('.')[1];

        cultures.Add(name != "resx" ? name : "auto"); \\Change "auto" to something else like "en-US" if needed.
    }
    return cultures.ToArray();
}

You could also use this one for more functionality getting the full CultureInfo instances:

public static CultureInfo[] GetInstalledCultures()
{
    List<CultureInfo> cultures = new List<CultureInfo>();
    foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath("/App_GlobalResources"), "*.resx", SearchOption.TopDirectoryOnly))
    {
        string name = file.Split('\\').Last();
        name = name.Split('.')[1];

     string culture = name != "resx" ? name : "en-US";
     cultures.Add(new CultureInfo(culture));
    }
    return cultures.ToArray();
}
鹊巢 2024-07-14 04:52:14

特定语言的每个附属程序集都具有相同的名称,但位于以特定文化命名的子文件夹中,例如 fr 或 fr-CA。
也许您可以利用这一事实并扫描文件夹层次结构来动态构建该菜单。

Each satellite assembly for a specific language is named the same but lies in a sub-folder named after the specific culture e.g. fr or fr-CA.
Maybe you can use this fact and scan the folder hierarchy to build up that menu dynamically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文