开发者

Internationalion not working with PHP variable (Wordpress)?

What it basically does is to let the user input text in a field and that text will be displayed in h1 tags. The values is stored in the logo_text PHP variable:

<?php echo get_option(THEME_PREFIX . 'logo_image'); ?>

In order to internationalise it, I tried the following:

<?php echo get_option(__(THEME_PREFIX . 'logo_image') ); ?>

But the string wasn't shown in WPML's string translation panel.

Any suggestions?

header.php:

<h1>
        <?php if (get_option(THEME_PREFIX . "logo_image_enabled")) { ?>
             <img src="<?php bloginfo('template_directory'); ?>/images/<?php echo get_option(THEME_PREFIX . 'logo_image'); ?>" />
        <?php } else { ?>
            <h1><a href="<?php bloginfo('url'); ?>"><?php echo get_option(THEME_PREFIX . "logo_text"); ?></a></h1>
        <?php } ?>
    </h1>

custom-logo.php:

<?php
    $option_fields[] = $logo_image = THEME_PREFIX . "logo_image";
    $option_fields[] = $logo_image_enabled = THEME_PREFIX . "logo_image_enabled";
    $option_fields[] = $logo_text = THEME_PREFIX . "logo_text";

?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/ajaxupload.3.5.js" ></script>
<script type="text/javascript" >
    $(function(){
        var btnUpload=$('#upload');
        var status=$('#logo-upload-status');
        new AjaxUpload(btnUpload, {
            action: '<?php bloginfo('template_directory'); ?>/upload-file.php',
            name: 'uploadfile',
            onSubmit: function(file, ext){
                 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
                    // extension is not allowed
                    status.text('Only JPG, PNG or GIF files are allowed');
                    return false;
                }
                status.text('Uploading...');
            },
            onComplete: function(file, response){
                //On completion clear the status
                status.text('');
                //Add uploaded file to list
                if(response==="success"){
                    $('<li></li>').appendTo('#files').html('<img src="<?php bloginfo('template_directory'); ?>/images/'+file+'" alt="" /><br />'+file).addClass('success');
                    $('#<?php echo $logo_image; ?>').val(file);
                } else{
                    $('<li></li>').appendTo('#files').text(file).addClass('error');
                }
            }
        });

    });
</script>

<div class="postbox">
    <h3>Logo Customization Options</h3>

    <div class="postbox-content">

        <div class="option-row">
            <p>Choose how you would like to display your logo.</p>
        </div><!--end option-row-->

        <div class="option-row">
            <div class="option-name">
                <label>Use Image For Logo</label>
            </div><!--end option-name-->
            <div class="option-value">
                <input class="checkbox" id="<?php echo $logo_image_enabled; ?>" type="checkbox" name="<?php echo $logo_image_enabled; ?>" value="true"<?php checked(TRUE, (bool) get_option($logo_image_enabled)); ?> />
            </div><!--end option-value-->
        </div><!--end option-row-->

        <div class="option-row">
            <div class="option-name">
                <label>Upload An Image</label>
                <span id="logo-upload-status"></span>
       开发者_开发问答     </div><!--end option-name-->
            <div class="option-value">
                <input class="logo-name" id="<?php echo $logo_image; ?>" type="text" name="<?php echo $logo_image; ?>" value="<?php echo get_option($logo_image); ?>" />
                <input type="button" class="background_pattern_button" id="upload" value="Choose Logo" />

            </div><!--end option-value-->
        </div><!--end option-row-->

        <div class="option-row">
            <div class="option-name">
                <label>Logo Text</label>
            </div><!--end option-name-->
            <div class="option-value">
                <input class="input-box" id="<?php echo $logo_text; ?>" type="text" name="<?php echo $logo_text; ?>" value="<?php echo get_option($logo_text) ?>" />
            </div><!--end option-value-->
        </div><!--end option-row-->

        <input type="submit" class="button" value="Save Changes" />

    </div>

</div><!--end postbox-->


WPML cannot resolve dynamic data inside GetText calls.

Since your 'THEME_PREFIX' doesn't change, all you need to do is translate the 2nd part of the argument and it should work:

  • Make sure to replace THEME_TEXTDOMAIN with your theme's textdomain value.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