<?php

function supported_charsets(){
// check http://nl2.php.net/htmlentities
    $charsets = array('iso-8859-1',
		      'iso-8859-15',
		      'utf-8',
		      'cp866',  //'ibm866'
		      'cp1251', // 'Windows-1251'
		      'cp1252', // 'Windows-1252'
		      'koi8-r',
		      'big5',
		      'gb2312',
		      'big5-hkscs',
		      'shift_jis',
		      'euc-jp');
    return $charsets;

}

function iso639_reverse(){

  $iso639 = iso639();
  $iso638 = array_flip($iso639);
  return $iso639;

}

function iso639(){

// http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt
// Technical contents of ISO 639:1988 (E/F)
// "Code for the representation of names of languages".
//
// Typed by Keld.Simonsen@dkuug.dk 1990-11-30  <ftp://dkuug.dk/i18n/ISO_639>
// Minor corrections, 1992-09-08 by Keld Simonsen
// Sundanese corrected, 1992-11-11 by Keld Simonsen
// Telugu corrected, 1995-08-24 by Keld Simonsen
// Hebrew, Indonesian, Yiddish corrected 1995-10-10 by Michael Everson
// Inuktitut, Uighur, Zhuang added 1995-10-10 by Michael Everson
// Sinhalese corrected, 1995-10-10 by Michael Everson
// Faeroese corrected to Faroese, 1995-11-18 by Keld Simonsen
// Sangro corrected to Sangho, 1996-07-28 by Keld Simonsen
// 
// Two-letter lower-case symbols are used.
// The Registration Authority for ISO 639 is Infoterm, Osterreichisches
// Normungsinstitut (ON), Postfach 130, A-1021 Vienna, Austria.

  $iso639 = array(
'aa' => 'Afar',
'ab' => 'Abkhazian',
'af' => 'Afrikaans',
'am' => 'Amharic',
'ar' => 'Arabic',
'as' => 'Assamese',
'ay' => 'Aymara',
'az' => 'Azerbaijani',

'ba' => 'Bashkir',
'be' => 'Byelorussian',
'bg' => 'Bulgarian',
'bh' => 'Bihari',
'bi' => 'Bislama',
'bn' => 'Bengali',
'bo' => 'Tibetan',
'br' => 'Breton',

'ca' => 'Catalan',
'co' => 'Corsican',
'cs' => 'Czech',
'cy' => 'Welsh',

'da' => 'Danish',
'de' => 'German',
'dz' => 'Bhutani',

'el' => 'Greek',
'en' => 'English',
'eo' => 'Esperanto',
'es' => 'Spanish',
'et' => 'Estonian',
'eu' => 'Basque',

'fa' => 'Persian',
'fi' => 'Finnish',
'fj' => 'Fiji',
'fo' => 'Faroese',
'fr' => 'French',
'fy' => 'Frisian',

'ga' => 'Irish',
'gd' => 'Scots_Gaelic',
'gl' => 'Galician',
'gn' => 'Guarani',
'gu' => 'Gujarati',

'ha' => 'Hausa',
'he' => 'Hebrew',
'hi' => 'Hindi',
'hr' => 'Croatian',
'hu' => 'Hungarian',
'hy' => 'Armenian',

'ia' => 'Interlingua',
'id' => 'Indonesian',
'ie' => 'Interlingue',
'ik' => 'Inupiak',
'is' => 'Icelandic',
'it' => 'Italian',
'iu' => 'Inuktitut',

'ja' => 'Japanese',
'jw' => 'Javanese',

'ka' => 'Georgian',
'kk' => 'Kazakh',
'kl' => 'Greenlandic',
'km' => 'Cambodian',
'kn' => 'Kannada',
'ko' => 'Korean',
'ks' => 'Kashmiri',
'ku' => 'Kurdish',
'ky' => 'Kirghiz',

'la' => 'Latin',
'ln' => 'Lingala',
'lo' => 'Laothian',
'lt' => 'Lithuanian',
'lv' => 'Latvian',

'mg' => 'Malagasy',
'mi' => 'Maori',
'mk' => 'Macedonian',
'ml' => 'Malayalam',
'mn' => 'Mongolian',
'mo' => 'Moldavian',
'mr' => 'Marathi',
'ms' => 'Malay',
'mt' => 'Maltese',
'my' => 'Burmese',

'na' => 'Nauru',
'ne' => 'Nepali',
'nl' => 'Dutch',
'no' => 'Norwegian',

'oc' => 'Occitan',
'om' => '(Afan)Oromo',
'or' => 'Oriya',

'pa' => 'Punjabi',
'pl' => 'Polish',
'ps' => 'Pashto,Pushto',
'pt' => 'Portuguese',

'qu' => 'Quechua',

'rm' => 'Rhaeto-Romance',
'rn' => 'Kirundi',
'ro' => 'Romanian',
'ru' => 'Russian',
'rw' => 'Kinyarwanda',

'sa' => 'Sanskrit',
'sd' => 'Sindhi',
'sg' => 'Sangho',
'sh' => 'Serbo-Croatian',
'si' => 'Sinhalese',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'sm' => 'Samoan',
'sn' => 'Shona',
'so' => 'Somali',
'sq' => 'Albanian',
'sr' => 'Serbian',
'ss' => 'Siswati',
'st' => 'Sesotho',
'su' => 'Sundanese',
'sv' => 'Swedish',
'sw' => 'Swahili',

'ta' => 'Tamil',
'te' => 'Telugu',
'tg' => 'Tajik',
'th' => 'Thai',
'ti' => 'Tigrinya',
'tk' => 'Turkmen',
'tl' => 'Tagalog',
'tn' => 'Setswana',
'to' => 'Tonga',
'tr' => 'Turkish',
'ts' => 'Tsonga',
'tt' => 'Tatar',
'tw' => 'Twi',

'ug' => 'Uighur',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',

'vi' => 'Vietnamese',
'vo' => 'Volapuk',

'wo' => 'Wolof',

'xh' => 'Xhosa',

'yi' => 'Yiddish',
'yo' => 'Yoruba',

'za' => 'Zhuang',
'zh' => 'Chinese',
'zu' => 'Zulu');

  return $iso639;

}

