I'm using a combination of WordPress
and the qTranslate
plugin to acheive a multi-language property site. I'm calling some hardcoded values in a custom way, as there's no default way in the theme to allow qTranslate in the labels.
So currently I've got:
<?php if(get_post_meta($post->ID,'property_pool',true) && $property_pool): ?>
<li>
<p><?php echo PROP_POOL_CSTM;?>:</p><p> <?php echo get_post_meta($post->ID,'property_pool',true);?></p>
</li>
<?php endif; ?>
Only problem is, 'property_pool' value is also coming in 1 language. I need to be able to modify the outcome directly on this page. If it's Yes, replace it with <!--:en-->Yes<!--:--><!--:es-->Si<!--:--><!--:ru-->да<!--:-->
, and if it's No, replace it with <!--:en-->No<!--:--><!--:es-->No<!--:--><!--:ru-->нет<!--:-->
.
I've looked a few things up, like str_replace
but I'm a total beginner and have no idea how I can incorporate this into an existing function.
As you've described it, this should work
<?php if(get_post_meta($post->ID,'property_pool',true) && $property_pool):
$property_pool_meta = get_post_meta($post->ID,'property_pool',true);
if ($property_pool_meta == 'Yes') {
$property_pool_meta = '<!--:en-->Yes<!--:--><!--:es-->Si<!--:--><!--:ru-->да<!--:-->';
}
elseif ($property_pool_meta == 'No') {
$property_pool_meta = '<!--:en-->No<!--:--><!--:es-->No<!--:--><!--:ru-->нет<!--:-->';
} ?>
<li>
<p><?php echo PROP_POOL_CSTM;?>:</p><p> <?php echo $property_pool_meta; ?></p>
</li>
<?php endif; ?>
My only concern would be that that wouldn't be processed by qTranslate. To get qTranslate to process it, I'd replace
<?php echo $property_pool_meta; ?
with
<?php _e( $property_pool_meta ); ?>
qTranslate hooks into the __()
and _e()
functions.
Edit
If you have lots of values, you might be better off doing something like this (I haven't tested it, so there might be a syntax error or two in there):
<?php
$property_pool_map = array(
'Yes' => '<!--:en-->Yes<!--:--><!--:es-->Si<!--:--><!--:ru-->да<!--:-->',
'No' => '<!--:en-->No<!--:--><!--:es-->No<!--:--><!--:ru-->нет<!--:-->'
);
if(get_post_meta($post->ID,'property_pool',true) && $property_pool):
$property_pool_meta = get_post_meta($post->ID,'property_pool',true);
if (isset($property_pool_map[$property_pool_meta])) {
$property_pool_meta = $property_pool_map[$property_pool_meta];
} ?>
<li>
<p><?php echo PROP_POOL_CSTM;?>:</p><p> <?php echo $property_pool_meta; ?></p>
</li>
<?php endif; ?>