C#で作成したアプリを、複数の言語で表示したい場合の作成方法。
また忘れそうなので備忘録として。。
言語ごとの文字列情報
日本語、英語、中国語、韓国語・・・など言語ごとの情報はソリューションエクスプローラーの
プロジェクト>Properties>Resources.resx に保存する。
デフォルト言語(通常は英語)は、”Resources.resx”に保存しておき、
他の言語は別ファイルとして同様のファイルを保存する。
例えば、日本語の場合は、”Resources.ja-JP.resx”など。
で、これらリソースの中に各言語の変数と文言を定義しておく。
例)
今回の例では、2つの文言(変数)を定義。
ちなみに、リソースの追加は、ソリューションエクスプローラのツリーでプロジェクトを右クリックして「追加」>「新しい項目」ポップアップメニューを選択し、下記「新しい項目の追加」ダイアログで「リソースファイル」を選択し追加する。

プログラムソース
上記Resourcesで定義したSelectLanguageと、Messageをプログラムから呼び出す。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using WindowsFormsApp1.Properties;
using System.Globalization;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.Items.Add("English");
comboBox1.Items.Add("Japanese");
comboBox1.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox1.Text)
{
case "Japanese":
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ja-JP");
break;
case "English":
default:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("");
break;
}
label1.Text = Resources.SelectLanguage;
label2.Text = Resources.Message;
}
}
}
デザイン
Formのデザインは、以下の通り。
ラベル2つと、コンボボックスを配置しておく。

実行
<追記>
おまけで、OSの言語を調べる方法。
最初からOS言語をある程度調べて、デフォルトで選択したい場合など。
MessageBox.Show(
CultureInfo.CurrentCulture.TwoLetterISOLanguageName + "\n" +
CultureInfo.CurrentCulture.IetfLanguageTag + "\n" +
CultureInfo.CurrentCulture.NativeName
);
実行例:
| 日本語 | 英語 |
![]() |
![]() |
更に発展して、OSの表示言語を基に、自動的に表示切り替えしたい場合
// Windowsの表示言語をもとにアプリの表示言語も切り替え
switch (CultureInfo.CurrentCulture.IetfLanguageTag)
{
case "ja-JP":
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ja-JP");
break;
default:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("");
break;
}
デフォルトの言語表示は上記処理として、更にユーザーが自分で選べるように設定画面で切り替えられると尚更良い。
ダウンロード
| バージョン | 公開日 | カウンタ |
|---|---|---|
| 1.0 | 2025/03/30 | 550 |











