Migration Gallery from Big5 to UTF-8

「想要把Gallery從Big5轉換到UTF-8」,這個念頭其實已經很久了。在這個UTF-8盛行的年代,blog也是UTF-8,但是藝廊卻因為歷史的因素而停留在Big5。雖說Gallery有支援Localization,可以轉換界面的編碼,但是所有相簿的標題跟描述都還是Big5,一換成UTF-8之後就是亂碼。Gallery的網站中好像也沒有相關的轉換程式……

於是在某一個什麼事都不想幹的午後,看到了IRC上的某一句話,就突然立了個志,寫了個轉換程式出來……..

在PHP下要從Big5轉到UTF-8,其實還有點傷腦筋,在 zonble的這篇「PHP、XML、以及字元編碼:一則關於悲情、憤怒以及傷逝(資料)的故事」中有提到用XML、mbstring或是iconv來實作。由於不一定每個PHP都有在編繹時加入 mbstring 或是 iconv的選項,因此我本來是想使用某一獨立的模組或是class來作這一部份的轉換的。只是網路上找了一下好像沒找到,而我又不想自己花大時間重新發明輪子,最後只好退而求其次,呼叫UNIX下常見(文件上是這麼說的)的iconv獨立程式來作轉換。效率雖然差了點,不過反正轉換程式才跑一次,慢一點應該無所謂,只要不跑到timeout就好了 🙂

需要的人可以到這兒下載,要注意的是,由於安全上的顧慮,在轉換完之後記得把script從Gallery目錄下移除 🙂

文後附上簡單的README。

##############################################################################
# The Script is for migration from Big5 to UTF-8 for gallery (http://gallery.sourceforge.net/)
#
# To use this script, you don’t need to have mbstring or iconv compiled in PHP.
# But you have to have iconv in your system.
#
# If you have mbstring or iconv compiled in you PHP, you can rewrite the “big52utf8” function
# to achieve the better performance(although such kind of converson tools do not urgely need
# “Performance”)
#
# The First thing you need, and you must to do is “BACKUP YOUR ALBUMS”!
#
# After upload the script on to your server , you have to put the script in you gallery dir.
# And modify the variable $iconv_loc and $albumdir.
# The open your browser and input the URL of this script.
#
# The script will first list all files it find to be translated from Big5 to UTF-8.
# You can click [UTF-8] to preview the result.
# When you are ready, click the “Convert all file from big5 to UTF-8 ” below the list.
# It will take a while, but is worth.
#
# At last, don’t forget to download the language pack from gallery main site and install it.
#
# Now, you can have your gallery “Unicoded” 🙂
#
# AND…DON’T FORGET TO DELETE THIS SCRIPT FROM YOUR GALLERY DIRECTORY, OR IT MAY CAUSE
# SERIOUS SECURITY PROBLEM!!!
#
# This script is GNU licensed, if you need any further help, you can e-mail me.
#
# PipperL (pipperl@serv.idv.tw)
# http://blog.serv.idv.tw
#
###################################################################################

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

%d 位部落客按了讚: