Updated boinctranslate_update_official_boinc_translations() tool to use a configurable resource name

(DBOINCP-141)
This commit is contained in:
Tristan Olive 2015-04-17 02:04:37 -04:00
parent b18adf9388
commit 8caf89cf8e
2 changed files with 23 additions and 21 deletions

View File

@ -24,6 +24,10 @@ function boinctranslate_admin_settings(&$form_state) {
'boinc_translate_transifex_standard_resources',
"project-generic\nweb"
),
'transifex_boinc_drupal_resource' => variable_get(
'boinc_translate_transifex_boinc_drupal_resource',
'drupal'
),
'transifex_project_name' => variable_get(
'boinc_translate_transifex_project_name', ''
),
@ -83,6 +87,16 @@ function boinctranslate_admin_settings(&$form_state) {
translations from the resources at the top of the list will be overridden
by any matching translations found in resources further down the list.'),
);
if (user_access('update official BOINC translations')) {
$form['transifex']['boinc_translate_transifex_boinc_drupal_resource'] = array(
'#type' => 'textfield',
'#title' => t('BOINC Drupal resource'),
'#default_value' => $default['transifex_boinc_drupal_resource'],
'#description' => t('The portion of the Transifex URL that identifies
the standard BOINC resource to use for translation of the public
content defined in the Drupal system.'),
);
}
$form['transifex']['boinc_translate_transifex_project_name'] = array(
'#type' => 'textfield',
'#title' => t('Project-specific Transifex project'),

View File

@ -373,15 +373,18 @@ function boinctranslate_update_official_boinc_translations() {
$project_name = variable_get(
'boinc_translate_transifex_standard_name', ''
);
$drupal_resource = variable_get(
'boinc_translate_transifex_boinc_drupal_resource', ''
);
if ($project_name) {
if ($project_name AND $drupal_resource) {
// Create or update the translation source, if needed
$source_exists = FALSE;
$path = "project/{$project_name}/resources";
$resources = boinctranslate_transifex_request($path);
if ($resources AND is_array($resources)) {
foreach ($resources as $resource) {
if ($resource['slug'] == 'drupal-generic') {
if ($resource['slug'] == $drupal_resource) {
$source_exists = TRUE;
break;
}
@ -390,8 +393,8 @@ function boinctranslate_update_official_boinc_translations() {
// Create the source
$path = "project/{$project_name}/resources";
$post = array(
'slug' => 'drupal-generic',
'name' => 'Drupal-Generic',
'slug' => $drupal_resource,
'name' => 'locale/templates/BOINC-Drupal.pot',
'i18n_type' => 'PO',
'category' => 'Drupal',
'content' => boinctranslate_get_po('en', 'boinc'),
@ -399,7 +402,7 @@ function boinctranslate_update_official_boinc_translations() {
}
else {
// Update the source
$path = "project/{$project_name}/resource/drupal-generic/content";
$path = "project/{$project_name}/resource/{$drupal_resource}/content";
$post = array(
'content' => boinctranslate_get_po('en', 'boinc')
);
@ -415,21 +418,6 @@ function boinctranslate_update_official_boinc_translations() {
else {
drupal_set_message('Established new translation resource at Transifex');
}
// Ensure this exported project resource is in the config
$resource_config = (variable_get(
'boinc_translate_transifex_standard_resources', ''
));
$resource_names = boinctranslate_parse_resources($resource_config);
if (!in_array('drupal-generic', $resource_names)) {
$resource_config .= "\n" . 'drupal-generic';
variable_set(
'boinc_translate_transifex_standard_resources',
$resource_config
);
drupal_set_message(
'Added drupal-generic to BOINC resources'
);
}
// Try to export translations for all enabled languages
foreach ($enabled_languages as $langcode => $language_name) {
if ($langcode == en) {
@ -437,7 +425,7 @@ function boinctranslate_update_official_boinc_translations() {
}
$po_file = boinctranslate_get_po($langcode, 'boinc');
if ($po_file) {
$path = "project/{$project_name}/resource/drupal-generic/translation/{$langcode}";
$path = "project/{$project_name}/resource/{$drupal_resource}/translation/{$langcode}";
$post = array(
'content' => $po_file,
);