Looking for language database and codes [closed]
开发者_如何学Python
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed last year.
Improve this questionI am looking for a table of language names and codes like the ISO 639-1 set: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
Thanks
You'll want ISO 639-3 if you want the up-to-date list.
Enhancing Obalix answer, I have created a bash script that will take a UTF-8 CSV file and insert it into a database. Note that the file provided by Obalix is in UTF-16 NOT UTF-8. The below script checks for its encoding and advises user on how to convert it.
Of course you will need to modify the insert statement according to your schema.
#!/bin/bash
USAGE="Usage: $0 <csv-file>"
if [ $# -lt 1 ]
then
echo $USAGE
exit 1
fi
csv=$1
if [ ! -f $csv ]; then
echo "$csv: No such file"
exit 1
fi
file $csv | grep -q UTF-8
if [ $? -ne 0 ]
then
echo $csv: must be in UTF-8 format, use the following command to fix this:
echo "cat $csv | iconv -f UTF-16 -t UTF-8 | tr -d \"\r\" > utf8-$csv"
exit 1
fi
mysql=<PATH/TO/mysql/BINARY>
db=<DATABASE_NAME>
user=<USERNAME>
pass=<PASSWORD>
sql=insert-all-langs.sql
echo "-- Inserting all languages generated on `date`" > $sql
printf "Processing CSV file..."
# prepend _ to all lines so that no line starts by whitespace
sed 's/.*/_&/' $csv | while read l; do
iso6391=`echo "$l" | cut -f4`
name=`echo -e "$l" | cut -f3 | tr -d "\"" | sed 's/'\''/\\\\'\''/g'`
echo $iso6391:$name
# insert ignore supresses errors for duplicate locales (row still not inserted)
echo "insert ignore into languages (name, locale, rtl, created_at, updated_at) values ('$name', '$iso6391', 0, now(), now());" >> $sql
done
echo Done
printf "Executing SQL..."
cat $sql | $mysql -u$user -p$pass $db
echo Done
精彩评论