Include translations in build-process

Download commons translation files during make process, enable and
import languages during installation, set language negotiation to
URL based. Supported languages: zh-hant,zh-hans,ja,ko,vi,ru,pl,
de,fr,es,it,pt-pt,hu,ar,tr

Change-Id: I8f05a63b00f657225d3b8b84d531940dddbe8162
This commit is contained in:
Marton Kiss 2013-09-15 11:27:36 +02:00
parent 1502873142
commit a1a458d25f
4 changed files with 159 additions and 1 deletions

View File

@ -1,7 +1,8 @@
api = 2
core = 7.x
includes[] = "commons.make"
includes[commons] = "commons.make"
includes[translations] = "groups-translations.make"
; Contributed modules.

81
groups-translations.make Normal file
View File

@ -0,0 +1,81 @@
api = 2
core = 7.x
; Notice: we are using 'profile' as a project type here, because drush make
; doesn't support direct download of contribution language files
;
projects[translation_zh-hant][type] = "profile"
projects[translation_zh-hant][directory_name] = "groups/translations"
projects[translation_zh-hant][download][type] = "file"
projects[translation_zh-hant][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.zh-hant.po"
projects[translation_zh-hans][type] = "profile"
projects[translation_zh-hans][directory_name] = "groups/translations"
projects[translation_zh-hans][download][type] = "file"
projects[translation_zh-hans][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.zh-hans.po"
projects[translation_ja][type] = "profile"
projects[translation_ja][directory_name] = "groups/translations"
projects[translation_ja][download][type] = "file"
projects[translation_ja][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.ja.po"
projects[translation_ko][type] = "profile"
projects[translation_ko][directory_name] = "groups/translations"
projects[translation_ko][download][type] = "file"
projects[translation_ko][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.ko.po"
projects[translation_vi][type] = "profile"
projects[translation_vi][directory_name] = "groups/translations"
projects[translation_vi][download][type] = "file"
projects[translation_vi][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.vi.po"
projects[translation_ru][type] = "profile"
projects[translation_ru][directory_name] = "groups/translations"
projects[translation_ru][download][type] = "file"
projects[translation_ru][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.ru.po"
projects[translation_pl][type] = "profile"
projects[translation_pl][directory_name] = "groups/translations"
projects[translation_pl][download][type] = "file"
projects[translation_pl][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.pl.po"
projects[translation_de][type] = "profile"
projects[translation_de][directory_name] = "groups/translations"
projects[translation_de][download][type] = "file"
projects[translation_de][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.de.po"
projects[translation_fr][type] = "profile"
projects[translation_fr][directory_name] = "groups/translations"
projects[translation_fr][download][type] = "file"
projects[translation_fr][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.fr.po"
projects[translation_es][type] = "profile"
projects[translation_es][directory_name] = "groups/translations"
projects[translation_es][download][type] = "file"
projects[translation_es][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.es.po"
projects[translation_it][type] = "profile"
projects[translation_it][directory_name] = "groups/translations"
projects[translation_it][download][type] = "file"
projects[translation_it][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.it.po"
projects[translation_pt-pt][type] = "profile"
projects[translation_pt-pt][directory_name] = "groups/translations"
projects[translation_pt-pt][download][type] = "file"
projects[translation_pt-pt][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.pt-pt.po"
projects[translation_hu][type] = "profile"
projects[translation_hu][directory_name] = "groups/translations"
projects[translation_hu][download][type] = "file"
projects[translation_hu][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.hu.po"
projects[translation_ar][type] = "profile"
projects[translation_ar][directory_name] = "groups/translations"
projects[translation_ar][download][type] = "file"
projects[translation_ar][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.ar.po"
projects[translation_tr][type] = "profile"
projects[translation_tr][directory_name] = "groups/translations"
projects[translation_tr][download][type] = "file"
projects[translation_tr][download][url] = "http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.tr.po"

View File

@ -50,9 +50,60 @@ function groups_install_tasks() {
'groups_revert_features' => array(
'display' => FALSE,
),
'groups_import_locales' => array(
'display_name' => 'Install additional languages',
'display' => TRUE,
'type' => 'batch',
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
),
);
}
/**
* Import translation files and languages from profile directory
*
*/
function groups_import_locales(&$install_state) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
include_once DRUPAL_ROOT . '/includes/iso.inc';
$batch = array(
'title' => t('Importing interface translations'),
'init_message' => t('Starting import'),
'error_message' => t('Error importing interface translations'),
'file' => 'includes/locale.inc',
'operations' => array(),
);
$predefined = _locale_get_predefined_list();
$path = drupal_get_path('profile', drupal_get_profile()) . '/translations';
$translations = file_scan_directory($path, '/.*\.po$/');
foreach ($translations as $file) {
$langcode = pathinfo($file->name, PATHINFO_EXTENSION);
if (isset($predefined[$langcode])) {
locale_add_language($langcode);
$batch['operations'][] = array('_locale_import_po', array($file,
$langcode, LOCALE_IMPORT_OVERWRITE, 'default'));
}
}
return $batch;
}
/**
* Set language negotiation to URL based.
*
*/
function groups_set_language_negotiation() {
require_once DRUPAL_ROOT . '/includes/language.inc';
require_once DRUPAL_ROOT . '/includes/locale.inc';
$negotation = array(
LOCALE_LANGUAGE_NEGOTIATION_URL => 2,
LANGUAGE_NEGOTIATION_DEFAULT => 10,
);
language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $negotation);
}
/**
* Override of install_finished() without the useless text.
*/
@ -66,6 +117,9 @@ function groups_install_finished(&$install_state) {
_flag_clear_cache();
}
// set language negotation
groups_set_language_negotiation();
// Flush all caches to ensure that any full bootstraps during the installer
// do not leave stale cached data, and that any content types or other items
// registered by the installation profile are registered correctly.

View File

@ -0,0 +1,22 @@
#!/bin/bash
set -e
languages=(zh-hant zh-hans ja ko vi ru pl de fr es it pt-pt hu ar tr)
echo "
api = 2
core = 7.x
; Notice: we are using 'profile' as a project type here, because drush make
; doesn't support direct download of contribution language files
;
"
for i in "${languages[@]}"; do
echo "
projects[translation_${i}][type] = \"profile\"
projects[translation_${i}][directory_name] = \"groups/translations\"
projects[translation_${i}][download][type] = \"file\"
projects[translation_${i}][download][url] = \"http://ftp.drupal.org/files/translations/7.x/commons/commons-7.x-3.3-rc2.${i}.po\""
done