Is it good idea to use "tw" instead of "zh-tw" in i18n?

As per IANA (standards body), no.

See:
https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

The TW subtag has a type of region
Type: region
Subtag: TW
Description: Taiwan, Province of China
Added: 2005-10-16

This means that it can only be used this way: language_code+REGION so for Taiwan Chinese, the correct language tagging is zh-TW or zh-tw (as per W3C, it is case-insensitive; see next link).

See also:

The language subtag syntax is: language-extlang-script-region-variant-extension-privateuse.

Examples:

  • zh-Hans-TW
  • zh-Hant-TW

Breakdown:

  • zh is the language
  • Hans or Hant is the script (simplified and traditional respectively)
  • TW is the region.

General rule, if it can be shorter, the better. So instead of zh-hant-tw just write zh-tw but not tw only as Apple is using. Some language features of Hugo (and GoLang itself) also relies on correct tag usage (like the datetime localisation).

The reason tw works fine is because major browsers chose to interpret it as zh-tw. However, you can not guarantee that tw will work in other rendering engines and/or browsers, for example, browsers used for special needs like Braille and voice/speech browsing. (IIRC, there was one time Amazon’s gadgets doesn’t interpret incorrect tagging either but later added support because webmasters/web developers of major sites, like Apple in your example, refuses to fix their bug.)

If you want to learn more, I have a very old blog post about it here:

It’s geared towards Philippine languages (we can use up to the variant tag) but it’s practically the same.

3 Likes