admin管理员组文章数量:1336340
I currently have a website that some of it's content is hardcoded: Let's say, the navbar isn't editable from the WP dashboard, and some of the content throughout the page.
I found very useful a few plugins that give me the ability to translate content that is editable from the dashboard, like posts, pages. etc.
However as far as I know they won't translate the hardcoded content.
Is there a way to achieve this functionality? Or do I have to figure it out how to make all the content editable and accessible from the dashboard?
I currently have a website that some of it's content is hardcoded: Let's say, the navbar isn't editable from the WP dashboard, and some of the content throughout the page.
I found very useful a few plugins that give me the ability to translate content that is editable from the dashboard, like posts, pages. etc.
However as far as I know they won't translate the hardcoded content.
Is there a way to achieve this functionality? Or do I have to figure it out how to make all the content editable and accessible from the dashboard?
Share Improve this question asked Jun 8, 2020 at 19:10 Andres UrdanetaAndres Urdaneta 1011 Answer
Reset to default 0So it depends, one 2 things:
- hardcoded HTML tags containing spanish text
- i18n api text, e.g.
echo __( 'string', 'textdomain' );
You want the latter, but the theme author may not have used that API
Hardcoded HTML tags
This is when the text is hardcoded in the file, e.g.
<p>spanish text</p>
<?php echo "spanish text"; ?>
There are 2 options here, and one of them is awful for performance:
- Create a child theme and replace the templates that have hardcoded text with i18n api calls ( choose this option )
- Use an output buffer to prevent anything being sent, then search replace it at the end ( avoid!!!! this is the bad option! )
For maximum flexibility, and compatibility with translation plugins, use the i18n translation APIs.
Note that the output buffer approach will cripple the time to first byte metric and induce performance hits and SEO penalties. It also won't change the language of the page when using plugin language switchers, but I've included it for completeness.
i18n and the Official internationalisation/localisation API
The translation API lets you specify the default string, and a textdomain, then you can tell WP about this and where your theme stores translation files containing these strings but in other languages. This data is stored as mo
/po
/pot
files, and it's how vanilla WordPress translates its APIs.
Note that this API cannot be used for dynamic content from the database or other external sources, it's for static strings only. That's what plugins are for.
There are a number of these APIs but the most basic one is __( 'static string', 'textdomain' );
.
For specifics on how to translate a theme, I recommend the dedicated chapters in the theme and plugin handbooks:
- https://developer.wordpress/themes/functionality/internationalization/
- https://developer.wordpress/themes/functionality/localization/
These will teach you how to enable localisation of your theme/plugin, and how to then use that to create language files. Your plugins should automatically switch between these once the support is added.
本文标签: pluginsHow to translate to spanish wordpress hardcoded contentfiles
版权声明:本文标题:plugins - How to translate to spanish wordpress hardcoded contentfiles? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742366702a2461430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论