1 Star 0 Fork 1

snowelf / mule

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
I18N.md 1.69 KB
Copy Edit Web IDE Raw Blame History

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).

Comment ( 0 )

Sign in for post a comment