Welcome Tour
Site Checklist
Our Story




The translate command/function allows you to tap into BoltWire's small translation engine, and translate phrases in language packs you have installed.

Language packs are simply pages in your site like or They can be downloaded from the extensions? area. To install one, copy the file into your local/pages folder to make them available to one site. Move it into boltwire/system to make it available on all your sites.

The Translate Function

To use it, you must have at least one language file installed. A language file has a name like or These pages contain lines like the following:

hello :: bonjour
goodbye :: au revoir
yes :: oui
no :: non
name :: nom
date :: date
print :: imprimer
edit :: modifier
return :: revenir

To use the language function simply supply it a string of text (parameter 1) and set the language parameter (defaults to parameter 2):

[(translate hello fr)] => bonjour

It also works in reverse:

[(translate 'au revoir' fr reverse=true)] => good bye

If you enter a phrase or language BoltWire cannot find, the text is returned unchanged.

Note: This function attempts to match the capitalization of the original text. That is "HELLO" will return "BONJOUR" and "Good Bye" will return "Au Revoir". It also recognizes lower case and the single first letter capitalized. Anything more complicated will return all lower case regardless of the original capitalization.

The Translation Command

Commands work the same way. Consider this simple form:

Translate: [text content] [submit]
[command translate {=content} fr]
[command passdata]

The user enters a word or phrase and hits submit. BoltWire tries to translate it using the fr language file, and passes the results back to the page through passdata. It is then caught by the GET variable and displayed.

If a match is not found in the translation page, the English version is retained (and in this case returned).

The translation engine tries to keep the same capitalization as the original phrase, though it is not always able to do this perfectly. YES is returned OUI, Yes is returned Oui. yes is returned oui.

Another Example

Suppose you want to translate a bit of text into a language chosen by your user. Consider this script:

[(search group=site.language fmt='[radio lang {+page}] <(source {+p}:title)>')]
[command passdata lang]
<(translate hello {?lang})>

This form generates a list of options from all the available language files and then passes the choice selected by the user back to the page. The GET variable is then used to set the translation language in the translate function.

New Language Packs

You can create additional language files for any language you want and modify existing packs to include any additional phrases you want.

To create a new language pack go to site.language.template and copy it to site.language.newname. Add the foreign language equivalents and save. To activate the new language file, set language: newname on site.config.

To add new phrases to a language file simply add them using the same format. Follow the format of the replacement table carefully. You can put complete phrases on either side of the " :: " separator, including spaces and punctuation. You cannot have line breaks. The dashboard module? has a special plugin for automating the translation process using google translate.

If you create a new or improved language file, please share it back with the BoltWire community.

Using Translations

The translation engine extends far beyond this function. Suppose you installed a french language file ( and wanted to run a French site. Go to site.config and set language: fr. Immediately, BoltWire begins trying to translate all of the following:

1) form buttons with a match
2) link labels with a match
3) system messages
4) headers (using the ! markups)

You can also mark a phrase for translation by wrapping it like this: ++some text++. The wrapper will not show up in your output, even if no match is found.

In addition all commands, functions, and conditionals get reverse translated. That is, you can write the fr word "modifier" as a command, and it will work as if you wrote the English word "edit". You can of course, still use the English version as long as it does not get translated into something BoltWire doesn't understand. :)

With a good translation file, you can get key parts of your site translated fairly quickly. BoltWire has full UTF-8 support for full internationalizations.

Dynamic Translations

Suppose you want to allow your users to choose their own language as a preference and have BoltWire remember it. Add the following line of code to config.php:

$BOLTlanguage = BOLTvars("member.$BOLTid:language");

Then simply create a form that saves their language preference as a data field on their member page. As soon as they login, everything possible is instantly translated. You could use an info page, or even link the language to the group they are in.