There are two levels of internationalization functionality in Mule.
- Level 1 Core Internationalization Support Java provides basic internationalization functions in the language and bundled libraries. Mule supports message conversion by the specified encoding in metadata and configuration files.
- Level 2 Message Catalog Mule supports a locale-based message catalog.
When writing code, respect the following priority order:
- encoding in metadata (HTTP headers, Mail headers, etc.)
- encoding in the configuration file
- hard-coded default encoding or platform default encoding
Conversion between string and byte stream is locale-sensitive. If you write code for byte stream conversion, carefully consider the encoding you use.
The following lists typically misused APIs.
- Incorrect:
String#getBytes()
. Correct: UseString#getBytes(String charsetName)
if you handle non-ASCII strings. - Incorrect:
String#String(byte[] bytes)
. Correct: UseString(byte[] bytes, String charsetName)
if you handle non-ASCII byte stream. The following constructors are not friendly to internationalization and should be avoided.String(byte ascii[], int hibyte, int offset, int count);
String(byte ascii[], int hibyte);
String(byte bytes[], int offset, int length);
- Incorrect: InputStreamReader#InputStreamReader(InputStream in) and Friends. Correct: Use
InputStreamReader(InputStream in, String charsetName)
if you handle non-ASCII byte stream. If you use subclasses of Reader and Writer, use a constructor with charsetName (we consider charsetName as encoding name in this context).