Re: use vim to "translate" Chinese (simplified/traditional)
- Xiangjiang Ma <maxiangjiang@...> wrote:
> Hi,see ":help stridx()"
> I am interested in "translating" between the simplified Chinese
> and the traditional Chinese using vim functions/scripts. This is
> more like what "gu" and "gU" do for ASCII. Anyone out there can
> help with the following task 3?
> I will add it to http://vim.sourceforge.net/tips
> if it can be done successfully.
> 1. There is one-to-one map between the Simplified Chinese and the
> Traditional Chinese (80% true in real life?)
> 2. The encoding is set to be utf-8
> 1. define a Simplified_Chinese_String, with 6000 unicode point (DONE)
> 2. define a Traditional_Chinese_String, with 6000 unicode point (DONE)
> 3. write one function to do transform from Simplified to Traditional
> a) loop through the whole vim buffer
> b) for every char, find its index in the Simplified_Chinese_String
> c) use the index to replace the char with the correspondingshould be the same in reverse (i.e. reversing the roles of the two arrays)
> Traditional which can be found from the
> 4. write one function to do transform from Traditional to Simplified
Seems interesting. I suppose it can be assumed that anything "not found in
table" is to be kept without change. To speedup the conversion, "codepoint
ranges" might be defined, so that out-of-range values would be left
unchanged with no lookup.
I look forward to seeing this in vim script.