Allow dynamic amazon locale choice
in

Amazon module of Drupal is very useful when showing items, but the current implementation is limited to one locale.

There is an API level patch here.
Allow dynamic amazon locale choice

I've modified the Amazon Filter module so that I can utilize the API patch. The modification allows amazon filter to have optional locale like

[amazon 1234567890 full JP]

This will show the item from amazon.co.jp, instead of default local (usually U.S.)

<?php
function _amazon_filter_process_text($text) {
 
$pattern = "/\[amazon +(.*?)(?: +(.*?))?(?: +(.*?))?\]/";
 
$matches = array();
  if (
preg_match_all($pattern, $text, $matches)) {
   
$items = array();
   
$ids = array();

   
// Separate amazon items with and without locale
   
for($i = 0; $i < count($matches[1]) ; $i++)
    {
      if(empty(
$matches[3][$i]))
      {
       
// Locale is not specified. Add to the array of ids
       
array_push($ids, $matches[1][$i]);
      }
      else
      {
       
// Local is specified. Store id and locale pair
       
$loc_ids[$matches[1][$i]] = $matches[3][$i];
      }
    }
   
   
// Look up items for default locale
   
foreach(amazon_item_lookup($ids) as $item) {
     
$items[$item['asin']] = $item;
    }
   
   
// Then, look up items with locale
   
if(is_array($loc_ids))
    {
      foreach(
$loc_ids as $id => $loc)
      {
        foreach(
amazon_item_lookup(array($id), $loc) as $item)
        {
         
$items[$item['asin']] = $item;
        }
      }
    }
 
    ... [
snipped] ...
 
?>