mirror of https://github.com/BOINC/boinc.git
Drupal: Remove pre-defined project-specific translation resource
Require that at least one project-specific resource be provided in Transifex settings and set the first one given as the target for translation exports https://dev.gridrepublic.org/browse/DBOINCP-222
This commit is contained in:
parent
74d8b8f370
commit
c734b6e2d4
|
@ -111,7 +111,11 @@ function boinctranslate_admin_settings(&$form_state) {
|
|||
for translating strings on this site (one resource string per line).
|
||||
Resources will be imported in the order they are given, so
|
||||
translations from the resources at the top of the list will be overridden
|
||||
by any matching translations found in resources further down the list.'),
|
||||
by any matching translations found in resources further down the list.
|
||||
<br/>
|
||||
NOTE: The first resource listed here is considered the primary resource
|
||||
for project-specific translations and will be updated by the "Update
|
||||
project-specific resources" button below!'),
|
||||
);
|
||||
$form['transifex']['buttons']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
|
@ -209,6 +213,11 @@ function boinctranslate_admin_settings_validate($form, &$form_state) {
|
|||
t('At least one BOINC Transifex project resource is required.')
|
||||
);
|
||||
}
|
||||
if (!$values['boinc_translate_transifex_project_resources']) {
|
||||
form_set_error('boinc_translate_transifex_project_resources',
|
||||
t('At least one project-specific Transifex resource is required.')
|
||||
);
|
||||
}
|
||||
|
||||
$username = $values['boinc_translate_transifex_user'];
|
||||
$password = ($values['boinc_translate_transifex_pass']) ? $values['boinc_translate_transifex_pass'] : variable_get('boinc_translate_transifex_pass', '');
|
||||
|
|
|
@ -385,15 +385,21 @@ function boinctranslate_export_translations() {
|
|||
$project_name = variable_get(
|
||||
'boinc_translate_transifex_project_name', ''
|
||||
);
|
||||
// Get resource names from local config
|
||||
$resource_config = (variable_get(
|
||||
'boinc_translate_transifex_project_resources', ''
|
||||
));
|
||||
$resource_names = boinctranslate_parse_resources($resource_config);
|
||||
$primary_resource = reset($resource_names);
|
||||
|
||||
if ($project_name) {
|
||||
if ($project_name AND $primary_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-project') {
|
||||
if ($resource['slug'] == $primary_resource) {
|
||||
$source_exists = TRUE;
|
||||
break;
|
||||
}
|
||||
|
@ -402,7 +408,7 @@ function boinctranslate_export_translations() {
|
|||
// Create the source
|
||||
$path = "project/{$project_name}/resources";
|
||||
$post = array(
|
||||
'slug' => 'drupal-project',
|
||||
'slug' => $primary_resource,
|
||||
'name' => 'Drupal-Project',
|
||||
'i18n_type' => 'PO',
|
||||
'category' => 'Drupal',
|
||||
|
@ -412,7 +418,7 @@ function boinctranslate_export_translations() {
|
|||
}
|
||||
else {
|
||||
// Update the source
|
||||
$path = "project/{$project_name}/resource/drupal-project/content";
|
||||
$path = "project/{$project_name}/resource/{$primary_resource}/content";
|
||||
$post = array(
|
||||
'content' => boinctranslate_get_po('en', 'project')
|
||||
);
|
||||
|
@ -428,21 +434,6 @@ function boinctranslate_export_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_project_resources', ''
|
||||
));
|
||||
$resource_names = boinctranslate_parse_resources($resource_config);
|
||||
if (!in_array('drupal-project', $resource_names)) {
|
||||
$resource_config .= "\n" . 'drupal-project';
|
||||
variable_set(
|
||||
'boinc_translate_transifex_project_resources',
|
||||
$resource_config
|
||||
);
|
||||
drupal_set_message(
|
||||
'Added drupal-project to Project-specific resources'
|
||||
);
|
||||
}
|
||||
// Try to export translations for all enabled languages
|
||||
foreach ($enabled_languages as $langcode => $language_name) {
|
||||
if ($langcode == 'en') {
|
||||
|
@ -450,7 +441,7 @@ function boinctranslate_export_translations() {
|
|||
}
|
||||
$po_file = boinctranslate_get_po($langcode, 'project');
|
||||
if ($po_file) {
|
||||
$path = "project/{$project_name}/resource/drupal-project/translation/{$langcode}";
|
||||
$path = "project/{$project_name}/resource/{$primary_resource}/translation/{$langcode}";
|
||||
$post = array(
|
||||
'content' => $po_file,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue