{"id":854,"date":"2010-03-02T22:48:07","date_gmt":"2010-03-02T14:48:07","guid":{"rendered":"http:\/\/blog.lolyco.com\/sean\/?p=854"},"modified":"2010-12-31T07:51:32","modified_gmt":"2010-12-30T23:51:32","slug":"pos-malaysia-widget-in-malay-and-chinese-browser-language-detection","status":"publish","type":"post","link":"https:\/\/blog.lolyco.com\/sean\/2010\/03\/02\/pos-malaysia-widget-in-malay-and-chinese-browser-language-detection\/","title":{"rendered":"Pos Malaysia widget in Malay and Chinese (browser language detection)"},"content":{"rendered":"<div id=\"attachment_855\" style=\"width: 215px\" class=\"wp-caption alignright\"><a href=\"http:\/\/spider.my\/posmalaysia4.html\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-855\" class=\"size-full wp-image-855 \" title=\"Browser language 'en'. Netherlands quote requests 1-to-NL.js\" src=\"http:\/\/blog.lolyco.com\/sean\/wp-content\/uploads\/2010\/03\/spider.my_.pos_.widget.i18n.en_.jpeg\" alt=\"Browser language 'en'. Netherlands quote requests 1-to-NL.js\" width=\"205\" height=\"265\" \/><\/a><p id=\"caption-attachment-855\" class=\"wp-caption-text\">Shipping widget appearance for browser language &#39;en&#39;.<\/p><\/div>\n<p>Adding the Pos Parcel rates (ripped yesterday) to the previously ripped Pos Laju rates made it glaringly obvious how difficult it is to write software for data that&#8217;s in as bad a shape as is Pos Malaysia&#8217;s. With the problems in country names I&#8217;d already mentioned (Luxembourg\/Lux<em><strong>z<\/strong><\/em>emboug, Netherlands\/Netherland, United Kingdom\/Great Britain), the benefit of replying to a shipping quote query by weight \/ country is lost. If the country names don&#8217;t match for different datasets, there&#8217;s no easy way of grouping different quotes for the same destination together.<\/p>\n<p>I mentioned ISO3166-1 &#8211; the ISO Country Code standard before. I wrote a quick tool to map Pos Malaysia country names (there&#8217;s some really funny stuff in there!) onto ISO3166-1 2-letter codes in my version of their data, and instantly broke all my code. I&#8217;d written the demo code to use Pos Malaysia&#8217;s names, so I had to convert everything to use the 2-letter ISO codes. That finally merged all the strangely-named countries. Having done that, the only possibility left (it&#8217;s a good one!) for the API was to use the 2-letter codes. The query for 0.5kg to Netherlands is now:<\/p>\n<p><del datetime=\"2010-12-30T23:43:41+00:00\"><a href=\"http:\/\/spider.my\/pos-malaysia-shipping-quote-2\/0.5-to-NL.xml\">http:\/\/spider.my\/pos-malaysia-shipping-quote-2\/0.5-to-NL.xml<\/a><\/del><br \/>\n(updated 31st Dec 2010)<br \/>\n<a href=\"http:\/\/spider.my\/api\/shipping-quote\/0.5-to-NL-ex-MY.xml\">http:\/\/spider.my\/api\/shipping-quote\/0.5-to-NL-ex-MY.xml<\/a><\/p>\n<p>Using two-letter codes also meant I lost my source of country names for the pop-up selection menus on my pages. Fortunately Java comes equipped with a <a href=\"http:\/\/java.sun.com\/j2se\/1.4.2\/docs\/api\/java\/util\/Locale.html\">Locale<\/a> class which can provide a nice country name for a 2-letter code. Here&#8217;s the good bit though: it can give the name in any language for which it has the necessary platform data. Coverage is pretty good, so widely-spoken languages in Malaysia like Malay, English and Chinese are available for free! Unfortunately for the large local Tamil-speaking population, Tamil doesn&#8217;t seem to be included in the Java platform at the moment.<\/p>\n<p>Since I was using Locale to provide country-code-to-name mapping, I added a small amount of extra code to <a href=\"http:\/\/www.w3.org\/International\/questions\/qa-lang-priorities\">detect browser language preference<\/a>. Now if you use the widget demo, you&#8217;ll get it &#8216;your way&#8217; if your browser is set to ask for Malay (ms), English (en &#8211; the default) or Chinese (zh). Other browser settings will probably get you a best-effort at country names and everything else in English.<\/p>\n<div id=\"attachment_856\" style=\"width: 215px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/blog.lolyco.com\/sean\/wp-content\/uploads\/2010\/03\/spider.my_.pos_.widget.i18n.ms_.jpeg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-856\" class=\"size-full wp-image-856\" title=\"Browser language 'ms' (Malay). Belanda (Netherlands) uses same 1-to-NL.js\" src=\"http:\/\/blog.lolyco.com\/sean\/wp-content\/uploads\/2010\/03\/spider.my_.pos_.widget.i18n.ms_.jpeg\" alt=\"Browser language 'ms' (Malay). Belanda (Netherlands) uses same 1-to-NL.js\" width=\"205\" height=\"266\" \/><\/a><p id=\"caption-attachment-856\" class=\"wp-caption-text\">Browser language &#39;ms&#39; (Malay). Belanda (Netherlands) uses same 1-to-NL.js<\/p><\/div>\n<div id=\"attachment_857\" style=\"width: 214px\" class=\"wp-caption alignright\"><a href=\"http:\/\/blog.lolyco.com\/sean\/wp-content\/uploads\/2010\/03\/spider.my_.pos_.widget.i18n.zh.jpeg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-857\" class=\"size-full wp-image-857\" title=\"Browser language 'zh' (Chinese). \u8377\u5170 (Netherlands) uses same 1-to-NL.js\" src=\"http:\/\/blog.lolyco.com\/sean\/wp-content\/uploads\/2010\/03\/spider.my_.pos_.widget.i18n.zh.jpeg\" alt=\"Browser language 'zh' (Chinese). \u8377\u5170 (Netherlands) uses same 1-to-NL.js\" width=\"204\" height=\"264\" \/><\/a><p id=\"caption-attachment-857\" class=\"wp-caption-text\">Browser language &#39;zh&#39; (Chinese). \u8377\u5170 (Netherlands) uses same 1-to-NL.js<\/p><\/div>\n<p style=\"clear: left;\">That&#8217;s more or less as far as setting up an API for Pos shipping quotes can go. I&#8217;ve got one more demonstration of the API that I want to do, and then I&#8217;ll do a recap of the current state of the API. Not a hint of a reply to my emails to Pos yet, I&#8217;ll try phoning later in the week.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding the Pos Parcel rates (ripped yesterday) to the previously ripped Pos Laju rates made it glaringly obvious how difficult it is to write software for data that&#8217;s in as bad a shape as is Pos Malaysia&#8217;s. With the problems in country names I&#8217;d already mentioned (Luxembourg\/Luxzemboug, Netherlands\/Netherland, United Kingdom\/Great Britain), the benefit of replying [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,3,35],"tags":[21,109,41,33,19,9,105,57],"class_list":["post-854","post","type-post","status-publish","format-standard","hentry","category-fixed","category-software","category-spidermy","tag-e-commerce","tag-fixed","tag-http","tag-java","tag-malaysia","tag-open-source","tag-software","tag-web"],"_links":{"self":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/comments?post=854"}],"version-history":[{"count":5,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":859,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/posts\/854\/revisions\/859"}],"wp:attachment":[{"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/media?parent=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/categories?post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lolyco.com\/sean\/wp-json\/wp\/v2\/tags?post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}