diff --git a/mailchimp.module b/mailchimp.module index 7e0749e..ba5744d 100644 --- a/mailchimp.module +++ b/mailchimp.module @@ -305,7 +305,7 @@ function mailchimp_get_list($list_id) { /** * Get the MailChimp memberinfo for a given email address and list. - * + * * Results are cached in the cache_mailchimp_user bin which is cleared by the MC * web hooks system when needed. * @@ -500,7 +500,7 @@ function mailchimp_get_campaign_data($campaign_id, $reset = FALSE) { /** * Wrapper around MCAPI::campaignsForEmail(). - * + * * Returns all IDs of campaigns that have included a given email address. * * @string $email @@ -546,3 +546,21 @@ function mailchimp_get_lists_by_email($email) { return $filtered_lists; } + +/** + * Helper function to help integrate with the i18n_strings module. + * + * @param string $name + * Textgroup and context glued with ':'. + * @param string $string + * The raw db value for the given property + * @param string $langcode + * Optional language code to override the page requested one. + */ +function mailchimp_t($name, $string, $langcode = NULL) { + static $i18n = NULL; + if (!isset($i18n)) { + $i18n = module_exists('mailchimp_i18n'); + } + return $i18n ? i18n_string($name, $string, array('langcode' => $langcode)) : $string; +} diff --git a/modules/mailchimp_i18n/mailchimp_i18n.info b/modules/mailchimp_i18n/mailchimp_i18n.info new file mode 100644 index 0000000..6a701df --- /dev/null +++ b/modules/mailchimp_i18n/mailchimp_i18n.info @@ -0,0 +1,12 @@ +name = Mailchimp internationalization +description = "Internationalization of mailchimp strings." + +package = "Multilingual - Internationalization" + +; Module dependencies +dependencies[] = mailchimp_lists +dependencies[] = i18n_string + +version = "7.x-2.12" +core = "7.x" +project = "mailchimp" diff --git a/modules/mailchimp_i18n/mailchimp_i18n.module b/modules/mailchimp_i18n/mailchimp_i18n.module new file mode 100644 index 0000000..34fae4d --- /dev/null +++ b/modules/mailchimp_i18n/mailchimp_i18n.module @@ -0,0 +1,40 @@ + t('Mailchimp'), + 'description' => t('Mailchimp strings for localization.'), + 'format' => FALSE, + 'list' => TRUE, + 'refresh callback' => 'mailchimp_i18n_string_refresh', + ); + return $groups; +} + +/** + * i18n_string callback for refreshing all strings. + */ +function mailchimp_i18n_string_refresh() { + $list_entities = mailchimp_lists_load_multiple_by_name(); + foreach ($list_entities as $list_entity) { + $list = mailchimp_get_list($list_entity->mc_list_id); + if (!empty($list['mergevars'])) { + foreach ($list['mergevars'] as $mergevar) { + if (!empty($list_entity->settings['mergefields_display'][$mergevar['tag']])) { + i18n_string_update('mailchimp:form:' . $mergevar['tag'], $mergevar['name']); + } + } + } + i18n_string_update('mailchimp:' . $list_entity->name . ':label', $list_entity->label); + i18n_string_update('mailchimp:' . $list_entity->name . ':description', $list_entity->description); + } + return TRUE; +} diff --git a/modules/mailchimp_lists/mailchimp_lists.module b/modules/mailchimp_lists/mailchimp_lists.module index ac345e4..19ccda9 100644 --- a/modules/mailchimp_lists/mailchimp_lists.module +++ b/modules/mailchimp_lists/mailchimp_lists.module @@ -251,7 +251,7 @@ function mailchimp_lists_form_user_register_form_alter(&$form, &$form_state, $fo /** * Implements hook_user_insert(). - * + * * Subscribe new users to optional and required newsletters. */ function mailchimp_lists_user_insert(&$edit, $account, $category) { @@ -350,12 +350,12 @@ function mailchimp_lists_user_sync($account, $old_email = '', $new_email = '', $ /** * Helper function for mailchimp_lists_user_sync(). - * + * * @user $account * @mailchimp_list $list * @email null $new_email * @email null $old_email - * + * * @return array * The mergevars with all values inserted. */ @@ -408,7 +408,7 @@ function mailchimp_lists_freeform_subscribe_page() { /** * Returns a subscription form, or forms, for a given user as a single form. - * + * * If there are multiple lists, this generates a single form for all of them. */ function mailchimp_lists_user_subscribe_form($form, &$form_state, $lists, $account) { @@ -460,12 +460,12 @@ function mailchimp_lists_auth_newsletter_form(&$form, $list, $account, $add_head $form[$wrapper_key]['list'] = array('#type' => 'value', '#value' => $list); // Add the title and description to lists for anonymous users or if requested: if ($add_header || ($list->settings['allow_anonymous'] && $is_anonymous)) { - $label_text = isset($list->settings['form_label']) ? $list->settings['form_label'] : 'Sign up for ' . $list->label(); + $label_text = isset($list->settings['form_label']) ? $list->settings['form_label'] : t('Sign up for ') . mailchimp_t('mailchimp:' . $list->name . ':label', $list->label()); $label = html_entity_decode(check_plain($label_text, ENT_QUOTES, 'UTF-8')); $form[$wrapper_key]['title'] = array( '#type' => 'item', '#markup' => $label, - '#description' => t('@mc_list_description', array('@mc_list_description' => $list->description)), + '#description' => mailchimp_t('mailchimp:' . $list->name . ':description', $list->description), ); } // Add merge vars for anonymous forms: @@ -585,9 +585,9 @@ function mailchimp_lists_user_subscribe_form_submit($form, &$form_state) { * Processor for various list form submissions. * * Subscription blocks, user settings, and new user creation. - * + * * @array $list_forms: an array of mailchimp_list form values, as generated - * by mailchimp_lists_list_form() + * by mailchimp_lists_list_form() * @account null $account: the user account to subscribe, if available. * Otherwise, operations will be run with the ['mergevars']['EMAIL'] value. */ @@ -643,15 +643,15 @@ function mailchimp_lists_process_subscribe_form_choices($list_forms, $account = /** * Calls the appropriate API function, or adds to the queue, as appropriate. - * + * * @string $function - 'add', 'remove', or 'update'. Matches Queue operations. - * @mailchimp_lists $list - the list to update + * @mailchimp_lists $list - the list to update * @string $mail - email address to update on the list * @array $mergevars - merge variables array formatted for mailchimp API * @account null $account - account that $mail came from, if non-anonymous call * @mcapi_entity null &$mcapi - api object if loaded, to avoid extra API calls * @queue null &$queue - the cron queue. If passed, this will force use of cron. - * + * * @return * Indicates whether the operation was successful. */ @@ -737,7 +737,7 @@ function mailchimp_lists_mailchimp_lists_merge_tokens() { /** * Get the relevant merge vars for the given user for the given list. - * + * * @account $account * @mailchimp_list $list * @array null $interest_groups @@ -890,7 +890,7 @@ function mailchimp_lists_block_view($delta = '') { function mailchimp_lists_insert_drupal_form_tag($mergevar) { // Insert common FormAPI properties: $input = array( - '#title' => t('@mergevar', array('@mergevar' => $mergevar['name'])), + '#title' => mailchimp_t('mailchimp:form:' . $mergevar['tag'], $mergevar['name']), '#weight' => $mergevar['order'], '#required' => $mergevar['req'], '#default_value' => $mergevar['default'], @@ -970,7 +970,7 @@ function mailchimp_lists_forms($form_id, $args) { * Queue existing users in a list. Optionally, queue users to remove. * * @mailchimp_list $list - * + * * @boolean $queue_removals * If set to TRUE, will queue anyone who should be removed from the list. *