WordPress Translate Plugin
There are plenty of auto translate plugins, but they leave the content rigid with grammatical errors.
For those needing a solution to translate a WordPress site manually into unlimited languages or versions,
WP-Translate will do the job.
Using shortcodes, template tags, and a widget, you can easily create a site that will reflect appropriate content, images, links, and text for each language.
You can use simple shortcodes in your content, or customize your templates to change your entire site.
The beautiful thing is that you don't need to create multiple posts or pages for each language.
All content is filtered off one post or page.
To facilitate the process of translating themes, there is a dictionary of terms in the admin page.
The term translations may be retrieved with a shortcode or a template tag and make customization of elements such as forms or titles on the page very handy.
Usage
Adding languages and dictionary terms
Navigate to the `Translate' page in the admin panel under Plugins and use the input fields next to green plus icons to add terms and languages.
Note that a term may be added only after there is at least one language.
The default language may be selected by adding it twice.
Translate page titles
To translate a page title, add a custom field to the post or page with key = %language_name%_title and value = translated title. Note the _title after %language_name%.
Example:
- english_title = Football
- american_title = Soccer
This will translate the title of a page assuming english and american are two previously added languages.
Shortcodes
The supported shortcodes are listed below and can be placed anywhere in posts, pages and text-widgets to generate content.
Arguments enclosed in <> are mandatory (must be given) and those enclosed in [] are optional.
- [translate] Translated text [/translate]
Saves a translated version of a paragraph.
It is displayed when the activated language is the same as the one given in the lang= argument.
Arguments:
- <lang=%language_name%>
- [nodiv=1]
Examples:
- [translate lang=english] Hello World! [/translate][translate lang=russian] Привет Мир! [/translate]
- When called with the nodiv=1 argument (i.e [translate lang=english nodiv=1]text[/translate]) this shortcode will not put the contents in a <div class="translate_%language_name%"> element.
- [translations]
Gives an unordered list of available languages and activation links. The li elements are listed with attribute class set like this: class="list_item_%language_name%"
Arguments:
Examples:
- [translations flags=1] - lists flags associated with languages instead of their names.
- [list_pages]
Produces a list of pages which have the custom field %language_name%_title set for the currently activated language.
This tag lists pages whose titles have been translated in other words.
To exclude pages, simply delete the custom title field for that language on the specified page.
- [tseveral]
A quick way to translate something into several languages without repeating [translate][/translate].
Arguments:
Example:
- [tseveral english="Autumn" american="Fall" russian="Осень"]
- [tdict]
Fetch the translation of a predefined term.
Arguments:
Example:
Template Tags
Arguments may be suplied to the various functions as an associative array or as a plain string in other cases:
list_translations( array('flags' => '1') );
translate_term("homepage");
HOME - the URL of your homepage
TEMPLATEPATH - the URL of your template directory
- <?php list_translations(); ?> - see the [translations] shortcode.
- <?php translate_list_pages(); ?> - see the [list_pages] shortcode.
- <?php translate_link($parameters); ?>
- Parameters must be separated by the pipe symbol | .
- lang = language name
- link = http://www.wherever.com
- text = Link display text
- class = link style class (defaults to %language%_link)
- target = link target
- Example: <?php translate_link('lang=english| link=http://misternifty.com| text=Go to Mister Nifty| target=_blank') ?>
- <?php translate_text($parameters); ?>
- Parameters must be separated by the pipe symbol | .
- lang = language name
- text = Paragraph text
- class = link style class (defaults to %language%_text)
- target = link target
- p = yes/no (enclose text in a paragraph element)
- Example: <?php translate_text(‘lang=english| text=This paragraph will only display when English is selected.’) ?>
- <?php translate_image($parameters); ?>
- Parameters must be separated by the pipe symbol | .
- lang = language name
- src = image source
- link = URL if you want to link image.
- target = link target
- alt = text to show if image cant be displayed
- title = name of image
- class = link style class (defaults to %language%_image)
- Example: <?php translate_image(‘lang=english| src=TEMPLATEPATH/images/logo.png| link=HOME| title=My Logo| alt=My Logo ‘) ?>
- <?php translate_title(); ?>
- Replace the_title(); with translate_title(); in your loop and <title> tags.
- <?php echo translate_term($predefined_term); ?>
Please not that this and the next tag return a value instead of printing it.
This is done to make things like the folowing example easier.
<div id="search"> <?php $search = translate_term("search"); ?>
<form id="searchform" method="get" action="<?php bloginfo ('home'); ?>">
<input id="s" type="text" value="<?php echo $search; ?>" name="s"
onfocus="if (this.value == '<?php echo $search; ?>') {this.value = '';}"
onblur="if (this.value == '') {this.value = '<?php echo $search; ?>';}" />
</input>
</form>
</div>
You may create a new function to echo the value if you dislike this behaviour like so:
function tt($t){ echo translate_term($t); }
<?php echo translate_several("english=fag|american=smoke|norwegian=sigg"); ?>