PHP Classes
elePHPant
Icontem

File: lib/translate.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of andreas altendorfer  >  XML Weblication  >  lib/translate.php  >  Download  
File: lib/translate.php
Role: Application script
Content type: text/plain
Description: Function translate()
Class: XML Weblication
XML based content management framework
Author: By
Last change:
Date: 11 years ago
Size: 896 bytes
 

Contents

Class file image Download
<?php
function translate( $search ) {
  global
$translation_table, $translation_loaded;
if ( !
$translation_loaded ) load_translation_table();
 
 
$rc = $search;
 
reset( $translation_table );
  for(
$i = 0; $i < count( $translation_table ); $i++ ) {
    if (
strlen(strstr($translation_table[$i][0],$search))==strlen($search) ) {
     
$rc = $translation_table[$i][1];
      break;
    }
  }
  return(
$rc );
}

function
load_translation_table()
{
  global
$cfg,$translation_table, $translation_loaded;
 
 
$fn = $cfg["translation-file"];
  if ( !
file_exists( $fn ) ) {
   
Fatal( "Couldn't load translation table $fn" );
  }
 
 
 
$f = fopen( $fn, "r" );
  if ( !
$f ) Fatal ( "Couldn't open/read file $fn" );
 
  while(
$ls = fgets( $f, 4096 ) ) {
   
$a = explode(":",$ls,2);
   
$translation_table[] = $a;
  }
 
reset( $translation_table );
 
$translation_loaded = true;
 
 
fclose($f);
}
?>