Özellikle Windows ortamında oluşturulan dosyalar genellikle Windows Türkçe ya da ISO-8859-9 formatında kodlanmış oluyorlar. Ancak çoklu dil aileleriyle çalışmaya başladığınızda bunun bir kabusa dönüştüğünü farketmek zor değil. Linux’da kısa yoldan bir dosyanın encode’unu değiştirmek için;
tcs -f 8859-9 -t utf dosyaadi.php > yenidosyaadi.php
komutu yeterli oluyor. Tcs direkt olarak çeviri yaptığı için içeriğini yeni bir dosya olarak kaydedebiliyoruz.
Bu işlemi otomatikleştirmek için şöyle bir script yazdık. Bu script sayesinde bir klasör içindeki bütün önemli uzantılara sahip dosyaların encodingini utf-8′e çevirebilirsiniz.
#!/bin/sh
CMDLN_ARGS=”$@” # Command line arguments for this script
export CMDLN_ARGS
# Run this script as root if not already.
chk_root () {
if [ ! $( id -u ) -eq 0 ]; then
echo “Please enter your password.”
exec sudo su -c “${0} ${CMDLN_ARGS}” # Call this prog as root
exit ${?} # sice we’re ‘execing’ above, we wont reach this exit
# unless something goes wrong.
fi
}
chk_root
files=`find $1 -regex “.*\(php\|html\|tpl\|js\|css\|htm\)$”`
suffix=`eval date +%s`
tar -zcvf backup-$suffix.tar.gz –exclude=’*.tar.gz’ $1
for xx in $files
do
mv $xx $xx.bak
echo backup to: $xx.bak
tcs -f 8859-9 -t utf $xx.bak > $xx
rm $xx.bak
echo $xx converted
done
If you like this blog please take a second and subscribe to my rss feed
Tags: dil kodlaması, encoding, file encoding, linux
Comments: No comments, be the first to comment
All the fields that are marked with REQ must be filled