watchdog('locale',t('Translation imported into %locale, %number translated strings added to language, %update strings updated.',array('%locale'=>"<em>$lang</em>",'%number'=>$additions,'%update'=>$updates)));
watchdog('special',t('Imported %file into %locale: %number new strings added and %update updated.',array('%file'=>"<em>$file->filename</em>",'%locale'=>"<em>$lang</em>",'%number'=>$additions,'%update'=>$updates)));
returnTRUE;
}
/**
* Parses Gettext Portable Object file into an array
*
* @param $path Name of local file to parse
* @param $file Object with properties of local file to parse
* @author Jacobo Tarrio
*/
function_locale_import_read_po($path){
function_locale_import_read_po($file){
$fd=fopen($path,"rb");
$fd=fopen($file->filepath,"rb");
if(!$fd){
drupal_set_message(t('Translation import failed: file %filename cannot be read.',array('%filename'=>"<em>$path</em>")),'error');
drupal_set_message(t('Translation import failed: file %filename cannot be read.',array('%filename'=>"<em>$file->filename</em>")),'error');
returnFALSE;
}
$info=fstat($fd);
...
...
@@ -303,19 +303,19 @@ function _locale_import_read_po($path) {
$context="COMMENT";
}
else{// Parse error
drupal_set_message(t("Translation file broken: expected 'msgstr' in line %line.",array('%line'=>$lineno)),'error');
drupal_set_message(t("Translation file %filename broken: expected 'msgstr' in line %line.",array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
}
elseif(!strncmp("msgid_plural",$line,12)){
if($context!="MSGID"){// Must be plural form for current entry
drupal_set_message(t("Translation file broken: unexpected 'msgid_plural' in line %line.",array('%line'=>$lineno)),'error');
drupal_set_message(t("Translation file %filename broken: unexpected 'msgid_plural' in line %line.",array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$line=trim(substr($line,12));
$quoted=_locale_import_parse_quoted($line);
if($quoted===false){
drupal_set_message(t('Translation file broken: syntax error in line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: syntax error in line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$current["msgid"]=$current["msgid"]."\0".$quoted;
...
...
@@ -327,13 +327,13 @@ function _locale_import_read_po($path) {
$current=array();
}
elseif($context=="MSGID"){// Already in this context? Parse error
drupal_set_message(t("Translation file broken: unexpected 'msgid' in line %line.",array('%line'=>$lineno)),'error');
drupal_set_message(t("Translation file %filename broken: unexpected 'msgid' in line %line.",array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$line=trim(substr($line,5));
$quoted=_locale_import_parse_quoted($line);
if($quoted===false){
drupal_set_message(t('Translation file broken: syntax error in line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: syntax error in line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$current["msgid"]=$quoted;
...
...
@@ -341,11 +341,11 @@ function _locale_import_read_po($path) {
}
elseif(!strncmp("msgstr[",$line,7)){
if(($context!="MSGID")&&($context!="MSGID_PLURAL")&&($context!="MSGSTR_ARR")){// Must come after msgid, msgid_plural, or msgstr[]
drupal_set_message(t("Translation file broken: unexpected 'msgstr[]' in line %line.",array('%line'=>$lineno)),'error');
drupal_set_message(t("Translation file %filename broken: unexpected 'msgstr[]' in line %line.",array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
if(strpos($line,"]")===false){
drupal_set_message(t('Translation file broken: syntax error in line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: syntax error in line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$frombracket=strstr($line,"[");
...
...
@@ -353,7 +353,7 @@ function _locale_import_read_po($path) {
$line=trim(strstr($line," "));
$quoted=_locale_import_parse_quoted($line);
if($quoted===false){
drupal_set_message(t('Translation file broken: syntax error in line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: syntax error in line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$current["msgstr"][$plural]=$quoted;
...
...
@@ -361,13 +361,13 @@ function _locale_import_read_po($path) {
}
elseif(!strncmp("msgstr",$line,6)){
if($context!="MSGID"){// Should come just after a msgid block
drupal_set_message(t("Translation file broken: unexpected 'msgstr' in line %line.",array('%line'=>$lineno)),'error');
drupal_set_message(t("Translation file %filename broken: unexpected 'msgstr' in line %line.",array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$line=trim(substr($line,6));
$quoted=_locale_import_parse_quoted($line);
if($quoted===false){
drupal_set_message(t('Translation file broken: syntax error in line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: syntax error in line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
$current["msgstr"]=$quoted;
...
...
@@ -376,7 +376,7 @@ function _locale_import_read_po($path) {
elseif($line!=""){
$quoted=_locale_import_parse_quoted($line);
if($quoted===false){
drupal_set_message(t('Translation file broken: syntax error in line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: syntax error in line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
@@ -389,7 +389,7 @@ function _locale_import_read_po($path) {
$current["msgstr"][$plural].=$quoted;
}
else{
drupal_set_message(t('Translation file broken: unexpected string in line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: unexpected string in line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
}
...
...
@@ -400,7 +400,7 @@ function _locale_import_read_po($path) {
$strings[$current["msgid"]]=$current;
}
elseif($context!="COMMENT"){
drupal_set_message(t('Translation file broken: unexpected end file at line %line.',array('%line'=>$lineno)),'error');
drupal_set_message(t('Translation file %filename broken: unexpected end file at line %line.',array('%filename'=>"<em>$file->filename</em>",'%line'=>$lineno)),'error');
returnFALSE;
}
...
...
@@ -433,11 +433,12 @@ function _locale_import_parse_header($header) {
* Parses a Plural-Forms entry from a Gettext Portable Object file header
*
* @param $pluralforms A string containing the Plural-Forms entry
* @param $filename A string containing the filename
* @return An array containing the number of plurals and a