gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.37k stars 7.43k forks source link

Automatic conversion between Traditional and Simplified Chinese #4669

Open anthonyfok opened 6 years ago

anthonyfok commented 6 years ago

For a multilingual website supporting the Chinese language, it is best to cater to both Simplified Chinese "zh-Hans" (zh-CN, zh-SG) and Traditional Chinese "zh-Hant" (zh-TW, zh-HK) audiences. It would be great if Hugo could automatically generate both zh-Hans and zh-Hant pages from a single .zh.md file, with the possibility of manual override if necessary. Some noteworthy examples are:

  1. The feature could be enabled globally, and enabled/disabled in the front matter of individual pages.
  2. When enabled, filename.zh.md would generate the corresponding filename.zh.html, filename.zh-Hans.html, filename.zh-Hant.html, as well as filename.zh-CN.html, filename.zh-TW.html and filename.zh-HK.html if the user desires (configurable), unless, for example, filename.zh-Hant.md already exists.
  3. Provide automatic conversion with Go port of OpenCC or similar.
  4. Allow manual override to prevent certain text from being converted.
  5. Allow custom conversion list for certain phrase-level/variant conversion.

Automatic conversion

OpenCC, written by @BYVoid and hosted at https://github.com/BYVoid/OpenCC, is currently one of the most popular and likely the best open-source Chinese conversion tool:

Open Chinese Convert (OpenCC, 開放中文轉換) is an opensource project for conversion between Traditional Chinese and Simplified Chinese, supporting character-level conversion, phrase-level conversion, variant conversion and regional idioms among Mainland China, Taiwan and Hong kong.

And a good news! @liuzl, a Hugo user himself, recently ported OpenCC to a pure Go implementation called GoCC, see https://github.com/liuzl/gocc

Manual override / Custom conversion list

Yes, Chinese Wikipedia has these features. I am not sure which syntax we should use for Hugo, or perhaps existing syntax and/or github.com/nicksnyder/go-i18n already handle some of these cases? Need further investigation and thinking.

See also gohugoio/hugoDocs#461

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

septs commented 1 year ago

i think, can add a template function support the feature, like babel handling method

{{ .Content | opencc "s2t" }}

equal to (pseudo-code):

{{ .Content }} | opencc --config "s2t" -- | {{ pipeline return value }}