1

私の C#/WF アプリケーションでは、言語ごとに異なるいくつかのファイルを使用しています。これらのファイルは、サテライト アセンブリのリソースとして配置できません。ただし、サテライト アセンブリと同じディレクトリに配置したいのですが、実際にアセンブリがどこにあるかを知る必要があります (バイナリ ファイルに埋め込まれた既定の言語が使用されている場合の状況を含む)。

たとえば、アプリケーションが自動的にポーランド語に切り替わったときに、場所を取得したいと考えています。

D:\<アプリフォルダー>\pl-PL\

そうする方法はありますか?フォルダーの場所を推測するのではなく、アセンブリからこの情報を取得したいことに注意してください。


Steve B の助けを借りて、ここに解決策があります。

string FindSatelliteAssemblyLocation(CultureInfo culture)
{
    if (culture == CultureInfo.InvariantCulture)
        return Path.GetDirectoryName(Application.ExecutablePath);

    try
    {
        Uri location = new Uri(Assembly.GetExecutingAssembly().GetSatelliteAssembly(culture).CodeBase);
        return Path.GetDirectoryName(location.LocalPath);
    }
    catch
    {
        return FindSatelliteAssemblyLocation(culture.Parent);
    }
}
4

2 に答える 2

1

現在のスレッド UI カルチャを使用して言語を取得できます。

var subfolder = System.Threading.Thread.CurrentUICulture.Name;
于 2012-11-06T16:52:41.537 に答える
-1

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)との組み合わせを使用して、CultureInfo.CurrentUICultureこれを理解 できると思います。

たとえば、アセンブリが C:\Program Files\MyCompany\App\ にあり、現在の UI カルチャが en_US である場合、2 つを組み合わせることができます。

string exeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
string culture = CultureInfo.CurrentUICulture.Name;

string langDir = System.IO.Path.Combine(exeDir, culture);

「C:\Program Files\MyCompany\App\en_US」を作成するには

于 2012-11-06T16:55:29.590 に答える