2004-08-11 11:26:20 +00:00
< ? php
// $Id$
2004-08-21 06:42:38 +00:00
2004-08-11 11:26:20 +00:00
/**
* @ file
2007-05-03 09:51:08 +00:00
* Administration functions for locale . module .
2004-08-11 11:26:20 +00:00
*/
/**
2007-05-03 09:51:08 +00:00
* @ defgroup locale - language - overview Language overview functionality
* @ {
2004-08-11 11:26:20 +00:00
*/
/**
2007-05-03 09:51:08 +00:00
* User interface for the language overview screen .
2004-08-11 11:26:20 +00:00
*/
2007-05-03 09:51:08 +00:00
function locale_languages_overview_form () {
2007-03-26 01:32:22 +00:00
$languages = language_list ( 'language' , TRUE );
2004-08-11 11:26:20 +00:00
2005-10-07 06:11:12 +00:00
$options = array ();
2007-03-26 01:32:22 +00:00
$form [ 'weight' ] = array ( '#tree' => TRUE );
foreach ( $languages as $langcode => $language ) {
2004-08-12 18:00:11 +00:00
2007-03-26 01:32:22 +00:00
$options [ $langcode ] = '' ;
if ( $language -> enabled ) {
$enabled [] = $langcode ;
2004-08-11 11:26:20 +00:00
}
2007-03-26 01:32:22 +00:00
$form [ 'weight' ][ $langcode ] = array (
'#type' => 'weight' ,
'#default_value' => $language -> weight
);
$form [ 'name' ][ $langcode ] = array ( '#value' => check_plain ( $language -> name ));
$form [ 'native' ][ $langcode ] = array ( '#value' => check_plain ( $language -> native ));
2007-05-03 09:51:08 +00:00
$form [ 'direction' ][ $langcode ] = array ( '#value' => ( $language -> direction == LANGUAGE_RTL ? 'Right to left' : 'Left to right' ));
2004-08-11 11:26:20 +00:00
}
2006-03-17 18:35:56 +00:00
$form [ 'enabled' ] = array ( '#type' => 'checkboxes' ,
'#options' => $options ,
'#default_value' => $enabled ,
);
2007-03-26 01:32:22 +00:00
$default = language_default ();
2006-03-17 18:35:56 +00:00
$form [ 'site_default' ] = array ( '#type' => 'radios' ,
'#options' => $options ,
2007-03-26 01:32:22 +00:00
'#default_value' => $default -> language ,
2006-03-17 18:35:56 +00:00
);
2005-10-11 19:44:35 +00:00
$form [ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save configuration' ));
2007-05-03 09:51:08 +00:00
$form [ '#theme' ] = 'locale_languages_overview_form' ;
2005-10-07 06:51:43 +00:00
2006-08-18 18:58:47 +00:00
return $form ;
2005-10-07 06:11:12 +00:00
}
2004-08-12 18:00:11 +00:00
2006-03-17 18:35:56 +00:00
/**
2007-05-03 09:51:08 +00:00
* Theme the langauge overview form .
2006-03-17 18:35:56 +00:00
*/
2007-05-03 09:51:08 +00:00
function theme_locale_languages_overview_form ( $form ) {
2007-04-09 14:46:55 +00:00
$default = language_default ();
2005-10-07 06:11:12 +00:00
foreach ( $form [ 'name' ] as $key => $element ) {
2006-03-17 18:35:56 +00:00
// Do not take form control structures.
2005-10-07 06:11:12 +00:00
if ( is_array ( $element ) && element_child ( $key )) {
2007-05-03 09:51:08 +00:00
$rows [] = array ( array ( 'data' => drupal_render ( $form [ 'enabled' ][ $key ]), 'align' => 'center' ), check_plain ( $key ), '<strong>' . drupal_render ( $form [ 'name' ][ $key ]) . '</strong>' , drupal_render ( $form [ 'native' ][ $key ]), drupal_render ( $form [ 'direction' ][ $key ]), drupal_render ( $form [ 'site_default' ][ $key ]), drupal_render ( $form [ 'weight' ][ $key ]), l ( t ( 'edit' ), 'admin/settings/language/edit/' . $key ) . (( $key != 'en' && $key != $default -> language ) ? ' ' . l ( t ( 'delete' ) , 'admin/settings/language/delete/' . $key ) : '' ));
2005-10-07 06:11:12 +00:00
}
}
2007-03-26 01:32:22 +00:00
$header = array ( array ( 'data' => t ( 'Enabled' )), array ( 'data' => t ( 'Code' )), array ( 'data' => t ( 'English name' )), array ( 'data' => t ( 'Native name' )), array ( 'data' => t ( 'Direction' )), array ( 'data' => t ( 'Default' )), array ( 'data' => t ( 'Weight' )), array ( 'data' => t ( 'Operations' )));
2005-10-07 06:11:12 +00:00
$output = theme ( 'table' , $header , $rows );
2006-08-10 15:42:33 +00:00
$output .= drupal_render ( $form );
2006-04-17 20:48:26 +00:00
2005-10-07 06:11:12 +00:00
return $output ;
2004-08-11 11:26:20 +00:00
}
/**
2007-05-03 09:51:08 +00:00
* Process language overview form submissions , updating existing languages .
2004-08-11 11:26:20 +00:00
*/
2007-05-03 09:51:08 +00:00
function locale_languages_overview_form_submit ( $form_id , $form_values ) {
2007-03-26 01:32:22 +00:00
$languages = language_list ();
$enabled_count = 0 ;
foreach ( $languages as $langcode => $language ) {
if ( $form_values [ 'site_default' ] == $langcode ) {
2007-05-03 09:51:08 +00:00
// Automatically enable the default language.
$form_values [ 'enabled' ][ $langcode ] = 1 ;
2006-03-17 18:35:56 +00:00
}
2007-03-26 01:32:22 +00:00
if ( $form_values [ 'enabled' ][ $langcode ]) {
$enabled_count ++ ;
$language -> enabled = 1 ;
2006-03-17 18:35:56 +00:00
}
else {
2007-03-26 01:32:22 +00:00
$language -> enabled = 0 ;
2006-03-17 18:35:56 +00:00
}
2007-03-26 01:32:22 +00:00
$language -> weight = $form_values [ 'weight' ][ $langcode ];
db_query ( " UPDATE { languages} SET enabled = %d, weight = %d WHERE language = '%s' " , $language -> enabled , $language -> weight , $langcode );
$languages [ $langcode ] = $language ;
2006-03-17 18:35:56 +00:00
}
drupal_set_message ( t ( 'Configuration saved.' ));
2007-03-26 01:32:22 +00:00
variable_set ( 'language_default' , $languages [ $form_values [ 'site_default' ]]);
variable_set ( 'language_count' , $enabled_count );
2006-04-17 20:48:26 +00:00
2007-03-26 01:32:22 +00:00
// Changing the language settings impacts the interface.
2006-08-30 08:46:17 +00:00
cache_clear_all ( '*' , 'cache_page' , TRUE );
2004-08-12 18:00:11 +00:00
2007-05-03 09:51:08 +00:00
return 'admin/settings/language' ;
}
/**
* @ } End of " locale-language-overview "
*/
/**
* @ defgroup locale - language - add - edit Language addition and editing functionality
* @ {
*/
/**
* User interface for the language addition screen .
*/
function locale_languages_add_screen () {
$output = drupal_get_form ( 'locale_languages_predefined_form' );
$output .= drupal_get_form ( 'locale_languages_custom_form' );
return $output ;
2006-03-17 18:35:56 +00:00
}
2007-03-26 01:32:22 +00:00
/**
* Predefined language setup form .
*/
2007-05-03 09:51:08 +00:00
function locale_languages_predefined_form () {
2007-03-26 01:32:22 +00:00
$predefined = _locale_prepare_predefined_list ();
2005-10-07 06:11:12 +00:00
$form = array ();
2006-03-17 18:35:56 +00:00
$form [ 'language list' ] = array ( '#type' => 'fieldset' ,
2007-03-26 01:32:22 +00:00
'#title' => t ( 'Predefined language' ),
2006-03-17 18:35:56 +00:00
'#collapsible' => TRUE ,
);
$form [ 'language list' ][ 'langcode' ] = array ( '#type' => 'select' ,
'#title' => t ( 'Language name' ),
2007-03-26 01:32:22 +00:00
'#default_value' => key ( $predefined ),
'#options' => $predefined ,
'#description' => t ( 'Select the desired language here, or add it below, if you are unable to find it in the list.' ),
2006-03-17 18:35:56 +00:00
);
$form [ 'language list' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Add language' ));
2006-08-18 18:58:47 +00:00
return $form ;
}
2006-04-17 20:48:26 +00:00
2007-03-26 01:32:22 +00:00
/**
* Custom language addition form .
*/
2007-05-03 09:51:08 +00:00
function locale_languages_custom_form () {
2005-10-07 06:11:12 +00:00
$form = array ();
2006-03-17 18:35:56 +00:00
$form [ 'custom language' ] = array ( '#type' => 'fieldset' ,
'#title' => t ( 'Custom language' ),
'#collapsible' => TRUE ,
);
2007-05-03 09:51:08 +00:00
_locale_languages_common_controls ( $form [ 'custom language' ]);
2007-03-26 01:32:22 +00:00
$form [ 'custom language' ][ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Add custom language' )
2006-03-17 18:35:56 +00:00
);
2007-05-03 09:51:08 +00:00
// Reuse the validation and submit functions of the predefined language setup form.
$form [ '#submit' ][ 'locale_languages_predefined_form_submit' ] = array ();
$form [ '#validate' ][ 'locale_languages_predefined_form_validate' ] = array ();
2007-03-26 01:32:22 +00:00
return $form ;
}
/**
* Editing screen for a particular language .
*
* @ param $langcode
2007-03-28 14:08:23 +00:00
* Language code of the language to edit .
2007-03-26 01:32:22 +00:00
*/
2007-05-03 09:51:08 +00:00
function locale_languages_edit_form ( $langcode ) {
2007-03-26 01:32:22 +00:00
if ( $language = db_fetch_object ( db_query ( " SELECT * FROM { languages} WHERE language = '%s' " , $langcode ))) {
$form = array ();
2007-05-03 09:51:08 +00:00
_locale_languages_common_controls ( $form , $language );
2007-03-26 01:32:22 +00:00
$form [ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Save language' )
);
2007-05-03 09:51:08 +00:00
$form [ '#submit' ][ 'locale_languages_edit_form_submit' ] = array ();
$form [ '#validate' ][ 'locale_languages_edit_form_validate' ] = array ();
2007-03-26 01:32:22 +00:00
return $form ;
}
else {
drupal_not_found ();
}
}
/**
2007-05-03 09:51:08 +00:00
* Common elements of the language addition and editing form .
2007-03-26 01:32:22 +00:00
*
* @ param $form
* A parent form item ( or empty array ) to add items below .
* @ param $language
* Language object to edit .
*/
2007-05-03 09:51:08 +00:00
function _locale_languages_common_controls ( & $form , $language = NULL ) {
2007-03-26 01:32:22 +00:00
if ( ! is_object ( $language )) {
$language = new stdClass ();
}
if ( isset ( $language -> language )) {
$form [ 'langcode_view' ] = array (
'#type' => 'item' ,
'#title' => t ( 'Language code' ),
'#value' => $language -> language
);
$form [ 'langcode' ] = array (
'#type' => 'value' ,
'#value' => $language -> language
);
}
else {
$form [ 'langcode' ] = array ( '#type' => 'textfield' ,
'#title' => t ( 'Language code' ),
'#size' => 12 ,
'#maxlength' => 60 ,
'#required' => TRUE ,
'#default_value' => @ $language -> language ,
'#disabled' => ( isset ( $language -> language )),
'#description' => t ( 'This should be an <a href="@rfc4646">RFC 4646</a> compliant language identifier. Basic tags use a country code with an optional script or regional variant name, like "en", "en-US" and "zh-Hant".' , array ( '@rfc4646' => 'http://www.ietf.org/rfc/rfc4646.txt' )),
);
}
2007-03-28 14:08:23 +00:00
$form [ 'name' ] = array ( '#type' => 'textfield' ,
2006-03-17 18:35:56 +00:00
'#title' => t ( 'Language name in English' ),
'#maxlength' => 64 ,
2007-03-26 01:32:22 +00:00
'#default_value' => @ $language -> name ,
2006-03-17 18:35:56 +00:00
'#required' => TRUE ,
'#description' => t ( 'Name of the language. Will be available for translation in all languages.' ),
);
2007-03-28 14:08:23 +00:00
$form [ 'native' ] = array ( '#type' => 'textfield' ,
2007-03-26 01:32:22 +00:00
'#title' => t ( 'Native language name' ),
'#maxlength' => 64 ,
'#default_value' => @ $language -> native ,
'#required' => TRUE ,
'#description' => t ( 'Name of the language in the language being added.' ),
);
$form [ 'prefix' ] = array ( '#type' => 'textfield' ,
'#title' => t ( 'Path prefix' ),
'#maxlength' => 64 ,
'#default_value' => @ $language -> prefix ,
'#description' => t ( 'Optional path prefix, for example "deutsch" for the German version. This value is not used in the "None" and "Domain" negotiation schemes. You can leave this empty if you use "Path only" negotiation and this is the default language. Changing this will break existing URLs.' )
);
$form [ 'domain' ] = array ( '#type' => 'textfield' ,
'#title' => t ( 'Language domain' ),
'#maxlength' => 64 ,
'#default_value' => @ $language -> domain ,
'#description' => t ( 'Optional custom domain with protocol (eg. "http://example.de" or "http://de.example.com" for the German version). This value is only used in the "Domain" negotiation mode. If left empty and in "Domain" mode, this language will not be accessible.' ),
);
$form [ 'direction' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Direction' ),
'#required' => TRUE ,
'#description' => t ( 'Direction of the text being written in this language.' ),
'#default_value' => @ $language -> direction ,
2007-05-03 09:51:08 +00:00
'#options' => array ( LANGUAGE_LTR => t ( 'Left to right' ), LANGUAGE_RTL => t ( 'Right to left' ))
2007-03-26 01:32:22 +00:00
);
2006-08-18 18:58:47 +00:00
return $form ;
}
2004-08-11 11:26:20 +00:00
/**
2006-03-17 18:35:56 +00:00
* Validate the language addition form .
*/
2007-05-03 09:51:08 +00:00
function locale_languages_predefined_form_validate ( $form_id , $form_values ) {
$langcode = $form_values [ 'langcode' ];
if ( $duplicate = db_num_rows ( db_query ( " SELECT language FROM { languages} WHERE language = '%s' " , $langcode )) != 0 ) {
form_set_error ( 'langcode' , t ( 'The language %language (%code) already exists.' , array ( '%language' => $form_values [ 'name' ], '%code' => $langcode )));
2006-03-17 18:35:56 +00:00
}
2007-03-28 14:08:23 +00:00
if ( ! isset ( $form_values [ 'name' ])) {
2007-03-26 01:32:22 +00:00
// Predefined language selection.
$predefined = _locale_get_predefined_list ();
2007-05-03 09:51:08 +00:00
if ( ! isset ( $predefined [ $langcode ])) {
2006-03-17 18:35:56 +00:00
form_set_error ( 'langcode' , t ( 'Invalid language code.' ));
}
}
2007-03-26 01:32:22 +00:00
else {
2007-05-03 09:51:08 +00:00
// Reuse the editing form validation routine if we add a custom language.
locale_languages_edit_form_validate ( $form_id , $form_values );
2007-03-26 01:32:22 +00:00
}
2006-03-17 18:35:56 +00:00
}
/**
* Process the language addition form submission .
*/
2007-05-03 09:51:08 +00:00
function locale_languages_predefined_form_submit ( $form_id , $form_values ) {
$langcode = $form_values [ 'langcode' ];
2007-03-28 14:08:23 +00:00
if ( isset ( $form_values [ 'name' ])) {
2006-03-17 18:35:56 +00:00
// Custom language form.
2007-05-03 09:51:08 +00:00
locale_add_language ( $langcode , $form_values [ 'name' ], $form_values [ 'native' ], $form_values [ 'direction' ], $form_values [ 'domain' ], $form_values [ 'prefix' ]);
2006-03-17 18:35:56 +00:00
}
else {
2007-03-26 01:32:22 +00:00
// Predefined language selection.
$predefined = _locale_get_predefined_list ();
2007-05-03 09:51:08 +00:00
$lang = & $predefined [ $langcode ];
locale_add_language ( $langcode , $lang [ 0 ], isset ( $lang [ 1 ]) ? $lang [ 1 ] : $lang [ 0 ], isset ( $lang [ 2 ]) ? $lang [ 2 ] : 0 , '' , $langcode );
2007-03-26 01:32:22 +00:00
}
2007-05-03 09:51:08 +00:00
return 'admin/settings/language' ;
2007-03-26 01:32:22 +00:00
}
/**
* Validate the language editing form . Reused for custom language addition too .
*/
2007-05-03 09:51:08 +00:00
function locale_languages_edit_form_validate ( $form_id , $form_values ) {
2007-03-26 01:32:22 +00:00
if ( ! empty ( $form_values [ 'domain' ]) && ! empty ( $form_values [ 'prefix' ])) {
form_set_error ( 'prefix' , t ( 'Domain and path prefix values should not be set at the same time.' ));
}
if ( ! empty ( $form_values [ 'domain' ]) && $duplicate = db_fetch_object ( db_query ( " SELECT language FROM { languages} WHERE domain = '%s' AND language != '%s' " , $form_values [ 'domain' ], $form_values [ 'langcode' ]))) {
form_set_error ( 'domain' , t ( 'The domain (%domain) is already tied to a language (%language).' , array ( '%domain' => $form_values [ 'domain' ], '%language' => $duplicate -> language )));
}
$default = language_default ();
if ( empty ( $form_values [ 'prefix' ]) && $default -> language != $form_values [ 'langcode' ] && empty ( $form_values [ 'domain' ])) {
form_set_error ( 'prefix' , t ( 'Only the default language can have both the domain and prefix empty.' ));
}
if ( ! empty ( $form_values [ 'prefix' ]) && $duplicate = db_fetch_object ( db_query ( " SELECT language FROM { languages} WHERE prefix = '%s' AND language != '%s' " , $form_values [ 'prefix' ], $form_values [ 'langcode' ]))) {
form_set_error ( 'prefix' , t ( 'The prefix (%prefix) is already tied to a language (%language).' , array ( '%prefix' => $form_values [ 'prefix' ], '%language' => $duplicate -> language )));
}
}
/**
* Process the language editing form submission .
*/
2007-05-03 09:51:08 +00:00
function locale_languages_edit_form_submit ( $form_id , $form_values ) {
2007-03-28 14:08:23 +00:00
db_query ( " UPDATE { languages} SET name = '%s', native = '%s', domain = '%s', prefix = '%s', direction = %d WHERE language = '%s' " , $form_values [ 'name' ], $form_values [ 'native' ], $form_values [ 'domain' ], $form_values [ 'prefix' ], $form_values [ 'direction' ], $form_values [ 'langcode' ]);
2007-03-26 01:32:22 +00:00
$default = language_default ();
if ( $default -> language == $form_values [ 'langcode' ]) {
2007-03-28 14:08:23 +00:00
$properties = array ( 'name' , 'native' , 'direction' , 'enabled' , 'plurals' , 'formula' , 'domain' , 'prefix' , 'weight' );
2007-04-13 08:56:59 +00:00
foreach ( $properties as $keyname ) {
2007-03-28 14:08:23 +00:00
$default -> $keyname = $form_values [ $keyname ];
}
2007-03-26 01:32:22 +00:00
variable_set ( 'language_default' , $default );
2006-03-17 18:35:56 +00:00
}
2007-05-03 09:51:08 +00:00
return 'admin/settings/language' ;
2007-03-26 01:32:22 +00:00
}
2007-05-03 09:51:08 +00:00
/**
* @ } End of " locale-language-add-edit "
*/
/**
* @ defgroup locale - language - delete Language deletion functionality
* @ {
*/
/**
* User interface for the language deletion confirmation screen .
*/
function locale_languages_delete_form ( $langcode ) {
// Do not allow deletion of English locale.
if ( $langcode == 'en' ) {
drupal_set_message ( t ( 'The English language cannot be deleted.' ));
drupal_goto ( 'admin/settings/language' );
}
$default = language_default ();
if ( $default -> language == $langcode ) {
drupal_set_message ( t ( 'The default language cannot be deleted.' ));
drupal_goto ( 'admin/settings/language' );
}
// For other languages, warn user that data loss is ahead.
$languages = language_list ();
if ( ! isset ( $languages [ $langcode ])) {
drupal_not_found ();
}
else {
$form [ 'langcode' ] = array ( '#type' => 'value' , '#value' => $langcode );
return confirm_form ( $form , t ( 'Are you sure you want to delete the language %name?' , array ( '%name' => t ( $languages [ $langcode ] -> name ))), 'admin/settings/language' , t ( 'Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.' ), t ( 'Delete' ), t ( 'Cancel' ));
}
}
/**
* Process language deletion submissions .
*/
function locale_languages_delete_form_submit ( $form_id , $form_values ) {
$languages = language_list ();
if ( isset ( $languages [ $form_values [ 'langcode' ]])) {
db_query ( " DELETE FROM { languages} WHERE language = '%s' " , $form_values [ 'langcode' ]);
db_query ( " DELETE FROM { locales_target} WHERE language = '%s' " , $form_values [ 'langcode' ]);
db_query ( " UPDATE { node} SET language = '' WHERE language = '%s' " , $form_values [ 'langcode' ]);
$variables = array ( '%locale' => $languages [ $form_values [ 'langcode' ]] -> name );
drupal_set_message ( t ( 'The language %locale has been removed.' , $variables ));
watchdog ( 'locale' , 'The language %locale has been removed.' , $variables );
}
// Changing the language settings impacts the interface:
cache_clear_all ( '*' , 'cache_page' , TRUE );
return 'admin/settings/language' ;
}
/**
* @ } End of " locale-language-add-edit "
*/
/**
* @ defgroup locale - languages - negotiation Language negotiation options screen
* @ {
*/
2007-03-26 01:32:22 +00:00
/**
* Setting for language negotiation options
*/
2007-05-03 09:51:08 +00:00
function locale_languages_configure_form () {
2007-03-26 01:32:22 +00:00
$form [ 'language_negotiation' ] = array (
'#title' => t ( 'Language negotiation' ),
'#type' => 'radios' ,
'#options' => array (
LANGUAGE_NEGOTIATION_NONE => t ( 'None. Language will be independent of visitor preferences and language prefixes or domains.' ),
LANGUAGE_NEGOTIATION_PATH_DEFAULT => t ( 'Path prefix only. If a suitable path prefix is not identified, the default language is used.' ),
LANGUAGE_NEGOTIATION_PATH => t ( 'Path prefix with language fallback. If a suitable path prefix is not identified, language is based on user preferences and browser language settings.' ),
LANGUAGE_NEGOTIATION_DOMAIN => t ( 'Domain name only. If a suitable domain name is not identified, the default language is used.' )),
'#default_value' => variable_get ( 'language_negotiation' , LANGUAGE_NEGOTIATION_NONE ),
2007-05-03 09:51:08 +00:00
'#description' => t ( 'The used language detection mode. Changing this also changes how paths are constructed, so setting a different value breaks all incoming links. Do not change on a live site without thinking twice!' )
2007-03-26 01:32:22 +00:00
);
$form [ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Save settings' )
);
return $form ;
}
2006-04-17 20:48:26 +00:00
2007-03-26 01:32:22 +00:00
/**
* Submit function for language negotiation settings .
*/
2007-05-03 09:51:08 +00:00
function locale_languages_configure_form_submit ( $form_id , $form_values ) {
2007-03-26 01:32:22 +00:00
variable_set ( 'language_negotiation' , $form_values [ 'language_negotiation' ]);
drupal_set_message ( t ( 'Language negotiation configuration saved.' ));
2007-05-03 09:51:08 +00:00
return 'admin/settings/language' ;
}
/**
* @ } End of " locale-languages-negotiation "
*/
/**
* @ defgroup locale - translate - overview Translation overview screen .
* @ {
*/
/**
* Overview screen for translations .
*/
function locale_translate_overview_screen () {
$languages = language_list ( 'language' , TRUE );
$groups = module_invoke_all ( 'locale' , 'groups' );
// Build headers with all groups in order.
$headers = array_merge ( array ( t ( 'Language' )), array_values ( $groups ));
// Collect summaries of all source strings in all groups.
$sums = db_query ( " SELECT COUNT(*) AS strings, textgroup FROM { locales_source} GROUP BY textgroup " );
$groupsums = array ();
while ( $group = db_fetch_object ( $sums )) {
$groupsums [ $group -> textgroup ] = $group -> strings ;
}
// Setup overview table with default values, ensuring common order for values.
$rows = array ();
foreach ( $languages as $langcode => $language ) {
$rows [ $langcode ] = array ( 'name' => ( $langcode == 'en' ? t ( 'English (built-in)' ) : t ( $language -> name )));
foreach ( $groups as $group => $name ) {
$rows [ $langcode ][ $group ] = ( $langcode == 'en' ? t ( 'n/a' ) : '0/' . ( isset ( $groupsums [ $group ]) ? $groupsums [ $group ] : 0 ) . ' (0%)' );
}
}
// Languages with at least one record in the locale table.
$translations = db_query ( " SELECT COUNT(*) AS translation, t.language, s.textgroup FROM { locales_source} s LEFT JOIN { locales_target} t ON s.lid = t.lid WHERE translation != '' GROUP BY textgroup, language " );
while ( $data = db_fetch_object ( $translations )) {
$ratio = ( ! empty ( $groupsums [ $data -> textgroup ]) && $data -> translation > 0 ) ? round (( $data -> translation / $groupsums [ $data -> textgroup ]) * 100. , 2 ) : 0 ;
$rows [ $data -> language ][ $data -> textgroup ] = $data -> translation . '/' . $groupsums [ $data -> textgroup ] . " ( $ratio %) " ;
}
return theme ( 'table' , $headers , $rows );
}
/**
* @ } End of " locale-translate-overview "
*/
/**
* @ defgroup locale - translate - seek Translation search screen .
* @ {
*/
/**
* String search screen .
*/
function locale_translate_seek_screen () {
$output = _locale_translate_seek ();
$output .= drupal_get_form ( 'locale_translate_seek_form' );
return $output ;
}
/**
* User interface for the string search screen .
*/
function locale_translate_seek_form () {
// Get all languages, except English
$languages = locale_language_list ( 'name' , TRUE );
unset ( $languages [ 'en' ]);
// Present edit form preserving previous user settings
$query = _locale_translate_seek_query ();
$form = array ();
$form [ 'search' ] = array ( '#type' => 'fieldset' ,
'#title' => t ( 'Search' ),
);
$form [ 'search' ][ 'string' ] = array ( '#type' => 'textfield' ,
'#title' => t ( 'String contains' ),
'#default_value' => @ $query [ 'string' ],
'#description' => t ( 'Leave blank to show all strings. The search is case sensitive.' ),
);
$form [ 'search' ][ 'language' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Language' ),
'#default_value' => ( ! empty ( $query [ 'language' ]) ? $query [ 'language' ] : 'all' ),
'#options' => array_merge ( array ( 'all' => t ( 'All languages' ), 'en' => t ( 'English (provided by Drupal)' )), $languages ),
);
$form [ 'search' ][ 'translation' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Search in' ),
'#default_value' => ( ! empty ( $query [ 'translation' ]) ? $query [ 'translation' ] : 'all' ),
'#options' => array ( 'all' => t ( 'All strings in that language' ), 'translated' => t ( 'Only translated strings' ), 'untranslated' => t ( 'Only untranslated strings' )),
);
$groups = module_invoke_all ( 'locale' , 'groups' );
$form [ 'search' ][ 'group' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Limit search to' ),
'#default_value' => ( ! empty ( $query [ 'group' ]) ? $query [ 'group' ] : 'all' ),
'#options' => array_merge ( array ( 'all' => t ( 'All text groups' )), $groups ),
);
$form [ 'search' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Search' ));
$form [ '#redirect' ] = FALSE ;
return $form ;
2006-03-17 18:35:56 +00:00
}
2007-05-03 09:51:08 +00:00
/**
* @ } End of " locale-translate-seek "
*/
2006-03-17 18:35:56 +00:00
2007-05-03 09:51:08 +00:00
/**
* @ defgroup locale - translate - import Translation import screen .
* @ {
*/
2007-03-26 01:32:22 +00:00
2006-03-17 18:35:56 +00:00
/**
* User interface for the translation import screen .
2004-08-11 11:26:20 +00:00
*/
2007-05-03 09:51:08 +00:00
function locale_translate_import_form () {
// Get all languages, except English
2007-03-28 14:08:23 +00:00
$names = locale_language_list ( 'name' , TRUE );
unset ( $names [ 'en' ]);
2004-08-12 18:00:11 +00:00
2007-03-28 14:08:23 +00:00
if ( ! count ( $names )) {
2007-03-26 01:32:22 +00:00
$languages = _locale_prepare_predefined_list ();
2007-03-28 14:08:23 +00:00
$default = array_shift ( array_keys ( $languages ));
2004-08-11 11:26:20 +00:00
}
else {
$languages = array (
2007-03-28 14:08:23 +00:00
t ( 'Already added languages' ) => $names ,
2007-03-26 01:32:22 +00:00
t ( 'Languages not yet added' ) => _locale_prepare_predefined_list ()
2004-08-11 11:26:20 +00:00
);
2007-03-28 14:08:23 +00:00
$default = array_shift ( array_keys ( $names ));
2004-08-11 11:26:20 +00:00
}
2004-08-21 21:13:29 +00:00
2005-10-07 06:11:12 +00:00
$form = array ();
2006-03-17 18:35:56 +00:00
$form [ 'import' ] = array ( '#type' => 'fieldset' ,
2006-04-30 00:28:53 +00:00
'#title' => t ( 'Import translation' ),
2006-03-17 18:35:56 +00:00
);
$form [ 'import' ][ 'file' ] = array ( '#type' => 'file' ,
'#title' => t ( 'Language file' ),
'#size' => 50 ,
'#description' => t ( 'A gettext Portable Object (.po) file.' ),
);
$form [ 'import' ][ 'langcode' ] = array ( '#type' => 'select' ,
'#title' => t ( 'Import into' ),
2007-03-28 14:08:23 +00:00
'#options' => $languages ,
'#default_value' => $default ,
2007-05-03 09:51:08 +00:00
'#description' => t ( 'Choose the language you want to add strings into. If you choose a language which is not yet set up, it will be added.' ),
);
$form [ 'import' ][ 'group' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Text group' ),
'#default_value' => 'default' ,
'#options' => module_invoke_all ( 'locale' , 'groups' ),
'#description' => t ( 'Imported translations will be added to this text group.' ),
2006-03-17 18:35:56 +00:00
);
$form [ 'import' ][ 'mode' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Mode' ),
'#default_value' => 'overwrite' ,
'#options' => array ( 'overwrite' => t ( 'Strings in the uploaded file replace existing ones, new ones are added' ), 'keep' => t ( 'Existing strings are kept, only new strings are added' )),
);
$form [ 'import' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Import' ));
2005-10-11 19:44:35 +00:00
$form [ '#attributes' ][ 'enctype' ] = 'multipart/form-data' ;
2005-10-07 06:11:12 +00:00
2006-08-18 18:58:47 +00:00
return $form ;
2004-08-11 11:26:20 +00:00
}
2006-03-17 18:35:56 +00:00
/**
* Process the locale import form submission .
*/
2007-05-03 09:51:08 +00:00
function locale_translate_import_form_submit ( $form_id , $form_values ) {
2007-03-28 14:08:23 +00:00
// Ensure we have the file uploaded
if ( $file = file_check_upload ( 'file' )) {
// Add language, if not yet supported
$languages = language_list ( 'language' , TRUE );
2007-05-03 09:51:08 +00:00
$langcode = $form_values [ 'langcode' ];
if ( ! isset ( $languages [ $langcode ])) {
2007-03-28 14:08:23 +00:00
$predefined = _locale_get_predefined_list ();
2007-05-03 09:51:08 +00:00
$lang = & $predefined [ $langcode ];
locale_add_language ( $langcode , $lang [ 0 ], isset ( $lang [ 1 ]) ? $lang [ 1 ] : '' , isset ( $lang [ 2 ]) ? $lang [ 2 ] : 0 , '' , '' , FALSE );
2007-03-28 14:08:23 +00:00
}
2006-03-17 18:35:56 +00:00
2007-03-28 14:08:23 +00:00
// Now import strings into the language
2007-05-03 09:51:08 +00:00
if ( $ret = _locale_import_po ( $file , $langcode , $form_values [ 'mode' ], $form_values [ 'group' ]) == FALSE ) {
2007-04-24 13:53:15 +00:00
$variables = array ( '%filename' => $file -> filename );
drupal_set_message ( t ( 'The translation import of %filename failed.' , $variables ), 'error' );
watchdog ( 'locale' , 'The translation import of %filename failed.' , $variables , WATCHDOG_ERROR );
2007-03-28 14:08:23 +00:00
}
}
else {
drupal_set_message ( t ( 'File to import not found.' ), 'error' );
2007-05-03 09:51:08 +00:00
return 'admin/build/translate/import' ;
2006-03-17 18:35:56 +00:00
}
2007-05-03 09:51:08 +00:00
return 'admin/build/translate' ;
}
/**
* @ } End of " locale-translate-import "
*/
/**
* @ defgroup locale - translate - export Translation export screen .
* @ {
*/
/**
* User interface for the translation export screen .
*/
function locale_translate_export_screen () {
// Get all languages, except English
$names = locale_language_list ( 'name' , TRUE );
unset ( $names [ 'en' ]);
$output = '' ;
// Offer translation export if any language is set up.
if ( count ( $names )) {
$output = drupal_get_form ( 'locale_translate_export_po_form' , $names );
}
$output .= drupal_get_form ( 'locale_translate_export_pot_form' );
return $output ;
2006-03-17 18:35:56 +00:00
}
2007-05-03 09:51:08 +00:00
/**
* Form to export PO files for the languages provided .
*
* @ param $names
* An associate array with localized language names
*/
function locale_translate_export_po_form ( $names ) {
2006-08-18 18:58:47 +00:00
$form [ 'export' ] = array ( '#type' => 'fieldset' ,
'#title' => t ( 'Export translation' ),
'#collapsible' => TRUE ,
);
$form [ 'export' ][ 'langcode' ] = array ( '#type' => 'select' ,
'#title' => t ( 'Language name' ),
2007-03-28 14:08:23 +00:00
'#options' => $names ,
2006-08-18 18:58:47 +00:00
'#description' => t ( 'Select the language you would like to export in gettext Portable Object (.po) format.' ),
);
2007-05-03 09:51:08 +00:00
$form [ 'export' ][ 'group' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Text group' ),
'#default_value' => 'default' ,
'#options' => module_invoke_all ( 'locale' , 'groups' ),
);
2006-08-18 18:58:47 +00:00
$form [ 'export' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Export' ));
return $form ;
}
2007-05-03 09:51:08 +00:00
/**
* Translation template export form .
*/
function locale_translate_export_pot_form () {
2006-08-18 18:58:47 +00:00
// Complete template export of the strings
$form [ 'export' ] = array ( '#type' => 'fieldset' ,
'#title' => t ( 'Export template' ),
'#collapsible' => TRUE ,
2007-05-03 09:51:08 +00:00
'#description' => t ( 'Generate a gettext Portable Object Template (.pot) file with all strings from the Drupal locale database.' ),
);
$form [ 'export' ][ 'group' ] = array ( '#type' => 'radios' ,
'#title' => t ( 'Text group' ),
'#default_value' => 'default' ,
'#options' => module_invoke_all ( 'locale' , 'groups' ),
2006-08-18 18:58:47 +00:00
);
$form [ 'export' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Export' ));
2007-05-03 09:51:08 +00:00
// Reuse PO export submission callback.
$form [ '#submit' ][ 'locale_translate_export_po_form_submit' ] = array ();
$form [ '#validate' ][ 'locale_translate_export_po_form_validate' ] = array ();
2006-08-18 18:58:47 +00:00
return $form ;
}
2006-03-17 18:35:56 +00:00
/**
2007-05-03 09:51:08 +00:00
* Process a translation ( or template ) export form submission .
2006-03-17 18:35:56 +00:00
*/
2007-05-03 09:51:08 +00:00
function locale_translate_export_po_form_submit ( $form_id , $form_values ) {
// If template is required, language code is not given.
_locale_export_po ( isset ( $form_values [ 'langcode' ]) ? $form_values [ 'langcode' ] : NULL , $form_values [ 'group' ]);
2006-03-17 18:35:56 +00:00
}
/**
2007-05-03 09:51:08 +00:00
* @ } End of " locale-translate-export "
2006-03-17 18:35:56 +00:00
*/
2007-03-26 01:32:22 +00:00
2006-03-17 18:35:56 +00:00
/**
2007-05-03 09:51:08 +00:00
* @ defgroup locale - translate - edit Translation text editing
* @ {
2006-03-17 18:35:56 +00:00
*/
/**
* User interface for string editing .
*/
2007-05-03 09:51:08 +00:00
function locale_translate_edit_form ( $lid ) {
2007-03-26 01:32:22 +00:00
$languages = language_list ();
unset ( $languages [ 'en' ]);
2006-03-17 18:35:56 +00:00
2007-03-26 01:32:22 +00:00
$result = db_query ( 'SELECT DISTINCT s.source, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d' , $lid );
2006-03-17 18:35:56 +00:00
$form = array ();
2006-05-16 09:22:36 +00:00
$form [ 'translations' ] = array ( '#tree' => TRUE );
2006-03-17 18:35:56 +00:00
while ( $translation = db_fetch_object ( $result )) {
$orig = $translation -> source ;
// Approximate the number of rows in a textfield with a maximum of 10.
$rows = min ( ceil ( str_word_count ( $orig ) / 12 ), 10 );
2006-04-17 20:48:26 +00:00
2007-03-26 01:32:22 +00:00
$form [ 'translations' ][ $translation -> language ] = array (
2006-05-16 09:22:36 +00:00
'#type' => 'textarea' ,
2007-03-26 01:32:22 +00:00
'#title' => $languages [ $translation -> language ] -> name ,
2006-03-17 18:35:56 +00:00
'#default_value' => $translation -> translation ,
'#rows' => $rows ,
);
2007-03-26 01:32:22 +00:00
unset ( $languages [ $translation -> language ]);
2006-03-17 18:35:56 +00:00
}
// Handle erroneous lid.
2007-04-13 08:56:59 +00:00
if ( ! isset ( $orig )) {
2007-05-03 09:51:08 +00:00
drupal_set_message ( t ( 'String not found.' ), 'error' );
drupal_goto ( 'admin/build/translate/search' );
2006-03-17 18:35:56 +00:00
}
// Add original text. Assign negative weight so that it floats to the top.
$form [ 'item' ] = array ( '#type' => 'item' ,
'#title' => t ( 'Original text' ),
'#value' => check_plain ( wordwrap ( $orig , 0 )),
'#weight' => - 1 ,
);
2007-03-26 01:32:22 +00:00
foreach ( $languages as $langcode => $language ) {
$form [ 'translations' ][ $langcode ] = array (
2006-05-16 09:22:36 +00:00
'#type' => 'textarea' ,
2007-03-26 01:32:22 +00:00
'#title' => t ( $language -> name ),
2006-03-17 18:35:56 +00:00
'#rows' => $rows ,
);
}
$form [ 'lid' ] = array ( '#type' => 'value' , '#value' => $lid );
$form [ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save translations' ));
2006-08-18 18:58:47 +00:00
return $form ;
2006-03-17 18:35:56 +00:00
}
/**
* Process string editing form submissions .
* Saves all translations of one string submitted from a form .
*/
2007-05-03 09:51:08 +00:00
function locale_translate_edit_form_submit ( $form_id , $form_values ) {
2006-03-17 18:35:56 +00:00
$lid = $form_values [ 'lid' ];
2006-05-16 09:22:36 +00:00
foreach ( $form_values [ 'translations' ] as $key => $value ) {
2007-03-28 14:08:23 +00:00
$trans = db_fetch_object ( db_query ( " SELECT translation FROM { locales_target} WHERE lid = %d AND language = '%s' " , $lid , $key ));
2006-03-17 18:35:56 +00:00
if ( isset ( $trans -> translation )) {
2007-03-26 01:32:22 +00:00
db_query ( " UPDATE { locales_target} SET translation = '%s' WHERE lid = %d AND language = '%s' " , $value , $lid , $key );
2006-03-17 18:35:56 +00:00
}
else {
2007-03-26 01:32:22 +00:00
db_query ( " INSERT INTO { locales_target} (lid, translation, language) VALUES (%d, '%s', '%s') " , $lid , $value , $key );
2006-03-17 18:35:56 +00:00
}
}
drupal_set_message ( t ( 'The string has been saved.' ));
// Refresh the locale cache.
locale_refresh_cache ();
// Rebuild the menu, strings may have changed.
menu_rebuild ();
2007-05-03 09:51:08 +00:00
return 'admin/build/translate/search' ;
2006-03-17 18:35:56 +00:00
}
2007-05-03 09:51:08 +00:00
/**
* @ } End of " locale-translate-edit "
*/
/**
* @ defgroup locale - translate - delete Translation delete interface .
* @ {
*/
2006-03-17 18:35:56 +00:00
/**
* Delete a language string .
*/
2007-05-03 09:51:08 +00:00
function locale_translate_delete ( $lid ) {
2006-03-17 18:35:56 +00:00
db_query ( 'DELETE FROM {locales_source} WHERE lid = %d' , $lid );
db_query ( 'DELETE FROM {locales_target} WHERE lid = %d' , $lid );
locale_refresh_cache ();
drupal_set_message ( t ( 'The string has been removed.' ));
2007-05-03 09:51:08 +00:00
drupal_goto ( 'admin/build/translate/search' );
}
/**
* @ } End of " locale-translate-delete "
*/
/**
* @ defgroup locale - api - add Language addition API .
* @ {
*/
/**
* API function to add a language .
*
* @ param $langcode
* Language code .
* @ param $name
* English name of the language
* @ param $native
* Native name of the language
* @ param $direction
* LANGUAGE_LTR or LANGUAGE_RTL
* @ param $domain
* Optional custom domain name with protocol , without
* trailing slash ( eg . http :// de . example . com ) .
* @ param $prefix
* Optional path prefix for the language . Defaults to the
* language code if omitted .
* @ param $verbose
* Switch to omit the verbose message to the user when used
* only as a utility function .
*/
function locale_add_language ( $langcode , $name , $native , $direction = LANGUAGE_RTL , $domain = '' , $prefix = '' , $verbose = TRUE ) {
// Default prefix on language code.
if ( empty ( $prefix )) {
$prefix = $code ;
}
db_query ( " INSERT INTO { languages} (language, name, native, direction, domain, prefix) VALUES ('%s', '%s', '%s', %d, '%s', '%s') " , $langcode , $name , $native , $direction , $domain , $prefix );
// Add empty translations for strings (to optimize locale())
$result = db_query ( " SELECT lid FROM { locales_source} " );
while ( $string = db_fetch_object ( $result )) {
db_query ( " INSERT INTO { locales_target} (lid, language, translation) VALUES (%d,'%s', '') " , $string -> lid , $code );
}
2006-04-17 20:48:26 +00:00
2007-05-03 09:51:08 +00:00
// Set message depending on the verbosity required.
if ( $verbose ) {
drupal_set_message ( t ( 'The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.' , array ( '%language' => t ( $name ), '@locale-help' => url ( 'admin/help/locale' ))));
}
else {
drupal_set_message ( t ( 'The language %language has been created.' , array ( '%language' => t ( $name ))));
}
watchdog ( 'locale' , 'The %language language (%code) has been created.' , array ( '%language' => $name , '%code' => $langcode ));
2006-03-17 18:35:56 +00:00
}
2007-05-03 09:51:08 +00:00
/**
* @ } End of " locale-api-add "
*/
2006-03-17 18:35:56 +00:00
2007-05-03 09:51:08 +00:00
/**
* @ defgroup locale - api - import Translation import API .
* @ {
*/
2007-03-26 01:32:22 +00:00
2004-08-11 11:26:20 +00:00
/**
* Parses Gettext Portable Object file information and inserts into database
*
2006-09-01 05:38:40 +00:00
* @ param $file
* Drupal file object corresponding to the PO file to import
* @ param $lang
* Language code
* @ param $mode
* Should existing translations be replaced ( 'overwrite' or 'keep' )
2007-05-03 09:51:08 +00:00
* @ param $group
* Text group to import PO file into ( eg . 'default' for interface translations )
2004-08-11 11:26:20 +00:00
*/
2007-05-03 09:51:08 +00:00
function _locale_import_po ( $file , $lang , $mode , $group = NULL ) {
2004-08-21 21:13:29 +00:00
// If not in 'safe mode', increase the maximum execution time:
if ( ! ini_get ( 'safe_mode' )) {
set_time_limit ( 240 );
2004-09-08 15:38:26 +00:00
}
2004-08-21 21:13:29 +00:00
2004-08-11 11:26:20 +00:00
// Check if we have the language already in the database
2007-03-26 01:32:22 +00:00
if ( ! db_fetch_object ( db_query ( " SELECT language FROM { languages} WHERE language = '%s' " , $lang ))) {
2005-05-05 22:22:46 +00:00
drupal_set_message ( t ( 'The language selected for import is not supported.' ), 'error' );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
2004-08-12 18:00:11 +00:00
2006-02-05 15:42:56 +00:00
// Get strings from file (returns on failure after a partial import, or on success)
2007-05-03 09:51:08 +00:00
$status = _locale_import_read_po ( 'db-store' , $file , $mode , $lang , $group );
2006-06-22 12:23:39 +00:00
if ( $status === FALSE ) {
// error messages are set in _locale_import_read_po
return FALSE ;
}
2004-08-12 18:00:11 +00:00
2006-02-05 15:42:56 +00:00
// Get status information on import process
2006-09-01 05:38:40 +00:00
list ( $headerdone , $additions , $updates ) = _locale_import_one_string ( 'db-report' );
2004-08-12 18:00:11 +00:00
2006-02-05 15:42:56 +00:00
if ( ! $headerdone ) {
2006-08-18 12:17:00 +00:00
drupal_set_message ( t ( 'The translation file %filename appears to have a missing or malformed header.' , array ( '%filename' => $file -> filename )), 'error' );
2004-08-11 11:26:20 +00:00
}
2004-08-12 18:00:11 +00:00
2004-10-06 12:18:03 +00:00
// rebuild locale cache
2006-08-30 08:46:17 +00:00
cache_clear_all ( " locale: $lang " , 'cache' );
2004-10-06 12:18:03 +00:00
// rebuild the menu, strings may have changed
2004-10-05 20:09:47 +00:00
menu_rebuild ();
2004-10-06 12:18:03 +00:00
2005-05-05 22:22:46 +00:00
drupal_set_message ( t ( 'The translation was successfully imported. There are %number newly created translated strings and %update strings were updated.' , array ( '%number' => $additions , '%update' => $updates )));
2007-04-24 13:53:15 +00:00
watchdog ( 'locale' , 'Imported %file into %locale: %number new strings added and %update updated.' , array ( '%file' => $file -> filename , '%locale' => $lang , '%number' => $additions , '%update' => $updates ));
2004-08-11 11:26:20 +00:00
return TRUE ;
}
/**
* Parses Gettext Portable Object file into an array
*
2006-09-01 05:38:40 +00:00
* @ 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 ( 'overwrite' or 'keep' )
* @ param $lang
* Language code
2007-05-03 09:51:08 +00:00
* @ param $group
* Text group to import PO file into ( eg . 'default' for interface translations )
2004-08-11 11:26:20 +00:00
*/
2007-05-03 09:51:08 +00:00
function _locale_import_read_po ( $op , $file , $mode = NULL , $lang = NULL , $group = NULL ) {
2004-08-11 11:26:20 +00:00
2006-02-05 15:42:56 +00:00
$fd = fopen ( $file -> filepath , " rb " ); // File will get closed by PHP on return
2004-08-11 11:26:20 +00:00
if ( ! $fd ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation import failed, because the file %filename could not be read.' , $file );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$context = " COMMENT " ; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR
$current = array (); // Current entry being read
$plural = 0 ; // Current plural form
2006-02-05 15:42:56 +00:00
$lineno = 0 ; // Current line
2004-08-11 11:26:20 +00:00
2006-02-05 15:42:56 +00:00
while ( ! feof ( $fd )) {
$line = fgets ( $fd , 10 * 1024 ); // A line should not be this long
2004-08-11 11:26:20 +00:00
$lineno ++ ;
2006-02-05 15:42:56 +00:00
$line = trim ( strtr ( $line , array ( " \\ \n " => " " )));
2004-08-11 11:26:20 +00:00
if ( ! strncmp ( " # " , $line , 1 )) { // A comment
if ( $context == " COMMENT " ) { // Already in comment context: add
$current [ " # " ][] = substr ( $line , 1 );
}
elseif (( $context == " MSGSTR " ) || ( $context == " MSGSTR_ARR " )) { // End current entry, start a new one
2007-04-06 14:15:43 +00:00
_locale_import_one_string ( $op , $current , $mode , $lang , $file );
2004-08-11 11:26:20 +00:00
$current = array ();
$current [ " # " ][] = substr ( $line , 1 );
$context = " COMMENT " ;
}
else { // Parse error
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains an error: "msgstr" was expected but not found on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
}
elseif ( ! strncmp ( " msgid_plural " , $line , 12 )) {
if ( $context != " MSGID " ) { // Must be plural form for current entry
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$line = trim ( substr ( $line , 12 ));
$quoted = _locale_import_parse_quoted ( $line );
2006-07-05 11:45:51 +00:00
if ( $quoted === FALSE ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains a syntax error on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$current [ " msgid " ] = $current [ " msgid " ] . " \0 " . $quoted ;
2004-08-12 18:00:11 +00:00
$context = " MSGID_PLURAL " ;
2004-08-11 11:26:20 +00:00
}
elseif ( ! strncmp ( " msgid " , $line , 5 )) {
if ( $context == " MSGSTR " ) { // End current entry, start a new one
2007-04-06 14:15:43 +00:00
_locale_import_one_string ( $op , $current , $mode , $lang , $file );
2004-08-11 11:26:20 +00:00
$current = array ();
}
elseif ( $context == " MSGID " ) { // Already in this context? Parse error
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains an error: "msgid" is unexpected on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$line = trim ( substr ( $line , 5 ));
$quoted = _locale_import_parse_quoted ( $line );
2006-07-05 11:45:51 +00:00
if ( $quoted === FALSE ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains a syntax error on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$current [ " msgid " ] = $quoted ;
$context = " MSGID " ;
}
elseif ( ! strncmp ( " msgstr[ " , $line , 7 )) {
if (( $context != " MSGID " ) && ( $context != " MSGID_PLURAL " ) && ( $context != " MSGSTR_ARR " )) { // Must come after msgid, msgid_plural, or msgstr[]
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
2006-07-05 11:45:51 +00:00
if ( strpos ( $line , " ] " ) === FALSE ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains a syntax error on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$frombracket = strstr ( $line , " [ " );
$plural = substr ( $frombracket , 1 , strpos ( $frombracket , " ] " ) - 1 );
$line = trim ( strstr ( $line , " " ));
$quoted = _locale_import_parse_quoted ( $line );
2006-07-05 11:45:51 +00:00
if ( $quoted === FALSE ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains a syntax error on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$current [ " msgstr " ][ $plural ] = $quoted ;
$context = " MSGSTR_ARR " ;
}
elseif ( ! strncmp ( " msgstr " , $line , 6 )) {
if ( $context != " MSGID " ) { // Should come just after a msgid block
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains an error: "msgstr" is unexpected on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$line = trim ( substr ( $line , 6 ));
$quoted = _locale_import_parse_quoted ( $line );
2006-07-05 11:45:51 +00:00
if ( $quoted === FALSE ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains a syntax error on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
$current [ " msgstr " ] = $quoted ;
$context = " MSGSTR " ;
}
elseif ( $line != " " ) {
$quoted = _locale_import_parse_quoted ( $line );
2006-07-05 11:45:51 +00:00
if ( $quoted === FALSE ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains a syntax error on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
if (( $context == " MSGID " ) || ( $context == " MSGID_PLURAL " )) {
$current [ " msgid " ] .= $quoted ;
}
elseif ( $context == " MSGSTR " ) {
$current [ " msgstr " ] .= $quoted ;
}
elseif ( $context == " MSGSTR_ARR " ) {
$current [ " msgstr " ][ $plural ] .= $quoted ;
}
else {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename contains an error: there is an unexpected string on line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
}
}
// End of PO file, flush last entry
if (( $context == " MSGSTR " ) || ( $context == " MSGSTR_ARR " )) {
2007-04-06 14:15:43 +00:00
_locale_import_one_string ( $op , $current , $mode , $lang , $file );
2004-08-11 11:26:20 +00:00
}
elseif ( $context != " COMMENT " ) {
2006-09-01 05:38:40 +00:00
_locale_import_message ( 'The translation file %filename ended unexpectedly at line %line.' , $file , $lineno );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
2006-02-05 15:42:56 +00:00
}
2006-09-01 05:38:40 +00:00
/**
2006-12-05 05:47:37 +00:00
* Sets an error message occurred during locale file parsing .
2006-09-01 05:38:40 +00:00
*
* @ param $message
* The message to be translated
* @ param $file
* Drupal file object corresponding to the PO file to import
* @ param $lineno
* An optional line number argument
*/
function _locale_import_message ( $message , $file , $lineno = NULL ) {
$vars = array ( '%filename' => $file -> filename );
if ( isset ( $lineno )) {
$vars [ '%line' ] = $lineno ;
}
2006-09-05 02:15:04 +00:00
$t = get_t ();
2006-09-01 05:38:40 +00:00
drupal_set_message ( $t ( $message , $vars ), 'error' );
}
2006-02-05 15:42:56 +00:00
/**
* Imports a string into the database
*
2006-09-01 05:38:40 +00:00
* @ param $op
* Operation to perform : 'db-store' , 'db-report' , 'mem-store' or 'mem-report'
* @ param $value
* Details of the string stored
* @ param $mode
* Should existing translations be replaced ( 'overwrite' or 'keep' )
* @ param $lang
* Language to store the string in
2007-04-06 14:15:43 +00:00
* @ param $file
* Object representation of file being imported , only required when op is 'db-store'
2007-05-03 09:51:08 +00:00
* @ param $group
* Text group to import PO file into ( eg . 'default' for interface translations )
2006-02-05 15:42:56 +00:00
*/
2007-05-03 09:51:08 +00:00
function _locale_import_one_string ( $op , $value = NULL , $mode = NULL , $lang = NULL , $file = NULL , $group = 'default' ) {
2006-02-05 15:42:56 +00:00
static $additions = 0 ;
static $updates = 0 ;
static $headerdone = FALSE ;
2006-09-01 05:38:40 +00:00
static $strings = array ();
switch ( $op ) {
// Return stored strings
case 'mem-report' :
return $strings ;
// Store string in memory (only supports single strings)
case 'mem-store' :
$strings [ $value [ 'msgid' ]] = $value [ 'msgstr' ];
return ;
// Called at end of import to inform the user
case 'db-report' :
return array ( $headerdone , $additions , $updates );
// Store the string we got in the database
case 'db-store' :
// We got header information
if ( $value [ 'msgid' ] == '' ) {
$hdr = _locale_import_parse_header ( $value [ 'msgstr' ]);
// Get the plural formula
2007-05-03 09:51:08 +00:00
if ( isset ( $hdr [ " Plural-Forms " ]) && $p = _locale_import_parse_plural_forms ( $hdr [ " Plural-Forms " ], $file -> filename )) {
2006-09-01 05:38:40 +00:00
list ( $nplurals , $plural ) = $p ;
2007-03-26 01:32:22 +00:00
db_query ( " UPDATE { languages} SET plurals = %d, formula = '%s' WHERE language = '%s' " , $nplurals , $plural , $lang );
2006-02-05 15:42:56 +00:00
}
2006-09-01 05:38:40 +00:00
else {
2007-03-26 01:32:22 +00:00
db_query ( " UPDATE { languages} SET plurals = %d, formula = '%s' WHERE language = '%s' " , 0 , '' , $lang );
2006-09-01 05:38:40 +00:00
}
$headerdone = TRUE ;
}
// Some real string to import
else {
2006-12-29 08:35:04 +00:00
$comments = _locale_import_shorten_comments ( $value [ '#' ]);
2006-09-01 05:38:40 +00:00
// Handle a translation for some plural string
if ( strpos ( $value [ 'msgid' ], " \0 " )) {
$english = explode ( " \0 " , $value [ 'msgid' ], 2 );
$entries = array_keys ( $value [ 'msgstr' ]);
for ( $i = 3 ; $i <= count ( $entries ); $i ++ ) {
$english [] = $english [ 1 ];
}
$translation = array_map ( '_locale_import_append_plural' , $value [ 'msgstr' ], $entries );
$english = array_map ( '_locale_import_append_plural' , $english , $entries );
foreach ( $translation as $key => $trans ) {
if ( $key == 0 ) {
$plid = 0 ;
2006-02-05 15:42:56 +00:00
}
2007-05-03 09:51:08 +00:00
$loc = db_fetch_object ( db_query ( " SELECT lid FROM { locales_source} WHERE source = '%s' AND textgroup = '%s' " , $english [ $key ], $group ));
2007-04-04 20:47:41 +00:00
if ( ! empty ( $loc -> lid )) { // a string exists
2006-09-01 05:38:40 +00:00
$lid = $loc -> lid ;
// update location field
db_query ( " UPDATE { locales_source} SET location = '%s' WHERE lid = %d " , $comments , $lid );
2007-03-26 01:32:22 +00:00
$trans2 = db_fetch_object ( db_query ( " SELECT lid, translation, plid, plural FROM { locales_target} WHERE lid = %d AND language = '%s' " , $lid , $lang ));
2007-04-13 08:03:21 +00:00
if ( ! isset ( $trans2 -> lid )) { // no translation in current language
2007-03-26 01:32:22 +00:00
db_query ( " INSERT INTO { locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d) " , $lid , $lang , $trans , $plid , $key );
2006-09-01 05:38:40 +00:00
$additions ++ ;
} // translation exists
else if ( $mode == 'overwrite' || $trans2 -> translation == '' ) {
2007-03-26 01:32:22 +00:00
db_query ( " UPDATE { locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d " , $trans , $plid , $key , $lang , $lid );
2006-09-01 05:38:40 +00:00
if ( $trans2 -> translation == '' ) {
$additions ++ ;
}
else {
$updates ++ ;
}
}
2006-02-05 15:42:56 +00:00
}
2006-09-01 05:38:40 +00:00
else { // no string
2007-05-03 09:51:08 +00:00
db_query ( " INSERT INTO { locales_source} (location, source, textgroup) VALUES ('%s', '%s', '%s') " , $comments , $english [ $key ], $group );
$loc = db_fetch_object ( db_query ( " SELECT lid FROM { locales_source} WHERE source = '%s' AND textgroup = '%s' " , $english [ $key ], $group ));
2006-09-01 05:38:40 +00:00
$lid = $loc -> lid ;
2007-03-26 01:32:22 +00:00
db_query ( " INSERT INTO { locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d) " , $lid , $lang , $trans , $plid , $key );
2006-09-01 05:38:40 +00:00
if ( $trans != '' ) {
$additions ++ ;
}
}
$plid = $lid ;
2006-02-05 15:42:56 +00:00
}
}
2006-09-01 05:38:40 +00:00
// A simple translation
else {
$english = $value [ 'msgid' ];
$translation = $value [ 'msgstr' ];
2007-05-03 09:51:08 +00:00
$loc = db_fetch_object ( db_query ( " SELECT lid FROM { locales_source} WHERE source = '%s' AND textgroup = '%s' " , $english , $group ));
2007-04-04 20:47:41 +00:00
if ( ! empty ( $loc -> lid )) { // a string exists
2006-09-01 05:38:40 +00:00
$lid = $loc -> lid ;
// update location field
db_query ( " UPDATE { locales_source} SET location = '%s' WHERE source = '%s' " , $comments , $english );
2007-03-26 01:32:22 +00:00
$trans = db_fetch_object ( db_query ( " SELECT lid, translation FROM { locales_target} WHERE lid = %d AND language = '%s' " , $lid , $lang ));
2007-04-13 08:03:21 +00:00
if ( ! isset ( $trans -> lid )) { // no translation in current language
2007-03-26 01:32:22 +00:00
db_query ( " INSERT INTO { locales_target} (lid, language, translation) VALUES (%d, '%s', '%s') " , $lid , $lang , $translation );
2006-09-01 05:38:40 +00:00
$additions ++ ;
} // translation exists
else if ( $mode == 'overwrite' ) { //overwrite in any case
2007-03-26 01:32:22 +00:00
db_query ( " UPDATE { locales_target} SET translation = '%s' WHERE language = '%s' AND lid = %d " , $translation , $lang , $lid );
2006-09-01 05:38:40 +00:00
if ( $trans -> translation == '' ) {
$additions ++ ;
}
else {
$updates ++ ;
}
} // overwrite if empty string
else if ( $trans -> translation == '' ) {
2007-03-26 01:32:22 +00:00
db_query ( " UPDATE { locales_target} SET translation = '%s' WHERE language = '%s' AND lid = %d " , $translation , $lang , $lid );
2006-09-01 05:38:40 +00:00
$additions ++ ;
}
2006-02-05 15:42:56 +00:00
}
2006-09-01 05:38:40 +00:00
else { // no string
2007-05-03 09:51:08 +00:00
db_query ( " INSERT INTO { locales_source} (location, source, textgroup) VALUES ('%s', '%s', '%s') " , $comments , $english , $group );
$loc = db_fetch_object ( db_query ( " SELECT lid FROM { locales_source} WHERE source = '%s' AND textgroup = '%s' " , $english , $group ));
2006-09-01 05:38:40 +00:00
$lid = $loc -> lid ;
2007-03-26 01:32:22 +00:00
db_query ( " INSERT INTO { locales_target} (lid, language, translation) VALUES (%d, '%s', '%s') " , $lid , $lang , $translation );
2006-09-01 05:38:40 +00:00
if ( $translation != '' ) {
$additions ++ ;
}
2006-02-05 15:42:56 +00:00
}
}
}
2006-09-01 05:38:40 +00:00
} // end of db-store operation
2004-08-11 11:26:20 +00:00
}
/**
* Parses a Gettext Portable Object file header
*
* @ param $header A string containing the complete header
* @ return An associative array of key - value pairs
*/
function _locale_import_parse_header ( $header ) {
$hdr = array ();
$lines = explode ( " \n " , $header );
foreach ( $lines as $line ) {
$line = trim ( $line );
if ( $line ) {
list ( $tag , $contents ) = explode ( " : " , $line , 2 );
$hdr [ trim ( $tag )] = trim ( $contents );
}
}
return $hdr ;
}
/**
* Parses a Plural - Forms entry from a Gettext Portable Object file header
*
2006-09-01 05:38:40 +00:00
* @ 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
* formula in PHP for computing the plural form
2004-08-11 11:26:20 +00:00
*/
2004-10-26 17:20:58 +00:00
function _locale_import_parse_plural_forms ( $pluralforms , $filename ) {
2004-08-11 11:26:20 +00:00
// First, delete all whitespace
$pluralforms = strtr ( $pluralforms , array ( " " => " " , " \t " => " " ));
// Select the parts that define nplurals and plural
$nplurals = strstr ( $pluralforms , " nplurals= " );
if ( strpos ( $nplurals , " ; " )) {
$nplurals = substr ( $nplurals , 9 , strpos ( $nplurals , " ; " ) - 9 );
}
else {
return FALSE ;
}
$plural = strstr ( $pluralforms , " plural= " );
if ( strpos ( $plural , " ; " )) {
$plural = substr ( $plural , 7 , strpos ( $plural , " ; " ) - 7 );
}
else {
return FALSE ;
}
// Get PHP version of the plural formula
$plural = _locale_import_parse_arithmetic ( $plural );
2006-07-06 14:41:37 +00:00
if ( $plural !== FALSE ) {
2004-08-11 11:26:20 +00:00
return array ( $nplurals , $plural );
}
else {
2006-09-09 08:25:24 +00:00
drupal_set_message ( t ( 'The translation file %filename contains an error: the plural formula could not be parsed.' , array ( '%filename' => $filename )), 'error' );
2004-08-11 11:26:20 +00:00
return FALSE ;
}
}
/**
* Parses and sanitizes an arithmetic formula into a PHP expression
*
* While parsing , we ensure , that the operators have the right
* precedence and associativity .
*
* @ param $string A string containing the arithmetic formula
* @ return The PHP version of the formula
*/
function _locale_import_parse_arithmetic ( $string ) {
// Operator precedence table
$prec = array ( " ( " => - 1 , " ) " => - 1 , " ? " => 1 , " : " => 1 , " || " => 3 , " && " => 4 , " == " => 5 , " != " => 5 , " < " => 6 , " > " => 6 , " <= " => 6 , " >= " => 6 , " + " => 7 , " - " => 7 , " * " => 8 , " / " => 8 , " % " => 8 );
// Right associativity
$rasc = array ( " ? " => 1 , " : " => 1 );
$tokens = _locale_import_tokenize_formula ( $string );
// Parse by converting into infix notation then back into postfix
$opstk = array ();
$elstk = array ();
foreach ( $tokens as $token ) {
$ctok = $token ;
// Numbers and the $n variable are simply pushed into $elarr
if ( is_numeric ( $token )) {
$elstk [] = $ctok ;
}
elseif ( $ctok == " n " ) {
$elstk [] = '$n' ;
}
elseif ( $ctok == " ( " ) {
$opstk [] = $ctok ;
}
elseif ( $ctok == " ) " ) {
$topop = array_pop ( $opstk );
2007-05-03 09:51:08 +00:00
while ( isset ( $topop ) && ( $topop != " ( " )) {
2004-08-11 11:26:20 +00:00
$elstk [] = $topop ;
$topop = array_pop ( $opstk );
}
}
2007-04-04 20:47:41 +00:00
elseif ( ! empty ( $prec [ $ctok ])) {
2004-08-11 11:26:20 +00:00
// If it's an operator, then pop from $oparr into $elarr until the
// precedence in $oparr is less than current, then push into $oparr
$topop = array_pop ( $opstk );
2007-05-03 09:51:08 +00:00
while ( isset ( $topop ) && ( $prec [ $topop ] >= $prec [ $ctok ]) && ! (( $prec [ $topop ] == $prec [ $ctok ]) && ! empty ( $rasc [ $topop ]) && ! empty ( $rasc [ $ctok ]))) {
2004-08-11 11:26:20 +00:00
$elstk [] = $topop ;
$topop = array_pop ( $opstk );
}
if ( $topop ) {
$opstk [] = $topop ; // Return element to top
}
$opstk [] = $ctok ; // Parentheses are not needed
}
else {
2006-07-05 11:45:51 +00:00
return FALSE ;
2004-08-11 11:26:20 +00:00
}
}
// Flush operator stack
$topop = array_pop ( $opstk );
while ( $topop != NULL ) {
$elstk [] = $topop ;
$topop = array_pop ( $opstk );
}
// Now extract formula from stack
$prevsize = count ( $elstk ) + 1 ;
while ( count ( $elstk ) < $prevsize ) {
$prevsize = count ( $elstk );
for ( $i = 2 ; $i < count ( $elstk ); $i ++ ) {
$op = $elstk [ $i ];
2007-05-03 09:51:08 +00:00
if ( ! empty ( $prec [ $op ])) {
2004-08-11 11:26:20 +00:00
$f = " " ;
if ( $op == " : " ) {
$f = $elstk [ $i - 2 ] . " ): " . $elstk [ $i - 1 ] . " ) " ;
}
elseif ( $op == " ? " ) {
$f = " ( " . $elstk [ $i - 2 ] . " ?( " . $elstk [ $i - 1 ];
}
else {
$f = " ( " . $elstk [ $i - 2 ] . $op . $elstk [ $i - 1 ] . " ) " ;
}
array_splice ( $elstk , $i - 2 , 3 , $f );
break ;
}
}
}
// If only one element is left, the number of operators is appropriate
if ( count ( $elstk ) == 1 ) {
return $elstk [ 0 ];
}
else {
return FALSE ;
}
}
/**
* Backward compatible implementation of token_get_all () for formula parsing
*
* @ param $string A string containing the arithmetic formula
* @ return The PHP version of the formula
*/
function _locale_import_tokenize_formula ( $formula ) {
$formula = str_replace ( " " , " " , $formula );
$tokens = array ();
for ( $i = 0 ; $i < strlen ( $formula ); $i ++ ) {
2006-01-15 07:14:14 +00:00
if ( is_numeric ( $formula [ $i ])) {
$num = $formula [ $i ];
2004-08-11 11:26:20 +00:00
$j = $i + 1 ;
2007-01-02 05:05:38 +00:00
while ( $j < strlen ( $formula ) && is_numeric ( $formula [ $j ])) {
2006-01-15 07:14:14 +00:00
$num .= $formula [ $j ];
2004-08-11 11:26:20 +00:00
$j ++ ;
}
$i = $j - 1 ;
$tokens [] = $num ;
}
2006-01-15 07:14:14 +00:00
elseif ( $pos = strpos ( " =<>!&| " , $formula [ $i ])) { // We won't have a space
$next = $formula [ $i + 1 ];
2004-08-11 11:26:20 +00:00
switch ( $pos ) {
case 1 :
case 2 :
case 3 :
case 4 :
if ( $next == '=' ) {
2006-01-15 07:14:14 +00:00
$tokens [] = $formula [ $i ] . '=' ;
2004-08-11 11:26:20 +00:00
$i ++ ;
}
else {
2006-01-15 07:14:14 +00:00
$tokens [] = $formula [ $i ];
2004-08-11 11:26:20 +00:00
}
break ;
case 5 :
if ( $next == '&' ) {
$tokens [] = '&&' ;
$i ++ ;
}
else {
2006-01-15 07:14:14 +00:00
$tokens [] = $formula [ $i ];
2004-08-11 11:26:20 +00:00
}
break ;
case 6 :
if ( $next == '|' ) {
$tokens [] = '||' ;
$i ++ ;
}
else {
2006-01-15 07:14:14 +00:00
$tokens [] = $formula [ $i ];
2004-08-11 11:26:20 +00:00
}
break ;
}
}
else {
2006-01-15 07:14:14 +00:00
$tokens [] = $formula [ $i ];
2004-08-11 11:26:20 +00:00
}
}
return $tokens ;
}
/**
* Modify a string to contain proper count indices
*
* This is a callback function used via array_map ()
*
* @ param $entry An array element
* @ param $key Index of the array element
*/
function _locale_import_append_plural ( $entry , $key ) {
2004-08-12 18:00:11 +00:00
// No modifications for 0, 1
2004-08-11 11:26:20 +00:00
if ( $key == 0 || $key == 1 ) {
return $entry ;
}
// First remove any possibly false indices, then add new ones
2006-08-18 12:17:00 +00:00
$entry = preg_replace ( '/(@count)\[[0-9]\]/' , '\\1' , $entry );
return preg_replace ( '/(@count)/' , " \\ 1[ $key ] " , $entry );
2004-08-11 11:26:20 +00:00
}
/**
* Generate a short , one string version of the passed comment array
*
* @ param $comment An array of strings containing a comment
* @ return Short one string version of the comment
*/
function _locale_import_shorten_comments ( $comment ) {
$comm = '' ;
2005-07-29 18:56:58 +00:00
while ( count ( $comment )) {
$test = $comm . substr ( array_shift ( $comment ), 1 ) . ', ' ;
if ( strlen ( $comm ) < 130 ) {
$comm = $test ;
}
else {
break ;
}
2004-08-11 11:26:20 +00:00
}
return substr ( $comm , 0 , - 2 );
}
/**
* Parses a string in quotes
*
* @ param $string A string specified with enclosing quotes
* @ return The string parsed from inside the quotes
*/
function _locale_import_parse_quoted ( $string ) {
if ( substr ( $string , 0 , 1 ) != substr ( $string , - 1 , 1 )) {
return FALSE ; // Start and end quotes must be the same
}
$quote = substr ( $string , 0 , 1 );
$string = substr ( $string , 1 , - 1 );
if ( $quote == '"' ) { // Double quotes: strip slashes
return stripcslashes ( $string );
}
elseif ( $quote == " ' " ) { // Simple quote: return as-is
return $string ;
}
else {
return FALSE ; // Unrecognized quote
}
}
2007-05-03 09:51:08 +00:00
/**
* @ } End of " locale-api-import "
*/
/**
* @ defgroup locale - api - export Translation ( template ) export API .
* @ {
*/
2004-08-11 11:26:20 +00:00
/**
* Exports a Portable Object ( Template ) file for a language
*
2007-03-28 14:08:23 +00:00
* @ param $language
* Language code to generate the output for , or NULL if generating
* translation template .
2007-05-03 09:51:08 +00:00
* @ param $group
* Text group to export PO file from ( eg . 'default' for interface translations )
2004-08-11 11:26:20 +00:00
*/
2007-05-03 09:51:08 +00:00
function _locale_export_po ( $language = NULL , $group = 'default' ) {
2004-08-11 11:26:20 +00:00
global $user ;
2007-03-27 05:13:55 +00:00
$header = '' ;
2004-08-11 11:26:20 +00:00
// Get language specific strings, or all strings
2007-03-28 14:08:23 +00:00
if ( isset ( $language )) {
2007-03-26 01:32:22 +00:00
$meta = db_fetch_object ( db_query ( " SELECT * FROM { languages} WHERE language = '%s' " , $language ));
2007-05-03 09:51:08 +00:00
$result = db_query ( " SELECT s.lid, s.source, s.location, t.translation, t.plid, t.plural FROM { locales_source} s INNER JOIN { locales_target} t ON s.lid = t.lid WHERE t.language = '%s' AND s.textgroup = '%s' ORDER BY t.plid, t.plural " , $language , $group );
2004-08-11 11:26:20 +00:00
}
else {
2007-05-03 09:51:08 +00:00
$result = db_query ( " SELECT s.lid, s.source, s.location, t.plid, t.plural FROM { locales_source} s INNER JOIN { locales_target} t ON s.lid = t.lid WHERE s.textgroup = '%s' ORDER BY t.plid, t.plural " , $group );
2004-08-11 11:26:20 +00:00
}
2004-08-12 18:00:11 +00:00
2004-08-11 11:26:20 +00:00
// Build array out of the database results
$parent = array ();
while ( $child = db_fetch_object ( $result )) {
2004-10-11 19:57:42 +00:00
if ( $child -> source != '' ) {
$parent [ $child -> lid ][ 'comment' ] = $child -> location ;
$parent [ $child -> lid ][ 'msgid' ] = $child -> source ;
2007-05-03 09:51:08 +00:00
$parent [ $child -> lid ][ 'translation' ] = isset ( $child -> translation ) ? $child -> translation : '' ;
2004-10-11 19:57:42 +00:00
if ( $child -> plid ) {
2006-09-05 11:40:44 +00:00
$parent [ $child -> lid ][ 'child' ] = 1 ;
$parent [ $child -> plid ][ 'plural' ] = $child -> lid ;
2004-10-11 19:57:42 +00:00
}
2004-08-11 11:26:20 +00:00
}
}
2004-08-12 18:00:11 +00:00
2004-08-11 11:26:20 +00:00
// Generating Portable Object file for a language
2007-03-28 14:08:23 +00:00
if ( isset ( $language )) {
2004-08-11 11:26:20 +00:00
$filename = $language . '.po' ;
2007-03-28 14:08:23 +00:00
$header = " # $meta->name translation of " . variable_get ( 'site_name' , 'Drupal' ) . " \n " ;
2004-08-11 11:26:20 +00:00
$header .= '# Copyright (c) ' . date ( 'Y' ) . ' ' . $user -> name . ' <' . $user -> mail . " > \n " ;
$header .= " # \n " ;
$header .= " msgid \" \" \n " ;
$header .= " msgstr \" \" \n " ;
$header .= " \" Project-Id-Version: PROJECT VERSION \\ n \" \n " ;
$header .= " \" POT-Creation-Date: " . date ( " Y-m-d H:iO " ) . " \\ n \" \n " ;
$header .= " \" PO-Revision-Date: " . date ( " Y-m-d H:iO " ) . " \\ n \" \n " ;
$header .= " \" Last-Translator: " . $user -> name . ' <' . $user -> mail . " > \\ n \" \n " ;
$header .= " \" Language-Team: " . $meta -> name . ' <' . $user -> mail . " > \\ n \" \n " ;
$header .= " \" MIME-Version: 1.0 \\ n \" \n " ;
$header .= " \" Content-Type: text/plain; charset=utf-8 \\ n \" \n " ;
$header .= " \" Content-Transfer-Encoding: 8bit \\ n \" \n " ;
if ( $meta -> formula && $meta -> plurals ) {
2006-09-05 11:40:44 +00:00
$header .= " \" Plural-Forms: nplurals= " . $meta -> plurals . " ; plural= " . strtr ( $meta -> formula , array ( '$' => '' )) . " ; \\ n \" \n " ;
2004-08-11 11:26:20 +00:00
}
$header .= " \n " ;
2007-04-24 13:53:15 +00:00
watchdog ( 'locale' , 'Exported %locale translation file: %filename.' , array ( '%locale' => $meta -> name , '%filename' => $filename ));
2004-08-11 11:26:20 +00:00
}
2004-08-12 18:00:11 +00:00
2004-08-11 11:26:20 +00:00
// Generating Portable Object Template
else {
2006-06-01 12:32:52 +00:00
$filename = 'drupal.pot' ;
2007-03-28 14:08:23 +00:00
$header = " # LANGUAGE translation of PROJECT \n " ;
2004-08-11 11:26:20 +00:00
$header .= " # Copyright (c) YEAR NAME <EMAIL@ADDRESS> \n " ;
$header .= " # \n " ;
$header .= " msgid \" \" \n " ;
$header .= " msgstr \" \" \n " ;
$header .= " \" Project-Id-Version: PROJECT VERSION \\ n \" \n " ;
$header .= " \" POT-Creation-Date: " . date ( " Y-m-d H:iO " ) . " \\ n \" \n " ;
$header .= " \" PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ \\ n \" \n " ;
$header .= " \" Last-Translator: NAME <EMAIL@ADDRESS> \\ n \" \n " ;
$header .= " \" Language-Team: LANGUAGE <EMAIL@ADDRESS> \\ n \" \n " ;
$header .= " \" MIME-Version: 1.0 \\ n \" \n " ;
$header .= " \" Content-Type: text/plain; charset=utf-8 \\ n \" \n " ;
$header .= " \" Content-Transfer-Encoding: 8bit \\ n \" \n " ;
$header .= " \" Plural-Forms: nplurals=INTEGER; plural=EXPRESSION; \\ n \" \n " ;
$header .= " \n " ;
2007-04-24 13:53:15 +00:00
watchdog ( 'locale' , 'Exported translation file: %filename.' , array ( '%filename' => $filename ));
2004-08-11 11:26:20 +00:00
}
// Start download process
header ( " Content-Disposition: attachment; filename= $filename " );
header ( " Content-Type: text/plain; charset=utf-8 " );
print $header ;
foreach ( $parent as $lid => $message ) {
2006-09-05 11:40:44 +00:00
if ( ! isset ( $message [ 'child' ])) {
2004-08-11 11:26:20 +00:00
if ( $message [ 'comment' ]) {
print '#: ' . $message [ 'comment' ] . " \n " ;
}
print 'msgid ' . _locale_export_print ( $message [ 'msgid' ]);
2007-03-28 14:08:23 +00:00
if ( ! empty ( $message [ 'plural' ])) {
$plural = $message [ 'plural' ];
2006-09-05 11:40:44 +00:00
print 'msgid_plural ' . _locale_export_print ( $parent [ $plural ][ 'msgid' ]);
2007-03-28 14:08:23 +00:00
if ( isset ( $language )) {
2006-09-05 11:40:44 +00:00
$translation = $message [ 'translation' ];
2004-08-11 11:26:20 +00:00
for ( $i = 0 ; $i < $meta -> plurals ; $i ++ ) {
2006-09-05 11:40:44 +00:00
print 'msgstr[' . $i . '] ' . _locale_export_print ( $translation );
if ( $plural ) {
$translation = $parent [ $plural ][ 'translation' ];
if ( $i > 1 ) {
$translation = _locale_export_remove_plural ( $translation );
}
$plural = $parent [ $plural ][ 'plural' ];
}
else {
$translation = '' ;
}
2004-08-11 11:26:20 +00:00
}
}
else {
2007-04-13 08:56:59 +00:00
print 'msgstr[0] ""' . " \n " ;
print 'msgstr[1] ""' . " \n " ;
2004-08-11 11:26:20 +00:00
}
}
else {
2007-03-28 14:08:23 +00:00
if ( isset ( $language )) {
2004-08-11 11:26:20 +00:00
print 'msgstr ' . _locale_export_print ( $message [ 'translation' ]);
}
else {
2007-04-13 08:56:59 +00:00
print 'msgstr ""' . " \n " ;
2004-08-11 11:26:20 +00:00
}
}
print " \n " ;
}
}
die ();
}
/**
* Print out a string on multiple lines
*/
function _locale_export_print ( $str ) {
$stri = addcslashes ( $str , " \0 .. \37 \\ \" " );
$parts = array ();
// Cut text into several lines
while ( $stri != " " ) {
$i = strpos ( $stri , " \\ n " );
if ( $i === FALSE ) {
$curstr = $stri ;
$stri = " " ;
}
else {
$curstr = substr ( $stri , 0 , $i + 2 );
$stri = substr ( $stri , $i + 2 );
}
$curparts = explode ( " \n " , _locale_export_wrap ( $curstr , 70 ));
$parts = array_merge ( $parts , $curparts );
}
2007-03-28 14:08:23 +00:00
// Multiline string
2004-08-11 11:26:20 +00:00
if ( count ( $parts ) > 1 ) {
return " \" \" \n \" " . implode ( " \" \n \" " , $parts ) . " \" \n " ;
}
2007-03-28 14:08:23 +00:00
// Single line string
elseif ( count ( $parts ) == 1 ) {
2004-08-11 11:26:20 +00:00
return " \" $parts[0] \" \n " ;
}
2007-03-28 14:08:23 +00:00
// No translation
else {
return " \" \" \n " ;
}
2004-08-11 11:26:20 +00:00
}
/**
* Custom word wrapping for Portable Object ( Template ) files .
*/
function _locale_export_wrap ( $str , $len ) {
2006-01-13 14:38:38 +00:00
$words = explode ( ' ' , $str );
2004-08-11 11:26:20 +00:00
$ret = array ();
$cur = " " ;
$nstr = 1 ;
while ( count ( $words )) {
$word = array_shift ( $words );
if ( $nstr ) {
$cur = $word ;
$nstr = 0 ;
}
elseif ( strlen ( " $cur $word " ) > $len ) {
2007-04-13 08:56:59 +00:00
$ret [] = $cur . " " ;
2004-08-11 11:26:20 +00:00
$cur = $word ;
}
else {
$cur = " $cur $word " ;
}
}
$ret [] = $cur ;
return implode ( " \n " , $ret );
}
/**
* Removes plural index information from a string
*/
function _locale_export_remove_plural ( $entry ) {
2006-08-18 12:17:00 +00:00
return preg_replace ( '/(@count)\[[0-9]\]/' , '\\1' , $entry );
2004-08-11 11:26:20 +00:00
}
/**
2007-05-03 09:51:08 +00:00
* @ } End of " locale-api-export "
2004-08-11 11:26:20 +00:00
*/
/**
2007-05-03 09:51:08 +00:00
* @ defgroup locale - api - seek String search functions .
* @ {
2004-08-11 11:26:20 +00:00
*/
/**
* Perform a string search and display results in a table
*/
2007-05-03 09:51:08 +00:00
function _locale_translate_seek () {
2007-03-26 01:32:22 +00:00
$output = '' ;
2005-03-31 21:18:08 +00:00
// We have at least one criterion to match
2007-05-03 09:51:08 +00:00
if ( $query = _locale_translate_seek_query ()) {
$join = " SELECT s.source, s.location, s.lid, s.textgroup, t.translation, t.language FROM { locales_source} s INNER JOIN { locales_target} t ON s.lid = t.lid " ;
2004-08-11 11:26:20 +00:00
2006-01-05 23:35:34 +00:00
$arguments = array ();
2004-08-11 11:26:20 +00:00
// Compute LIKE section
2007-05-03 09:51:08 +00:00
switch ( $query [ 'translation' ]) {
2004-08-11 11:26:20 +00:00
case 'translated' :
2006-01-05 23:35:34 +00:00
$where = " WHERE (t.translation LIKE '%%%s%%' AND t.translation != '') " ;
2004-08-11 11:26:20 +00:00
$orderby = " ORDER BY t.translation " ;
2007-03-26 01:32:22 +00:00
$arguments [] = $query [ 'string' ];
2004-08-11 11:26:20 +00:00
break ;
case 'untranslated' :
2006-01-05 23:35:34 +00:00
$where = " WHERE (s.source LIKE '%%%s%%' AND t.translation = '') " ;
2004-08-11 11:26:20 +00:00
$orderby = " ORDER BY s.source " ;
2007-03-26 01:32:22 +00:00
$arguments [] = $query [ 'string' ];
2004-08-11 11:26:20 +00:00
break ;
case 'all' :
default :
2006-01-05 23:35:34 +00:00
$where = " WHERE (s.source LIKE '%%%s%%' OR t.translation LIKE '%%%s%%') " ;
2004-08-11 11:26:20 +00:00
$orderby = '' ;
2007-03-26 01:32:22 +00:00
$arguments [] = $query [ 'string' ];
$arguments [] = $query [ 'string' ];
2004-08-11 11:26:20 +00:00
break ;
}
2007-05-03 09:51:08 +00:00
$grouplimit = '' ;
if ( ! empty ( $query [ 'group' ]) && $query [ 'group' ] != 'all' ) {
$grouplimit = " AND s.textgroup = '%s' " ;
$arguments [] = $query [ 'group' ];
}
2004-08-11 11:26:20 +00:00
2007-03-26 01:32:22 +00:00
switch ( $query [ 'language' ]) {
2004-08-11 11:26:20 +00:00
// Force search in source strings
case " en " :
2007-05-03 09:51:08 +00:00
$sql = $join . " WHERE s.source LIKE '%%%s%%' $grouplimit ORDER BY s.source " ;
2007-03-26 01:32:22 +00:00
$arguments = array ( $query [ 'string' ]); // $where is not used, discard its arguments
2007-05-03 09:51:08 +00:00
if ( ! empty ( $grouplimit )) {
$arguments [] = $query [ 'group' ];
}
2004-08-11 11:26:20 +00:00
break ;
// Search in all languages
case " all " :
2007-05-03 09:51:08 +00:00
$sql = " $join $where $grouplimit $orderby " ;
2004-08-11 11:26:20 +00:00
break ;
// Some different language
default :
2007-05-03 09:51:08 +00:00
$sql = " $join $where $grouplimit AND t.language = '%s' $orderby " ;
2007-03-26 01:32:22 +00:00
$arguments [] = $query [ 'language' ];
2004-08-11 11:26:20 +00:00
}
2006-01-05 23:35:34 +00:00
$result = pager_query ( $sql , 50 , 0 , NULL , $arguments );
2004-08-11 11:26:20 +00:00
2007-05-03 09:51:08 +00:00
$groups = module_invoke_all ( 'locale' , 'groups' );
$header = array ( t ( 'Text group' ), t ( 'String' ), t ( 'Languages' ), array ( 'data' => t ( 'Operations' ), 'colspan' => '2' ));
2004-08-11 11:26:20 +00:00
$arr = array ();
while ( $locale = db_fetch_object ( $result )) {
2007-05-03 09:51:08 +00:00
$arr [ $locale -> lid ][ 'group' ] = $groups [ $locale -> textgroup ];
$arr [ $locale -> lid ][ 'languages' ][ $locale -> language ] = $locale -> translation ;
2004-08-11 11:26:20 +00:00
$arr [ $locale -> lid ][ 'location' ] = $locale -> location ;
$arr [ $locale -> lid ][ 'source' ] = $locale -> source ;
}
2007-03-26 01:32:22 +00:00
$rows = array ();
2004-08-11 11:26:20 +00:00
foreach ( $arr as $lid => $value ) {
2007-05-03 09:51:08 +00:00
$rows [] = array ( $value [ 'group' ], array ( 'data' => check_plain ( truncate_utf8 ( $value [ 'source' ], 150 , FALSE , TRUE )) . '<br /><small>' . $value [ 'location' ] . '</small>' ), array ( 'data' => _locale_translate_language_list ( $value [ 'languages' ]), 'align' => 'center' ), array ( 'data' => l ( t ( 'edit' ), " admin/build/translate/edit/ $lid " ), 'class' => 'nowrap' ), array ( 'data' => l ( t ( 'delete' ), " admin/build/translate/delete/ $lid " ), 'class' => 'nowrap' ));
2004-08-11 11:26:20 +00:00
}
2005-10-07 06:11:12 +00:00
if ( count ( $rows )) {
$output .= theme ( 'table' , $header , $rows );
2007-03-28 14:08:23 +00:00
if ( $pager = theme ( 'pager' , NULL , 50 )) {
$output .= $pager ;
}
2005-10-07 06:11:12 +00:00
}
2007-03-28 14:08:23 +00:00
else {
$output .= t ( 'No strings found for your search.' );
2005-10-07 06:11:12 +00:00
}
2004-08-11 11:26:20 +00:00
}
return $output ;
}
2007-05-03 09:51:08 +00:00
/**
* Build array out of search criteria specified in request variables
*/
function _locale_translate_seek_query () {
static $query = NULL ;
if ( ! isset ( $query )) {
$query = array ();
$fields = array ( 'string' , 'language' , 'translation' , 'group' );
foreach ( $fields as $field ) {
if ( isset ( $_REQUEST [ $field ])) {
$query [ $field ] = $_REQUEST [ $field ];
}
}
}
return $query ;
}
/**
* List languages in search result table
*/
function _locale_translate_language_list ( $translation ) {
// Add CSS
drupal_add_css ( drupal_get_path ( 'module' , 'locale' ) . '/locale.css' , 'module' , 'all' , FALSE );
$languages = language_list ();
unset ( $languages [ 'en' ]);
$output = '' ;
foreach ( $languages as $langcode => $language ) {
$output .= ( ! empty ( $translation [ $langcode ])) ? $langcode . ' ' : " <em class= \" locale-untranslated \" > $langcode </em> " ;
}
return $output ;
}
/**
* @ } End of " locale-api-seek "
*/
/**
* @ defgroup locale - api - predefined List of predefined languages
* @ {
*/
2004-08-11 11:26:20 +00:00
/**
* Prepares the language code list for a select form item with only the unsupported ones
*/
2007-03-26 01:32:22 +00:00
function _locale_prepare_predefined_list () {
$languages = language_list ();
$predefined = _locale_get_predefined_list ();
foreach ( $predefined as $key => $value ) {
if ( isset ( $languages [ $key ])) {
unset ( $predefined [ $key ]);
2004-08-11 11:26:20 +00:00
continue ;
}
2007-03-26 01:32:22 +00:00
// Include native name in output, if possible
2004-08-11 11:26:20 +00:00
if ( count ( $value ) == 2 ) {
$tname = t ( $value [ 0 ]);
2007-03-26 01:32:22 +00:00
$predefined [ $key ] = ( $tname == $value [ 1 ]) ? $tname : " $tname ( $value[1] ) " ;
2004-08-11 11:26:20 +00:00
}
else {
2007-03-26 01:32:22 +00:00
$predefined [ $key ] = t ( $value [ 0 ]);
2004-08-11 11:26:20 +00:00
}
}
2007-03-26 01:32:22 +00:00
asort ( $predefined );
return $predefined ;
2004-08-11 11:26:20 +00:00
}
/**
* Some of the common languages with their English and native names
*
* Based on ISO 639 and http :// people . w3 . org / rishida / names / languages . html
*/
2007-03-26 01:32:22 +00:00
function _locale_get_predefined_list () {
2004-08-11 11:26:20 +00:00
return array (
" aa " => array ( " Afar " ),
" ab " => array ( " Abkhazian " , " аҧсуа бызшәа " ),
" ae " => array ( " Avestan " ),
" af " => array ( " Afrikaans " ),
" ak " => array ( " Akan " ),
" am " => array ( " Amharic " , " አማርኛ " ),
2007-03-26 01:32:22 +00:00
" ar " => array ( " Arabic " , /* Left-to-right marker " " */ " العربية " , 1 ),
2004-08-11 11:26:20 +00:00
" as " => array ( " Assamese " ),
" av " => array ( " Avar " ),
" ay " => array ( " Aymara " ),
" az " => array ( " Azerbaijani " , " azərbaycan " ),
" ba " => array ( " Bashkir " ),
" be " => array ( " Belarusian " , " Беларуская " ),
" bg " => array ( " Bulgarian " , " Български " ),
" bh " => array ( " Bihari " ),
" bi " => array ( " Bislama " ),
" bm " => array ( " Bambara " , " Bamanankan " ),
" bn " => array ( " Bengali " ),
" bo " => array ( " Tibetan " ),
" br " => array ( " Breton " ),
" bs " => array ( " Bosnian " , " Bosanski " ),
" ca " => array ( " Catalan " , " Català " ),
" ce " => array ( " Chechen " ),
" ch " => array ( " Chamorro " ),
" co " => array ( " Corsican " ),
" cr " => array ( " Cree " ),
" cs " => array ( " Czech " , " Čeština " ),
" cu " => array ( " Old Slavonic " ),
2006-08-11 17:51:20 +00:00
" cv " => array ( " Chuvash " ),
" cy " => array ( " Welsh " , " Cymraeg " ),
2006-04-19 13:22:12 +00:00
" da " => array ( " Danish " , " Dansk " ),
2004-08-11 11:26:20 +00:00
" de " => array ( " German " , " Deutsch " ),
" dv " => array ( " Maldivian " ),
" dz " => array ( " Bhutani " ),
" ee " => array ( " Ewe " , " Ɛʋɛ " ),
" el " => array ( " Greek " , " Ελληνικά " ),
" en " => array ( " English " ),
" eo " => array ( " Esperanto " ),
" es " => array ( " Spanish " , " Español " ),
" et " => array ( " Estonian " , " Eesti " ),
" eu " => array ( " Basque " , " Euskera " ),
2007-03-26 01:32:22 +00:00
" fa " => array ( " Persian " , /* Left-to-right marker " " */ " فارسی " , 1 ),
2004-08-11 11:26:20 +00:00
" ff " => array ( " Fulah " , " Fulfulde " ),
" fi " => array ( " Finnish " , " Suomi " ),
" fj " => array ( " Fiji " ),
" fo " => array ( " Faeroese " ),
" fr " => array ( " French " , " Français " ),
" fy " => array ( " Frisian " , " Frysk " ),
" ga " => array ( " Irish " , " Gaeilge " ),
" gd " => array ( " Scots Gaelic " ),
" gl " => array ( " Galician " , " Galego " ),
" gn " => array ( " Guarani " ),
" gu " => array ( " Gujarati " ),
" gv " => array ( " Manx " ),
" ha " => array ( " Hausa " ),
2007-03-26 01:32:22 +00:00
" he " => array ( " Hebrew " , /* Left-to-right marker " " */ " עברית " , 1 ),
2004-08-11 11:26:20 +00:00
" hi " => array ( " Hindi " , " हिन्दी " ),
" ho " => array ( " Hiri Motu " ),
" hr " => array ( " Croatian " , " Hrvatski " ),
" hu " => array ( " Hungarian " , " Magyar " ),
" hy " => array ( " Armenian " , " Հայերեն " ),
" hz " => array ( " Herero " ),
" ia " => array ( " Interlingua " ),
" id " => array ( " Indonesian " , " Bahasa Indonesia " ),
" ie " => array ( " Interlingue " ),
" ig " => array ( " Igbo " ),
" ik " => array ( " Inupiak " ),
" is " => array ( " Icelandic " , " Íslenska " ),
" it " => array ( " Italian " , " Italiano " ),
" iu " => array ( " Inuktitut " ),
" ja " => array ( " Japanese " , " 日本語 " ),
" jv " => array ( " Javanese " ),
" ka " => array ( " Georgian " ),
" kg " => array ( " Kongo " ),
" ki " => array ( " Kikuyu " ),
" kj " => array ( " Kwanyama " ),
" kk " => array ( " Kazakh " , " Қазақ " ),
" kl " => array ( " Greenlandic " ),
" km " => array ( " Cambodian " ),
" kn " => array ( " Kannada " , " ಕನ್ನಡ " ),
" ko " => array ( " Korean " , " 한국어 " ),
" kr " => array ( " Kanuri " ),
" ks " => array ( " Kashmiri " ),
" ku " => array ( " Kurdish " , " Kurdî " ),
" kv " => array ( " Komi " ),
" kw " => array ( " Cornish " ),
" ky " => array ( " Kirghiz " , " Кыргыз " ),
" la " => array ( " Latin " , " Latina " ),
" lb " => array ( " Luxembourgish " ),
" lg " => array ( " Luganda " ),
" ln " => array ( " Lingala " ),
" lo " => array ( " Laothian " ),
" lt " => array ( " Lithuanian " , " Lietuviškai " ),
" lv " => array ( " Latvian " , " Latviešu " ),
" mg " => array ( " Malagasy " ),
" mh " => array ( " Marshallese " ),
" mi " => array ( " Maori " ),
" mk " => array ( " Macedonian " , " Македонски " ),
" ml " => array ( " Malayalam " , " മലയാളം " ),
" mn " => array ( " Mongolian " ),
" mo " => array ( " Moldavian " ),
" mr " => array ( " Marathi " ),
" ms " => array ( " Malay " , " Bahasa Melayu " ),
" mt " => array ( " Maltese " , " Malti " ),
" my " => array ( " Burmese " ),
" na " => array ( " Nauru " ),
" nd " => array ( " North Ndebele " ),
" ne " => array ( " Nepali " ),
" ng " => array ( " Ndonga " ),
" nl " => array ( " Dutch " , " Nederlands " ),
2007-03-24 19:07:34 +00:00
" nb " => array ( " Norwegian Bokmål " , " Bokmål " ),
" nn " => array ( " Norwegian Nynorsk " , " Nynorsk " ),
2004-08-11 11:26:20 +00:00
" nr " => array ( " South Ndebele " ),
" nv " => array ( " Navajo " ),
" ny " => array ( " Chichewa " ),
" oc " => array ( " Occitan " ),
" om " => array ( " Oromo " ),
" or " => array ( " Oriya " ),
" os " => array ( " Ossetian " ),
" pa " => array ( " Punjabi " ),
" pi " => array ( " Pali " ),
" pl " => array ( " Polish " , " Polski " ),
2007-03-26 01:32:22 +00:00
" ps " => array ( " Pashto " , /* Left-to-right marker " " */ " پښتو " , 1 ),
2006-12-07 17:10:29 +00:00
" pt " => array ( " Portuguese, Portugal " , " Português " ),
" pt-br " => array ( " Portuguese, Brazil " , " Português " ),
2004-08-11 11:26:20 +00:00
" qu " => array ( " Quechua " ),
" rm " => array ( " Rhaeto-Romance " ),
" rn " => array ( " Kirundi " ),
" ro " => array ( " Romanian " , " Română " ),
" ru " => array ( " Russian " , " Русский " ),
" rw " => array ( " Kinyarwanda " ),
" sa " => array ( " Sanskrit " ),
" sc " => array ( " Sardinian " ),
" sd " => array ( " Sindhi " ),
" se " => array ( " Northern Sami " ),
" sg " => array ( " Sango " ),
" sh " => array ( " Serbo-Croatian " ),
" si " => array ( " Singhalese " ),
" sk " => array ( " Slovak " , " Slovenčina " ),
" sl " => array ( " Slovenian " , " Slovenščina " ),
" sm " => array ( " Samoan " ),
" sn " => array ( " Shona " ),
" so " => array ( " Somali " ),
" sq " => array ( " Albanian " , " Shqip " ),
" sr " => array ( " Serbian " , " Српски " ),
" ss " => array ( " Siswati " ),
" st " => array ( " Sesotho " ),
" su " => array ( " Sudanese " ),
" sv " => array ( " Swedish " , " Svenska " ),
" sw " => array ( " Swahili " , " Kiswahili " ),
" ta " => array ( " Tamil " , " தமிழ் " ),
" te " => array ( " Telugu " , " తెలుగు " ),
" tg " => array ( " Tajik " ),
" th " => array ( " Thai " , " ภาษาไทย " ),
" ti " => array ( " Tigrinya " ),
" tk " => array ( " Turkmen " ),
" tl " => array ( " Tagalog " ),
" tn " => array ( " Setswana " ),
" to " => array ( " Tonga " ),
" tr " => array ( " Turkish " , " Türkçe " ),
" ts " => array ( " Tsonga " ),
" tt " => array ( " Tatar " , " Tatarça " ),
" tw " => array ( " Twi " ),
" ty " => array ( " Tahitian " ),
" ug " => array ( " Uighur " ),
" uk " => array ( " Ukrainian " , " Українська " ),
2007-03-26 01:32:22 +00:00
" ur " => array ( " Urdu " , /* Left-to-right marker " " */ " اردو " , 1 ),
2004-08-11 11:26:20 +00:00
" uz " => array ( " Uzbek " , " o'zbek " ),
" ve " => array ( " Venda " ),
" vi " => array ( " Vietnamese " , " Tiếng Việt " ),
" wo " => array ( " Wolof " ),
" xh " => array ( " Xhosa " , " isiXhosa " ),
" yi " => array ( " Yiddish " ),
" yo " => array ( " Yoruba " , " Yorùbá " ),
" za " => array ( " Zhuang " ),
2004-09-09 11:53:56 +00:00
" zh-hans " => array ( " Chinese, Simplified " , " 简体中文 " ),
" zh-hant " => array ( " Chinese, Traditional " , " 繁體中文 " ),
2004-08-11 11:26:20 +00:00
" zu " => array ( " Zulu " , " isiZulu " ),
);
}
2007-05-03 09:51:08 +00:00
/**
* @ } End of " locale-api-languages-predefined "
*/