如何在 WordPress 中添加新的语言字符串?
How to add a new language string in WordPress?
基本上我想在这个站点中为 "Previous Work" 和 "Next work" 更改单词 "Previous post" 和 "Next Post":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 网站,主题来自带有 cherry 插件的 Template Monster。
我已经四处搜索,但没能理解这是如何工作的。因此,我们将不胜感激任何帮助。
感谢您的宝贵时间,并提前感谢大家。
最佳
P.S.: 我是网络开发的初学者。
P.S.2:我也在 https://wordpress.org/support/topic/add-language-string-in-wordpress 上发布了这个,如果我找到解决方案,我会尽量更新这两个地方。
POST 编辑:
根据 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' => __('« Previous post', $domain),
'next_post' => __('Next Post »', $domain),
我相信最后两行是有问题的,但还有更多代码。
您需要做的就是将 theme_local_init
函数的最后两行从...
'prev_post' => __('« Previous post', $domain),
'next_post' => __('Next Post »', $domain),
到...
'prev_post' => __('« Previous work', $domain),
'next_post' => __('Next work »', $domain),
如果您有兴趣了解有关 wordpress 如何处理翻译的更多信息,您应该阅读 The i18n page in the Wordpress codex。它可以帮助您了解主题的工作原理。
更新: 或者如果您只想在某些情况下更改文本,您可以在函数中添加更多行,例如
'prev_work' => __('« Previous work', $domain),
'next_work' => __('Next work »', $domain),
然后更改模板中的 post_link
函数,改为使用 prev_work
和 next_work
。
然后在您下次生成 PO 文件时,将添加新的可翻译字符串。
希望对您有所帮助
段
基本上我想在这个站点中为 "Previous Work" 和 "Next work" 更改单词 "Previous post" 和 "Next Post":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 网站,主题来自带有 cherry 插件的 Template Monster。
我已经四处搜索,但没能理解这是如何工作的。因此,我们将不胜感激任何帮助。
感谢您的宝贵时间,并提前感谢大家。
最佳
P.S.: 我是网络开发的初学者。 P.S.2:我也在 https://wordpress.org/support/topic/add-language-string-in-wordpress 上发布了这个,如果我找到解决方案,我会尽量更新这两个地方。
POST 编辑:
根据 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' => __('« Previous post', $domain),
'next_post' => __('Next Post »', $domain),
我相信最后两行是有问题的,但还有更多代码。
您需要做的就是将 theme_local_init
函数的最后两行从...
'prev_post' => __('« Previous post', $domain),
'next_post' => __('Next Post »', $domain),
到...
'prev_post' => __('« Previous work', $domain),
'next_post' => __('Next work »', $domain),
如果您有兴趣了解有关 wordpress 如何处理翻译的更多信息,您应该阅读 The i18n page in the Wordpress codex。它可以帮助您了解主题的工作原理。
更新: 或者如果您只想在某些情况下更改文本,您可以在函数中添加更多行,例如
'prev_work' => __('« Previous work', $domain),
'next_work' => __('Next work »', $domain),
然后更改模板中的 post_link
函数,改为使用 prev_work
和 next_work
。
然后在您下次生成 PO 文件时,将添加新的可翻译字符串。
希望对您有所帮助
段