「文字コード」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎ターミナル: 差し替え)
(add TranslationStatus.)
 
(同じ利用者による、間の5版が非表示)
16行目: 16行目:
 
* [[xterm]] - Run with the argument {{ic|-u8}} or configure resource {{ic|xterm*utf8: 2}}.
 
* [[xterm]] - Run with the argument {{ic|-u8}} or configure resource {{ic|xterm*utf8: 2}}.
   
=== Unicode character insertion ===
+
=== ユニコード文字の挿入 ===
See [[List_of_applications/Utilities#Text_input]].
 
* [[Libreoffice]] includes a built-in charmap in ''Insert > Special Character'' showing character block, hex, and decimal encodings.
 
* [[Xorg/Keyboard_configuration#Configuring_compose_key|Compose Key]]: XCompose can be set up to insert special characters.
 
* [[Xorg/Keyboard_configuration#Configuring_AltGr|AltGr]] can be set up to access additional keyboard levels providing extra characters as well as Unicode control characters such as [https://en.wikipedia.org/wiki/Zwnj ZWNJ] and [https://en.wikipedia.org/wiki/Right-to-left_mark RTL mark].
 
   
  +
[[アプリケーション一覧/ユーティリティ#テキスト入力]]を参照してください。
== URL encoding ==
 
  +
* [[LibreOffice]] には、''挿入 > 特殊文字'' に組み込みのキャラクターマップがあり、文字ブロック、16 進、10 進エンコーディングが表示されます。
  +
* [[Xorg/キーボード設定#コンポーズキーの設定|Compose キー]]: XCompose を設定して特殊文字を挿入することができます。
  +
* [[Xorg/キーボード設定#AltGrの設定|AltGr]] を設定して、追加のキーボードレベルにアクセスし、ZWNJ や RTL マークなどの Unicode 制御文字を含む追加の文字を入力できます。
   
  +
== URL エンコード ==
URIs accept US-ASCII characters only and use [[Wikipedia:percent-encoding|percent-encoding]] to encode non-ASCII characters. This can result in very long and human-unreadable URIs.
 
   
  +
URI は US-ASCII 文字のみを受け入れ、非 ASCII 文字をエンコードするために[[Wikipedia:percent-encoding|パーセントエンコーディング]]を使用します。これにより、非常に長く、人間が読みづらい URI になることがあります。
In Firefox, it is possible to copy decoded URLs by enabling the {{ic|browser.urlbar.decodeURLsOnCopy}} flag in {{ic|about:config}}, or by inserting a space to the start of the URL, then selecting it (with the space) and copying it. However, this trick doesn't work on Chromium, and there is no equivalent flag. Alternatively, select starting at the end of the URL until right after the {{ic|https://}} part, then copy.
 
   
  +
Firefox では、{{ic|browser.urlbar.decodeURLsOnCopy}} フラグを {{ic|about:config}} で有効にするか、URL の先頭にスペースを挿入してからそのスペースを含めて選択し、コピーすることでデコードされた URL をコピーすることができます。ただし、この方法は Chromium では機能せず、同等のフラグもありません。代わりに、URL の末尾から {{ic|https://}} の部分を超えたところまで選択してコピーすることもできます。
For command line usage, you can use {{pkg|python-urllib3}} to translate encoded URLs from stdin.
 
  +
  +
コマンドラインで使用する場合、{{pkg|python-urllib3}} を使用して標準入力からエンコードされた URL を翻訳できます。
   
 
$ python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read().strip()))"
 
$ python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read().strip()))"
   
 
== トラブルシューティング ==
 
== トラブルシューティング ==
  +
エンコーディングの問題は、通常、異なるエンコーディングで通信している二つのプログラムが原因で発生します。通常、片方が UTF-8 を使用していないため、[[Wikipedia:mojibake|文字化け]] が発生します。
   
  +
{{Warning|ロケールのコードセットを {{ic|.UTF-8}} に設定することが強く推奨されます。そうしないと、UTF-8 から非 Unicode エンコーディングへの変換で情報が失われる可能性があります。}}
Encoding problems are usually due to two programs communicating with different encodings, with one side typically not using UTF-8, resulting in [[Wikipedia:mojibake|mojibake]].
 
 
{{Warning|It is highly recommended to set the codeset of your locale to {{ic|.UTF-8}}. Otherwise, conversion from UTF-8 to non-Unicode encoding can result in a loss of information. }}
 
   
  +
=== 不正なアーカイブエンコーディング ===
=== Incorrect archive encoding ===
 
   
  +
古いバージョンの Windows (XP、Vista、7) では、エクスプローラーが特定のロケールで ZIP アーカイブを作成する際に異なるエンコーディングを使用します。正しく展開するには、ターゲットエンコーディングを指定して ''unzip -O'' を使用します。例として、CP936 は古いバージョンの Windows で一般的なエンコーディングです。
On older versions of Windows (XP, Vista, and 7), File Explorer uses different encoding when creating a zip archive with certain locales. To extract properly, use ''unzip -O'' followed with the target encoding. E.g: CP936 is a common encoding in old versions of Windows.
 
   
 
$ unzip -O CP936 ''file.zip''
 
$ unzip -O CP936 ''file.zip''
   
  +
必要な文字セットが不明な場合は、{{ic|-l}} フラグを追加して抽出せずにドライランを行います:
If unsure about the needed charset, dry-run without extraction by adding the {{ic|-l}} flag:
 
   
 
$ unzip -lO SJIS ''file.zip''
 
$ unzip -lO SJIS ''file.zip''
   
Japanese versions of Windows encode ZIP archives with Shift-JIS. Use ''shift-jis'':
+
日本語版の Windows ZIP アーカイブを Shift-JIS でエンコードします。''shift-jis'' を使用します:
   
 
$ unzip -O shift-jis nihongo.zip
 
$ unzip -O shift-jis nihongo.zip
   
Chinese versions of Windows encode ZIP archives with ''gbk'':
+
中国語版の Windows ZIP アーカイブを ''gbk'' でエンコードします:
   
 
$ unzip -O gbk ''file''.zip
 
$ unzip -O gbk ''file''.zip
   
  +
あるいは、ターゲットエンコーディングを自動検出するために {{AUR|unzip-natspec}} を使用します。
Alternatively, use {{AUR|unzip-natspec}} for auto-detecting the targeted encoding.
 
   
  +
=== 不正なファイル名エンコーディング ===
=== Incorrect file name encoding ===
 
   
  +
{{Pkg|convmv}} を使用してエンコーディング変換を行います:
Use {{Pkg|convmv}} for encoding-conversion {{ic|mv}}:
 
   
 
$ convmv -f ''SOURCE_ENCODING'' -t UTF-8 --notest --nosmart file
 
$ convmv -f ''SOURCE_ENCODING'' -t UTF-8 --notest --nosmart file
   
  +
{{ic|--notest}} は移動せずにドライランを行うために使用されます。元のエンコーディングを {{ic|-f}} (例: 中国語の場合は {{ic|GBK}}) を使って特定した後、それを削除して移動操作を行います。なお、{{ic|--smart}} は既に UTF8 エンコードされている場合、変換をスキップします。サポートされているエンコーディングを確認するには {{ic|convmv --list}} を使用します。
{{ic|--notest}} is used to dry-run without moving. After figuring out the original encoding using {{ic|-f}} (e.g: for Chinese {{ic|GBK}}), remove it to proceed with the move operation. Note that {{ic|--smart}} skips conversion if it is already UTF8-encoded. Use {{ic|convmv --list}} to find the supported encodings.
 
   
  +
=== 不正なファイルエンコーディング ===
=== Incorrect file encoding ===
 
   
  +
{{ic|iconv}} コマンドを使用して形式を変換します。例えば:
Use the {{ic|iconv}} command to convert the format. For example:
 
   
 
$ iconv -f ''SOURCE_ENCODING'' -t UTF-8 -o new-file origin-file
 
$ iconv -f ''SOURCE_ENCODING'' -t UTF-8 -o new-file origin-file
   
  +
{{ic|-f}} は元のエンコーディングを指定し、{{ic|-t}} は出力エンコーディングを指定します。サポートされているエンコーディングをすべて照会するには {{ic|iconv -l}} を、出力ファイルを指定するには {{ic|-o}} を使用します。
{{ic|-f}} specifies the original encoding and {{ic|-t}} specifies the output encoding. Use {{ic|iconv -l}} to query all supported encodings and {{ic|-o}} to specify the output file.
 
   
 
==== Vim ====
 
==== Vim ====
   
  +
ロケールが UTF-8 の場合、他の文字エンコードされたファイルを開くと文字化けすることがあります。''vimrc'' に以下のような行を追加してフォールバックを設定できます:
If the locale is UTF-8, opening other char-encoded files may be garbled. You can add a fallback adding to ''vimrc'' a line similar to:
 
   
 
set fileencodings=utf8,cp936,gb18030,big5
 
set fileencodings=utf8,cp936,gb18030,big5
   
Alternatively, you can explicitly set it by {{ic|:set fileencoding{{=}}ansi}}. Vim will do the conversion via ''iconv'' automatically. See {{ic|:h charset-conversion}}.
+
または、{{ic|1=:set fileencoding=ansi}} を明示的に設定することもできます。Vim ''iconv'' を介して自動的に変換を行います。{{ic|:h charset-conversion}} を参照してください。
   
=== Incorrect MP3 ID3 tag encoding ===
+
=== 不正な MP3 ID3 タグエンコーディング ===
To modify the MP3 file tag, convert using {{Pkg|python-mutagen}} or {{Pkg|mp3unicode}}:
+
MP3 ファイルのタグを変更するには、{{Pkg|python-mutagen}} または {{Pkg|mp3unicode}} を使用して変換します:
   
 
$ mid3iconv -e ''SOURCE_ENCODING'' XXX.mp3
 
$ mid3iconv -e ''SOURCE_ENCODING'' XXX.mp3
   
  +
ファイルの変更を望まない場合は、メディアプレーヤーの動作を調整できます。[[GStreamer]] をバックエンドとして使用するプレーヤー(例: [[Rhythmbox]] や totem)では、[[環境変数]]を設定します:
If file modification is undesired, you can tweak the behavior of media players. For players that use [[GStreamer]] as the backend, such as [[Rhythmbox]] and totem, set the [[environment variables]]:
 
   
 
export GST_ID3_TAG_ENCODING=GBK:UTF-8:GB18030
 
export GST_ID3_TAG_ENCODING=GBK:UTF-8:GB18030
 
export GST_ID3V2_TAG_ENCODING=GBK:UTF-8:GB18030
 
export GST_ID3V2_TAG_ENCODING=GBK:UTF-8:GB18030
   
For Beep media player, select MPEG Audio plugin in {{ic|preferences > plugins > media > title >}} then tick {{ic|Disable ID3v2 and Convert non-UTF8 ID3 tags to UTF8}}, and choose the correct encoding.
+
Beep メディアプレーヤーでは、{{ic|preferences > plugins > media > title >}} MPEG Audio プラグインを選択し、{{ic|Disable ID3v2 and Convert non-UTF8 ID3 tags to UTF8}} にチェックを入れ、適切なエンコーディングを選択します。
   
Quod Libet player supports tag editing and setting ID3v2 encoding. This can be set in {{ic|~/.quodlibet/config}}:
+
Quod Libet プレーヤーはタグ編集と ID3v2 エンコーディングの設定をサポートしています。{{ic|~/.quodlibet/config}} に設定できます:
   
 
{{hc|~/.quodlibet/config|2=
 
{{hc|~/.quodlibet/config|2=
102行目: 102行目:
 
}}
 
}}
   
{{Note|Quod Libet supports utf8 encoding by default.}}
+
{{Note|Quod Libet はデフォルトで utf8 エンコーディングをサポートしています。}}
   
  +
=== 不正なマウントエンコーディング ===
=== Incorrect mount encoding ===
 
   
  +
一般的に、マウントされた文字セットはロケールとは異なりますが、[[fstab]] を修正することで設定できます。ロケールが utf8 の場合は、以下のように行を修正します:
Generally, the mounted character set is different from the locales, which can be set by modifyinig [[fstab]]. If the locale is utf8, modify the line to:
 
   
 
{{hc|/etc/fstab|2=
 
{{hc|/etc/fstab|2=
113行目: 113行目:
 
}}
 
}}
   
  +
ロケールが GBK の場合は、以下のようにすべきです:
If the locale is GBK, it should be:
 
   
 
{{hc|/etc/fstab|2=
 
{{hc|/etc/fstab|2=
121行目: 121行目:
 
}}
 
}}
   
=== Incorrect Samba encoding ===
+
=== 不正な Samba エンコーディング ===
   
When using Arch as a [[Samba]] server, adding the following line to {{ic|/etc/samba/smb.conf}} can solve the garbled problem of Windows clients:
+
Arch [[Samba]] サーバーとして使用する場合、{{ic|/etc/samba/smb.conf}} に次の行を追加することで、Windows クライアントの文字化けの問題を解決できます:
   
 
{{hc|/etc/samba/smb.conf|2=
 
{{hc|/etc/samba/smb.conf|2=
131行目: 131行目:
 
}}
 
}}
   
=== Incorrect FTP encoding ===
+
=== 不正な FTP エンコーディング ===
   
  +
UTF8 ロケールを使用している場合、非 Unicode エンコードされたサーバーからダウンロードしたファイル名が文字化けすることがあります。lftp では、{{ic|.lftp/rc}} に次の設定を行います:
If you use UTF8 locale, the downloaded file name from a non-Unicode-encoded server might be garbled. For lftp, make the following settings under {{ic|.lftp/rc}}:
 
   
 
{{hc|.lftp/rc|
 
{{hc|.lftp/rc|
142行目: 142行目:
 
}}
 
}}
   
For gftp, you can do the following settings in {{ic|.gftp/gftprc}}:
+
gftp では、{{ic|.gftp/gftprc}} に次の設定を行うことができます:
   
 
{{hc|.gftp/gftprc|2=
 
{{hc|.gftp/gftprc|2=
150行目: 150行目:
 
}}
 
}}
   
However, the downloaded file name is still garbled and needs to be patched and compiled. The patch address is: https://www.teatime.com.tw/%7Etommy/linux/gftp_remote_charsets.patch
+
ただし、ダウンロードしたファイル名が依然として文字化けしている場合は、パッチを適用してコンパイルする必要があります。パッチのアドレスは: https://www.teatime.com.tw/%7Etommy/linux/gftp_remote_charsets.patch です。
  +
  +
{{TranslationStatus|Character encoding|2024-08-17|814093}}

2024年8月17日 (土) 19:10時点における最新版

関連記事

文字コードは、バイトを読み取り可能な文字に解釈するプロセスです。UTF-8 は 2009 年以降主要なエンコーディングとなっており、事実上の標準として推進されています[1]

UTF-8

ターミナル

Most terminals use UTF-8 by default. However, some (e.g: Gnome-terminal, rxvt-unicode) need to be launched from a UTF-8 locale. To do that, set the codeset part of your locale to .UTF-8 and reload your session. See Locale#Setting_the_locale for instructions.

  • xterm - Run with the argument -u8 or configure resource xterm*utf8: 2.

ユニコード文字の挿入

アプリケーション一覧/ユーティリティ#テキスト入力を参照してください。

  • LibreOffice には、挿入 > 特殊文字 に組み込みのキャラクターマップがあり、文字ブロック、16 進、10 進エンコーディングが表示されます。
  • Compose キー: XCompose を設定して特殊文字を挿入することができます。
  • AltGr を設定して、追加のキーボードレベルにアクセスし、ZWNJ や RTL マークなどの Unicode 制御文字を含む追加の文字を入力できます。

URL エンコード

URI は US-ASCII 文字のみを受け入れ、非 ASCII 文字をエンコードするためにパーセントエンコーディングを使用します。これにより、非常に長く、人間が読みづらい URI になることがあります。

Firefox では、browser.urlbar.decodeURLsOnCopy フラグを about:config で有効にするか、URL の先頭にスペースを挿入してからそのスペースを含めて選択し、コピーすることでデコードされた URL をコピーすることができます。ただし、この方法は Chromium では機能せず、同等のフラグもありません。代わりに、URL の末尾から https:// の部分を超えたところまで選択してコピーすることもできます。

コマンドラインで使用する場合、python-urllib3 を使用して標準入力からエンコードされた URL を翻訳できます。

$ python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read().strip()))"

トラブルシューティング

エンコーディングの問題は、通常、異なるエンコーディングで通信している二つのプログラムが原因で発生します。通常、片方が UTF-8 を使用していないため、文字化け が発生します。

警告: ロケールのコードセットを .UTF-8 に設定することが強く推奨されます。そうしないと、UTF-8 から非 Unicode エンコーディングへの変換で情報が失われる可能性があります。

不正なアーカイブエンコーディング

古いバージョンの Windows (XP、Vista、7) では、エクスプローラーが特定のロケールで ZIP アーカイブを作成する際に異なるエンコーディングを使用します。正しく展開するには、ターゲットエンコーディングを指定して unzip -O を使用します。例として、CP936 は古いバージョンの Windows で一般的なエンコーディングです。

$ unzip -O CP936 file.zip

必要な文字セットが不明な場合は、-l フラグを追加して抽出せずにドライランを行います:

$ unzip -lO SJIS file.zip

日本語版の Windows は ZIP アーカイブを Shift-JIS でエンコードします。shift-jis を使用します:

$ unzip -O shift-jis nihongo.zip

中国語版の Windows は ZIP アーカイブを gbk でエンコードします:

$ unzip -O gbk file.zip

あるいは、ターゲットエンコーディングを自動検出するために unzip-natspecAUR を使用します。

不正なファイル名エンコーディング

convmv を使用してエンコーディング変換を行います:

$ convmv -f SOURCE_ENCODING -t UTF-8 --notest --nosmart file

--notest は移動せずにドライランを行うために使用されます。元のエンコーディングを -f (例: 中国語の場合は GBK) を使って特定した後、それを削除して移動操作を行います。なお、--smart は既に UTF8 エンコードされている場合、変換をスキップします。サポートされているエンコーディングを確認するには convmv --list を使用します。

不正なファイルエンコーディング

iconv コマンドを使用して形式を変換します。例えば:

$ iconv -f SOURCE_ENCODING -t UTF-8 -o new-file origin-file

-f は元のエンコーディングを指定し、-t は出力エンコーディングを指定します。サポートされているエンコーディングをすべて照会するには iconv -l を、出力ファイルを指定するには -o を使用します。

Vim

ロケールが UTF-8 の場合、他の文字エンコードされたファイルを開くと文字化けすることがあります。vimrc に以下のような行を追加してフォールバックを設定できます:

set fileencodings=utf8,cp936,gb18030,big5

または、:set fileencoding=ansi を明示的に設定することもできます。Vim は iconv を介して自動的に変換を行います。:h charset-conversion を参照してください。

不正な MP3 ID3 タグエンコーディング

MP3 ファイルのタグを変更するには、python-mutagen または mp3unicode を使用して変換します:

$ mid3iconv -e SOURCE_ENCODING XXX.mp3

ファイルの変更を望まない場合は、メディアプレーヤーの動作を調整できます。GStreamer をバックエンドとして使用するプレーヤー(例: Rhythmbox や totem)では、環境変数を設定します:

export GST_ID3_TAG_ENCODING=GBK:UTF-8:GB18030
export GST_ID3V2_TAG_ENCODING=GBK:UTF-8:GB18030

Beep メディアプレーヤーでは、preferences > plugins > media > title > で MPEG Audio プラグインを選択し、Disable ID3v2 and Convert non-UTF8 ID3 tags to UTF8 にチェックを入れ、適切なエンコーディングを選択します。

Quod Libet プレーヤーはタグ編集と ID3v2 エンコーディングの設定をサポートしています。~/.quodlibet/config に設定できます:

~/.quodlibet/config
...
id3encoding = gbk
...
ノート: Quod Libet はデフォルトで utf8 エンコーディングをサポートしています。

不正なマウントエンコーディング

一般的に、マウントされた文字セットはロケールとは異なりますが、fstab を修正することで設定できます。ロケールが utf8 の場合は、以下のように行を修正します:

/etc/fstab
...
/dev/sdxx /media/win ntfs defaults,iocharset=utf8 0 0

ロケールが GBK の場合は、以下のようにすべきです:

/etc/fstab
...
/dev/sdxx /media/win ntfs defaults,iocharset=cp936 0 0
...

不正な Samba エンコーディング

Arch を Samba サーバーとして使用する場合、/etc/samba/smb.conf に次の行を追加することで、Windows クライアントの文字化けの問題を解決できます:

/etc/samba/smb.conf
...
unix charset=gb2312
...

不正な FTP エンコーディング

UTF8 ロケールを使用している場合、非 Unicode エンコードされたサーバーからダウンロードしたファイル名が文字化けすることがあります。lftp では、.lftp/rc に次の設定を行います:

.lftp/rc
...
set ftp:charset "gbk"
set file:charset "UTF-8"
...

gftp では、.gftp/gftprc に次の設定を行うことができます:

.gftp/gftprc
...
remote_charsets=gb2312
...

ただし、ダウンロードしたファイル名が依然として文字化けしている場合は、パッチを適用してコンパイルする必要があります。パッチのアドレスは: https://www.teatime.com.tw/%7Etommy/linux/gftp_remote_charsets.patch です。

翻訳ステータス: このページは en:Character encoding の翻訳バージョンです。最後の翻訳日は 2024-08-17 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。