Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 1.69 KB

I18N.md

File metadata and controls

29 lines (20 loc) · 1.69 KB

Internationalization Guidelines

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.

Encoding Priority

When writing code, respect the following priority order:

  1. encoding in metadata (HTTP headers, Mail headers, etc.)
  2. encoding in the configuration file
  3. hard-coded default encoding or platform default encoding

Byte Stream Conversion

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: Use String#getBytes(String charsetName) if you handle non-ASCII strings.
  • Incorrect: String#String(byte[] bytes). Correct: Use String(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).