function available_languages(){

  $iso639 = iso639();
  $lang = array();

  foreach ($lang as $id => $lang){
    if (is_dir('languages/'.strtolower($lang))){
      $lang[] = $lang;
    }
  }

  return $lang;

}


function get_available_languages(){
    $dirs = array();
    if ($handle=opendir('languages')){
	while ($file = readdir($handle)) {
	    if (is_dir('languages/'.$file) && 
		$file != '.' && $file != '..' && $file != 'CVS'){
	      if (file_exists('languages/'.$file.'/id.txt')){
		$lines=@file('languages/'.$file.'/id.txt');
		$lang = rtrim(array_shift($lines));
		$dirs[$lang] = $file;
	      }
	      else{
		$dirs[$file] = $file;
		// array_push($dirs,$file);
	      }
	    }
	}
	closedir($handle);
    }
    return $dirs;
}


function sb_language( $page ){
  global $blog_config;
  global $blog_page;

  $default_lang = 'english';
  $blog_page = $page;

  // load default language strings

  if (is_dir('languages/'.$default_lang)){
    if (is_file('languages/'.$default_lang.'/strings.php')){
      require('languages/'.$default_lang.'/strings.php');
    }
  }


  // overwrite with blog language strings

  if ($blog_config[ 'blog_language' ] != $default_lang){
    if (is_dir('languages/'.$blog_config[ 'blog_language' ])){
      if (is_file('languages/'.$blog_config[ 'blog_language' ].'/strings.php')){
	require('languages/'.$blog_config[ 'blog_language' ].'/strings.php');
      }
    }
  }

}


?>