Wednesday, October 31, 2018

Cantonese as a Language

Recently there are a spat of talks about Cantonese being a Language. To be fair, it is a language distinct from Mandarin (Putonghua).  Cantonese exists since before Qin Dynasty and later developed into NanYue in 204BC.  During the Tang dynasty, intermix between the Han and Guangdong, Guangxi people reached critical mass. These people refers to themselves as Tang people.  As a group who spoke a distinctive language from the Middle Chinese, it is deemed to be a language.

It is quite difficult to define Cantonese as a dialect as it is very distinguished from Mandarin. They are mutually unintelligible with each other. Cantonese used to say that their Language is older than PuTongHua (the official Chinese Language). There's a story about Cantonese almost become the official language of China after the XinHai Revolution in 1912 but was beaten by a small margin (Wikipedia). Whether the story is true is still arguable. Since the communist takeover in 1949, Putonghua is the common language. But since Hong Kong and Macao has not returned to China, Cantonese is the common language there.

Canton province since the Qing dynasty has been the only opening to the world, it is not surprising that many of the emigrants are Cantonese. Thus there is always an urge to define Cantonese as a language.

People in Hong Kong has always strive to distinguish themselves from Chinese. It is therefore not surprising that they actively promotes Cantonese as a Language thereby distinguishing themselves from Mandarin speaking Mainland Chinese.

There are many arguments for Cantonese as a Language.

1. Cantonese is older than Putonghua. Actually, they all developed from Middle Chinese on a different path. Putonghua is indeed developed later.

2. Tang poems are written in Cantonese. Tang poems are based on Middle Chinese. Some may have sounded more correctly in Cantonese while others simple does not sound right. Mandarin obviously does not really fit well too since Middle Chinese is used then.

3. UN has defined Cantonese as a language. UN did list Cantonese as a language together with other major spoken language of China. In the order of number of people speaking specific language in the world, Mandarin is the most (14%).  Wu (Shanghainese) gets 1.2%. Yue (including Cantonese) only gets 0.89% (Wikipedia). It is undeniable that it is a language listed by UN. But saying that UN recognize it as a language (not a dialect) is a bit far fetched.

4. There are claims that UN define Cantonese as one of the six "leading language in daily use" (粵語為日常六種主要用語). It is very much doubtful this is real. Yue (including Cantonese) is 24th in the list of world's most spoken language according to Wikipedia. Wu language has even higher usage than Yue. There is no definitive link to this saying in UN.

5. Cantonese is an official language in Hong Kong, Macao. Chinese constitution 中华人民共和国宪法》19.5 states that Putonghua is promoted as common language throughout the country.  中华人民共和国国家通用语言文字法》section 2 states that the common language is Putonghua. Section 8 of the same article indicates each race has the freedom to develop and use their own language. Even Putonghua is only stated as national common language not "Official language". How did Cantonese being defined as "official language"? (https://www.zhihu.com/question/22600638).

It is undeniable that Cantonese is indeed a language. There is no point citing unclear or untrue facts about it as a language.




Monday, October 29, 2018

Printing Receipt Using PHP again

Last blog on this subject is at Printing Receipt. It talks about a single use printing where there is only one printer for one purpose. There are requirements to use same type of printer for different receipts. Like for example, one company wants to print queue numbers, receipts and barcode travellers using the same type of printer.

It would be easy to just create three PHP page to do the work. Here the attempt is to use a single PHP page like a driver that can print to different printer for different purpose. It becomes like a class file. Also the print codes stays with the app that does the printing so that you do not need to look for specific PHP page for the printing code.

The PHP code is like the previous blog with a slight change. The printer is a Brother QL720NW which does not work with fwrite_stream. A simple fputs will work fine.

All that is required is to send the printer IP and the print code to the page as parameter using POST. Now the twist is that POST only sends AlphaNumeric not the full ASCII. Escape codes usually includes ASCII less than 32. The trick is to convert the print code into Base64 first before sending. At the PHP, just use base64_decode to convert it back before printing. The code is as below

$ipAddress = $_POST["IP"];
$printCode = $_POST['PrintCode"];
$printCode = Base64_decode($printCode);
$fp = fsockopen($ipAddress, 9100);
fputs($fp, $printCode, strlen($printCode));
fclose($fp)

With this, you can send to different printer with a different print code using the same PHP page. The advantage is that any app that can do a POST will be able to do printing.

Most programming codes will have base64_encode (or similar). If not then there are probably programmers who wrote a code library in the same programming language. If it does not have then you may have to create the code yourself. The trick is to convert the byte into Binary then take every 6 bit and convert it back to number to match against a table see https://en.wikipedia.org/wiki/Base64. to get the ASCII character. It is not that difficult.