[svn r14083] Added language file import method

skala
Yannick Warnier 17 years ago
parent a3bbce576a
commit c2bfae5465
  1. 3
      main/webrooms/checksession.php
  2. 59
      main/webrooms/get_translation.lib.php

@ -10,6 +10,7 @@ require_once('../newscorm/scorm.class.php');
require_once('../newscorm/scormItem.class.php');
require_once('../newscorm/aicc.class.php');
require_once('../newscorm/aiccItem.class.php');
require_once('get_translation.lib.php');
include("../../main/inc/global.inc.php");
api_block_anonymous_users();
@ -72,7 +73,7 @@ printf(' <studentview>%s</studentview>',$student_view);
printf(' <documentid>%s</documentid>',$document_id);
printf('</recorderparams>');
printf('<languageobject>');
include_once($language_interface.'.xml');
printf(get_language_file_as_xml($language_interface));
printf('</languageobject>');
printf('</dokeosobject>');
?>

@ -0,0 +1,59 @@
<?php
/**
* Library for language translation from Dokeos language files to XML for videoconference
* @uses main_api.lib.php for api_get_path()
*/
/**
* This function reads a Dokeos language file and transforms it into XML,
* then returns the XML string to the caller.
*/
function get_language_file_as_xml($language='english')
{
$path = api_get_path(SYS_LANG_PATH).$language.'/';
if(!is_dir($path) or !is_readable($path))
{
if($language != 'english')
{
return get_language_file_as_xml('english');
}
else
{
return '';
}
}
error_log('Analysing path '.$path);
$file = $path.'videoconf.inc.php';
if(!is_file($file) or !is_readable($file))
{
if($language != 'english')
{
return get_language_file_as_xml('english');
}
else
{
return '';
}
}
$list = file($file);
$xml = '';
foreach ( $list as $line )
{
if(substr($line,0,1)=='$')
{
$items = array();
$match = preg_match('/^\$([^\s]*)\s*=\s*"(.*)";$/',$line,$items);
if($match)
{
//todo: The following conversion should only happen for old language files (encoded in ISO-8859-1).
$string = iconv('ISO-8859-1','UTF-8',$items[2]);
$xml .= '<labelfield><labelid>'.$items[1].'</labelid><labelvalue>'.$string.'</labelvalue></labelfield>'."\n";
}
}
}
if(empty($xml) && $language!='english')
{
return get_language_file_as_xml('english');
}
return $xml;
}
?>
Loading…
Cancel
Save