'#description'=>t('A path relative to the Drupal installation directory where translation files will be stored, e.g. sites/all/translations. Saved translation files can be reused by other installations. If left empty the downloaded translation will not be saved.'),
);
returnsystem_settings_form($form);
}
/**
* Additional validation handler for update settings.
*
* Check for existing files directory and creates one when required.
form_set_error('l10n_update_download_store',t('The directory %directory does not exist or is not writable.',array('%directory'=>$form_values['l10n_update_download_store'])));
watchdog('file system','The directory %directory does not exist or is not writable.',array('%directory'=>$form_values['l10n_update_download_store']),WATCHDOG_ERROR);
}
}
}
/**
* Get array of import options.
*
* The import options of the Locale module are used but the UI text is altered
* to suit the Localization update cases.
*
* @return
* Keyed array of import options.
*/
function_l10n_update_admin_import_options(){
returnarray(
LOCALE_IMPORT_OVERWRITE=>t('Translation updates replace existing ones, new ones are added'),
LOCALE_UPDATE_OVERRIDE_DEFAULT=>t('Edited translations are kept, only previously imported ones are overwritten and new translations are added'),
LOCALE_IMPORT_KEEP=>t('All existing translations are kept, only new translations are added.'),
);
}
/**
* Get array of check options.
*
* @return
* Keyed array of source download options.
*/
function_l10n_update_admin_check_options(){
returnarray(
L10N_UPDATE_CHECK_ALL=>t('Local files and remote server.'),
L10N_UPDATE_CHECK_LOCAL=>t('Local files only.'),
L10N_UPDATE_CHECK_REMOTE=>t('Remote server only.'),
);
}
/**
* Format project update status.
*
* @param $variables
* An associative array containing:
* - projects: An array containing all enabled projects.
* - languages: An array of all enabled languages.
* - history: An array of the current translations per project.
* - available: An array of translation sources per project.
* - updates: An array of available translation updates per project.
* Object representing the file just imported or downloaded.
* @return integer
* FALSE on failure. Otherwise SAVED_NEW or SAVED_UPDATED.
* @see drupal_write_record()
*/
functionl10n_update_file_history($file){
// Update or write new record
if(db_query("SELECT project FROM {l10n_update_file} WHERE project = :project AND language = :language",array(':project'=>$file->project,':language'=>$file->language))->fetchField()){
'description'=>'Update information for project translations.',
'fields'=>array(
'name'=>array(
'description'=>'A unique short name to identify the project.',
'type'=>'varchar',
'length'=>'50',
'not null'=>TRUE,
),
'project_type'=>array(
'description'=>'Project type, may be core, module, theme',
'type'=>'varchar',
'length'=>'50',
'not null'=>TRUE,
),
'core'=>array(
'description'=>'Core compatibility string for this project.',
'type'=>'varchar',
'length'=>'128',
'not null'=>TRUE,
'default'=>'',
),
'version'=>array(
'description'=>'Human readable name for project used on the interface.',
'type'=>'varchar',
'length'=>'128',
'not null'=>TRUE,
'default'=>'',
),
'l10n_server'=>array(
'description'=>'Localization server for this project.',
'type'=>'varchar',
'length'=>'255',
'not null'=>TRUE,
'default'=>'',
),
'l10n_path'=>array(
'description'=>'Server path this project updates.',
'type'=>'varchar',
'length'=>'255',
'not null'=>TRUE,
'default'=>'',
),
'status'=>array(
'description'=>'Status flag. TBD',
'type'=>'int',
'not null'=>TRUE,
'default'=>1,
),
),
'primary key'=>array('name'),
);
$schema['l10n_update_file']=array(
'description'=>'File and download information for project translations.',
'fields'=>array(
'project'=>array(
'description'=>'A unique short name to identify the project.',
'type'=>'varchar',
'length'=>'50',
'not null'=>TRUE,
),
'language'=>array(
'description'=>'Reference to the {languages}.language for this translation.',
'type'=>'varchar',
'length'=>'12',
'not null'=>TRUE,
),
'type'=>array(
'description'=>'File origin: download or localfile',
'type'=>'varchar',
'length'=>'50',
'not null'=>TRUE,
'default'=>'',
),
'filename'=>array(
'description'=>'Link to translation file for download.',
'type'=>'varchar',
'length'=>255,
'not null'=>TRUE,
'default'=>'',
),
'fileurl'=>array(
'description'=>'Link to translation file for download.',
'type'=>'varchar',
'length'=>255,
'not null'=>TRUE,
'default'=>'',
),
'uri'=>array(
'description'=>'File system path for importing the file.',
'type'=>'varchar',
'length'=>255,
'not null'=>TRUE,
'default'=>'',
),
'timestamp'=>array(
'description'=>'Unix timestamp of the time the file was downloaded or saved to disk. Zero if not yet downloaded',
'type'=>'int',
'not null'=>FALSE,
'disp-width'=>'11',
'default'=>0,
),
'version'=>array(
'description'=>'Version tag of the downloaded file.',
'type'=>'varchar',
'length'=>'128',
'not null'=>TRUE,
'default'=>'',
),
'status'=>array(
'description'=>'Status flag. TBD',
'type'=>'int',
'not null'=>TRUE,
'default'=>1,
),
'last_checked'=>array(
'description'=>'Unix timestamp of the last time this translation was downloaded from or checked at remote server and confirmed to be the most recent release available.',
$schema['cache_l10n_update']['description']='Cache table for the Localization Update module to store information about available releases, fetched from central server.';
$requirements['l10n_update']['value']=t('There are available updates');
$requirements['l10n_update']['description']=t(
'There are new or updated translations available for currently installed modules and themes. To check for updates, you can visit the <a href="@check_manually">translation update page</a>.',
drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.',array('%filename'=>$file->filename)),'error');
}
// Clear cache and force refresh of JavaScript translations.
_locale_invalidate_js($langcode);
cache_clear_all('locale:','cache',TRUE);
// Rebuild the menu, strings may have changed.
menu_rebuild();
watchdog('locale','Imported %file into %locale: %number new strings added, %update updated and %delete removed.',array('%file'=>$file->filename,'%locale'=>$langcode,'%number'=>$additions,'%update'=>$updates,'%delete'=>$deletes));
if($skips){
watchdog('locale','@count disallowed HTML string(s) in %file',array('@count'=>$skips,'%file'=>$file->uri),WATCHDOG_WARNING);
}
// Return results of this import.
returnarray(
'file'=>$file,
'language'=>$langcode,
'add'=>$additions,
'update'=>$updates,
'delete'=>$deletes,
'skip'=>$skips,
);
}
/**
* Parses Gettext Portable Object file into an array
*
* @param $op
* Storage operation type: db-store or mem-store
* @param $file
* Drupal file object corresponding to the PO file to import
* @param $mode
* Should existing translations be replaced LOCALE_IMPORT_KEEP or LOCALE_IMPORT_OVERWRITE
* @param $lang
* Language code
* @param $group
* Text group to import PO file into (eg. 'default' for interface translations)
elseif(!empty($current["msgctxt"])){// Already in this context? Parse error
_locale_import_message('The translation file %filename contains an error: "msgctxt" is unexpected on line %line.',$file,$lineno);
returnFALSE;
}
$line=trim(substr($line,7));
$quoted=_locale_import_parse_quoted($line);
if($quoted===FALSE){
_locale_import_message('The translation file %filename contains a syntax error on line %line.',$file,$lineno);
returnFALSE;
}
$current["msgctxt"]=$quoted;
$context="MSGCTXT";
}
elseif(!strncmp("msgstr[",$line,7)){
if(($context!="MSGID")&&($context!="MSGCTXT")&&($context!="MSGID_PLURAL")&&($context!="MSGSTR_ARR")){// Must come after msgid, msgxtxt, msgid_plural, or msgstr[]
_locale_import_message('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.',$file,$lineno);
returnFALSE;
}
if(strpos($line,"]")===FALSE){
_locale_import_message('The translation file %filename contains a syntax error on line %line.',$file,$lineno);
$lid=db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup",array(':source'=>$source,':context'=>$context,':textgroup'=>$textgroup))->fetchField();
if(!empty($translation)){
// Skip this string unless it passes a check for dangerous code.
// Text groups other than default still can contain HTML tags
watchdog('locale','Disallowed HTML detected. String not imported: %string',array('%string'=>$translation),WATCHDOG_WARNING);
}
elseif($lid){
// We have this source string saved already.
db_update('locales_source')
->fields(array(
'location'=>$location,
))
->condition('lid',$lid)
->execute();
$exists=db_query("SELECT lid, l10n_status FROM {locales_target} WHERE lid = :lid AND language = :language",array(':lid'=>$lid,':language'=>$langcode))->fetchObject();
* Translation import mode keeping translations which are edited after enabling
* Locale Update module an only override default (un-edited) translations.
*/
define('LOCALE_UPDATE_OVERRIDE_DEFAULT',2);
/**
* The maximum number of projects which are checked for available translations each cron run.
*/
define('L10N_UPDATE_CRON_PROJECTS',10);
/**
* The maximum number of projects which are updated each cron run.
*/
define('L10N_UPDATE_CRON_UPDATES',2);
/**
* Implements hook_help().
*/
functionl10n_update_help($path,$arg){
switch($path){
case'admin/config/regional/translate/update':
$output='<p>'.t('List of latest imported translations and available updates for each enabled project and language.').'</p>';
$output.='<p>'.t('If there are available updates you can click on Update for them to be downloaded and imported now or you can edit the configuration for them to be updated automatically on the <a href="@update-settings">Update settings page</a>',array('@update-settings'=>url('admin/config/regional/language/update'))).'</p>';
return$output;
break;
case'admin/config/regional/language/update':
$output='<p>'.t('These are the settings for the translation update system. To update your translations now, check out the <a href="@update-admin">Translation update administration page</a>.',array('@update-admin'=>url('admin/config/regional/translate/update'))).'</p>';
$translation=db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language",array(':lid'=>$lid,':language'=>$key))->fetchField();
if(!empty($value)){
// Only update or insert if we have a value to use.
if(!empty($translation)){
db_update('locales_target')
->fields(array(
'translation'=>$value,
'l10n_status'=>L10N_UPDATE_STRING_CUSTOM,
))
->condition('lid',$lid)
->condition('language',$key)
->execute();
}
else{
db_insert('locales_target')
->fields(array(
'lid'=>$lid,
'translation'=>$value,
'language'=>$key,
'l10n_status'=>L10N_UPDATE_STRING_CUSTOM,
))
->execute();
}
}
elseif(!empty($translation)){
// Empty translation entered: remove existing entry from database.
db_delete('locales_target')
->condition('lid',$lid)
->condition('language',$key)
->execute();
}
// Force JavaScript translation file recreation for this language.
_locale_invalidate_js($key);
}
drupal_set_message(t('The string has been saved.'));
// Ensure we have this source string before we attempt to save it.
// @todo: add actual context support.
$lid=db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup",array(':source'=>$_POST['source'],':context'=>'',':textgroup'=>$_POST['textgroup']))->fetchField();
$message.=theme('l10n_client_message',array('message'=>t('You could share your work with !l10n_server if you set your API key at !user_link.',array('!l10n_server'=>l($server_url,$server_url),'!user_link'=>l($user_edit_url,'user/'.$user->uid.'/edit'))),'level'=>WATCHDOG_WARNING));
}
}
}
else{
$message=theme('l10n_client_message',array('message'=>t('Not saved due to source string missing.')));
}
}
else{
$message=theme('l10n_client_message',array('message'=>t('Not saved due to missing form values.')));
}
}
else{
$message=theme('l10n_client_message',array('message'=>t('Not saved due to insufficient permissions.')));
* Build the warning message for when there is no data about available updates.
*
* @return sting
* Message text with links.
*/
function_l10n_update_no_data(){
$destination=drupal_get_destination();
returnt('No information is available about potential new and updated translations for currently installed modules and themes. To check for updates, you may need to <a href="@run_cron">run cron</a> or you can <a href="@check_manually">check manually</a>. Please note that checking for available updates can take a long time, so please be patient.',array(