如何在WordPress中添加新的语言字符串?

时间:2015-03-05 17:25:24

标签: php string wordpress translation language-translation

基本上我想在此网站中更改“上一个工作”和“下一个工作”的“上一篇文章”和“下一篇文章”:http://fontaneriaborja.com/en/portfolio-view/solar-panels-swimming-pool/

我已经进入/wp-content/themes/CherryFramework/loop/loop-single-portfolio.php并找到了这段代码:

<!--BEGIN .pager .single-pager -->
        <ul class="pager single-pager">
        <?php if (get_previous_post()) : ?>
            <li class="previous"><?php previous_post_link('%link', theme_locals("prev_post")) ?>
        <?php endif; ?>

        <?php if (get_next_post()) : ?>
            <li class="next"><?php next_post_link('%link', theme_locals("next_post")) ?>
        <?php endif; ?>
<!--END .pager .single-pager -->

我相信theme_locals(“prev_post”)和theme_locals(“next_post”)是调用文本的字符串。

理想情况下,我想要做的是更改并添加一个新字符串,例如theme_locals(“prev_work”)和theme_locals(“next_work”),这将为我的.po文件生成两个新的翻译。但是,我在这里被困住了。

这是一个使用Polylang的多语言WordPress 4.1.1网站,以及来自Template Monster和Cherry插件的主题。

我已经四处搜索,没有运气,无法理解这是如何工作的。所以任何帮助都会非常感激。

感谢您的时间,并感谢您们所有人。

最佳

P.S。:我是网络开发的初学者。 P.2.2:我也在https://wordpress.org/support/topic/add-language-string-in-wordpress上发布了这个内容,如果找到解决方案,我会尝试更新这两个地方。

POST EDIT:

根据danbahrami的建议,我在/wp-content/themes/CherryFramework/includes/locals.php中找到了一个带有'theme_local_init()'函数的php文件。这是代码的一部分,我没有把它全部放在一边因为很长:

<?php
function theme_local_init() {
    global $is_cherry_local_init, $cherry_locals_arr;
    if ($is_cherry_local_init) return true;

    $domain = CURRENT_THEME;
    $cherry_locals_arr = array(
        //general
        'no' => __('No', 'cherry'),
        'yes' => __('Yes', $domain),
        'slow_speed' => __('Slow', $domain),
        'normal_speed' => __('Normal', $domain),
        'fast_speed' => __('Fast', $domain),
        'normal_size' => __('Normal size', $domain),
        'large_size' => __('Large size', $domain),
        'font_size' => __('Font Size', $domain),
        'lineheight' => __('Lineheight', $domain),
        'font_face' => __('Font Face', $domain),
        'character_sets' => __('Character Sets', $domain),
        'font_style' => __('Font Style', $domain),
        'color' => __('Color', $domain),
        'import' => __('Import', $domain),
        'export' => __('Export', $domain),
        'done' => __('Done', $domain),
        'error' => __('Error', $domain),
        'success' => __('success', $domain),
        'upload' => __('Upload', $domain),
        'try_again' => __('try again', $domain),
        'finish' => __('Finish', $domain),
        'skip' => __('Skip this step', $domain),
        'install_next' => __('next', $domain),
        'none' => __('None', $domain),
        'date' => __('Date', $domain),
        'title' => __('Title', $domain),
        'info' => __('Info', $domain),
        'rand' => __('Random', $domain),
        'comment_count' => __('Comment count', $domain),
        'enable_lightbox' => __('Enable Lightbox', $domain),
        'enable_lightbox_desc' => __('Check this to enable the lightbox.', $domain),
        'permalink_to' => __('Permalink', $domain),
        'read_more' => __('Read more', $domain),
        'view_all' => __('View all', $domain),
        'width' => __('Width', $domain),
        'height' => __('Height', $domain),
        'excerpt_length' => __('Excerpt length (words):', $domain),
        'link_text' => __('Link Text:', $domain),
        'link_url' => __('Link URL', $domain),
        'standard' => __('Standard', $domain),
        'aside' => __('Aside', $domain),
        'quote' => __('Quote', $domain),
        'link' => __('Link', $domain),
        'image' => __('Image', $domain),
        'gallery' => __('Gallery', $domain),
        'audio' => __('Audio', $domain),
        'video' => __('Video', $domain),
        'categories' => __('Categories', $domain),
        'tags' => __('Tags', $domain),
        'show_all' => __('Show All', $domain),
        'search' => __('search', $domain),
        'go' => __('Go', $domain),
        'prev_post' => __('&laquo; Previous post', $domain),
        'next_post' => __('Next Post &raquo;', $domain),

我相信最后两行是有问题的,但还有更多的代码。

1 个答案:

答案 0 :(得分:1)

您需要做的就是更改theme_local_init功能的最后两行...

'prev_post' => __('&laquo; Previous post', $domain),
'next_post' => __('Next Post &raquo;', $domain),

为...

'prev_post' => __('&laquo; Previous work', $domain),
'next_post' => __('Next work &raquo;', $domain),

如果您有兴趣了解wordpress如何处理翻译,请阅读The i18n page in the Wordpress codex。它可以帮助您了解主题的工作原理。

更新:或者如果您只想在某些情况下更改文字,可以在功能中添加更多行,例如

'prev_work' => __('&laquo; Previous work', $domain),
'next_work' => __('Next work &raquo;', $domain),

然后更改模板中的post_link功能,改为使用prev_worknext_work

然后,下次生成PO文件时,将添加新的可翻译字符串。

希望有所帮助