#994500 by Gábor Hojtsy: Fixed Drupal should not require .po file rename in installation

merge-requests/26/head
Angie Byron 2010-12-28 18:17:27 +00:00
parent a45a4c4d48
commit 52ba5cc84c
3 changed files with 21 additions and 22 deletions

View File

@ -91,8 +91,7 @@ INSTALLATION
- Download a translation file for the correct Drupal version and language - Download a translation file for the correct Drupal version and language
from the translation server: http://localize.drupal.org/download from the translation server: http://localize.drupal.org/download
- Rename the downloaded file to your language's ISO code (e.g., de.po or - Place the file into your installation profile's translations
fr.po) and place it into your installation profile's translations
directory. For instance, if you are using the Standard install profile, directory. For instance, if you are using the Standard install profile,
move the .po file into the directory: move the .po file into the directory:

View File

@ -1120,6 +1120,10 @@ function install_select_profile_form($form, &$form_state, $profile_files) {
function install_find_locales($profilename) { function install_find_locales($profilename) {
$locales = file_scan_directory('./profiles/' . $profilename . '/translations', '/\.po$/', array('recurse' => FALSE)); $locales = file_scan_directory('./profiles/' . $profilename . '/translations', '/\.po$/', array('recurse' => FALSE));
array_unshift($locales, (object) array('name' => 'en')); array_unshift($locales, (object) array('name' => 'en'));
foreach ($locales as $key => $locale) {
// The locale (file name) might be drupal-7.2.cs.po instead of cs.po.
$locales[$key]->langcode = preg_replace('!^(.+\.)?([^\.]+)$!', '\2', $locale->name);
}
return $locales; return $locales;
} }
@ -1145,8 +1149,8 @@ function install_select_locale(&$install_state) {
if (!empty($_POST['locale'])) { if (!empty($_POST['locale'])) {
foreach ($locales as $locale) { foreach ($locales as $locale) {
if ($_POST['locale'] == $locale->name) { if ($_POST['locale'] == $locale->langcode) {
$install_state['parameters']['locale'] = $locale->name; $install_state['parameters']['locale'] = $locale->langcode;
return; return;
} }
} }
@ -1164,14 +1168,6 @@ function install_select_locale(&$install_state) {
$output = '<p>Follow these steps to translate Drupal into your language:</p>'; $output = '<p>Follow these steps to translate Drupal into your language:</p>';
$output .= '<ol>'; $output .= '<ol>';
$output .= '<li>Download a translation from the <a href="http://localize.drupal.org/download" target="_blank">translation server</a>.</li>'; $output .= '<li>Download a translation from the <a href="http://localize.drupal.org/download" target="_blank">translation server</a>.</li>';
$output .= '<li>Rename the downloaded file retaining only the language code at the end of the file name and its extension. For example, if the file name is
<pre>
drupal-7.0.pt-br.po
</pre>
rename it to
<pre>
pt-br.po
</pre></li>';
$output .= '<li>Place it into the following directory: $output .= '<li>Place it into the following directory:
<pre> <pre>
/profiles/' . $profilename . '/translations/ /profiles/' . $profilename . '/translations/
@ -1237,16 +1233,15 @@ function install_select_locale_form($form, &$form_state, $locales, $profilename)
include_once DRUPAL_ROOT . '/includes/iso.inc'; include_once DRUPAL_ROOT . '/includes/iso.inc';
$languages = _locale_get_predefined_list(); $languages = _locale_get_predefined_list();
foreach ($locales as $locale) { foreach ($locales as $locale) {
// Try to use verbose locale name. $name = $locale->langcode;
$name = $locale->name;
if (isset($languages[$name])) { if (isset($languages[$name])) {
$name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array('@language' => $languages[$name][1])) : ''); $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array('@language' => $languages[$name][1])) : '');
} }
$form['locale'][$locale->name] = array( $form['locale'][$locale->langcode] = array(
'#type' => 'radio', '#type' => 'radio',
'#return_value' => $locale->name, '#return_value' => $locale->langcode,
'#default_value' => $locale->name == 'en' ? 'en' : '', '#default_value' => $locale->langcode == 'en' ? 'en' : '',
'#title' => $name . ($locale->name == 'en' ? ' ' . st('(built-in)') : ''), '#title' => $name . ($locale->langcode == 'en' ? ' ' . st('(built-in)') : ''),
'#parents' => array('locale') '#parents' => array('locale')
); );
} }

View File

@ -1068,11 +1068,16 @@ function st($string, array $args = array(), array $options = array()) {
if (!isset($locale_strings)) { if (!isset($locale_strings)) {
$locale_strings = array(); $locale_strings = array();
if (isset($install_state['parameters']['profile']) && isset($install_state['parameters']['locale'])) { if (isset($install_state['parameters']['profile']) && isset($install_state['parameters']['locale'])) {
$filename = 'profiles/' . $install_state['parameters']['profile'] . '/translations/' . $install_state['parameters']['locale'] . '.po'; // If the given locale was selected, there should be at least one .po file
if (file_exists(DRUPAL_ROOT . '/' . $filename)) { // with its name ending in {$install_state['parameters']['locale']}.po
// This might or might not be the entire filename. It is also possible
// that multiple files end with the same extension, even if unlikely.
$po_files = file_scan_directory('./profiles/' . $install_state['parameters']['profile'] . '/translations', '/'. $install_state['parameters']['locale'] .'\.po$/', array('recurse' => FALSE));
if (count($po_files)) {
require_once DRUPAL_ROOT . '/includes/locale.inc'; require_once DRUPAL_ROOT . '/includes/locale.inc';
$file = (object) array('uri' => $filename); foreach ($po_files as $po_file) {
_locale_import_read_po('mem-store', $file); _locale_import_read_po('mem-store', $po_file);
}
$locale_strings = _locale_import_one_string('mem-report'); $locale_strings = _locale_import_one_string('mem-report');
} }
} }