1 \documentclass[english]{article}
2 \usepackage[T1]{fontenc}
3 \usepackage[utf8]{inputenc}
7 % It is impossible to get the document language because the document could start with a command,
8 % whitespace, and English word or whatever and the rest is in Japanese. Checking for the first CJK
9 % environment is no solution because the document could be English and contain only some Japanese.
14 Japanese \end{CJK} \begin{CJK}{UTF8}{}Chinese traditional\end{CJK} \begin{CJK}{UTF8}{}
18 Chinese simplified \end{CJK}\begin{CJK}{UTF8}{hei} Japanese \end{CJK} \begin{CJK}{UTF8}{}Chinese simplified
25 \inputencoding{latin9}%
26 \selectlanguage{english}%