By: Pseudoclass
There are plenty of ways to configure a full multilingual site in EE using modules like Transcribe, Publisher, and Structure however, there are times when you may only need small portions of a site in multiple languages, and it does not warrant a full multilingual framework.
Babeltext is a multilingual text entry fieldtype which will allow you to configure a multiple language text input for a single piece of text in an entry.
- Configure multiple languages for one piece of text. Set the order in which you would like the language tabs to appear on the entry form by dragging them up and down in the list.
- Use regular text inputs, text areas, or the native ExpressionEngine Rich Text Editor.
- Mark specific languages as required. If the custom field is set as required validation will fail unless the required language fields have text.
- Set language direction for each language.
- The template tag can take an optional "language" parameter to output the language specific version of the text. If no language is indicated or it is set to "dynamic" Babeltext will look in the URL string for a language code (i.e.; http://example.com/es/ for spanish), and output the language specific version that way.
- ExpressionEngine 2.5.3 and above
- Native Rich Text Editor installed (If you wish to use it as a content type)
- Upload the system/expressionengine/third_party/babeltext/ folder to your system/expressionengine/third_party/ folder.
- Upload the themes/third_party/babeltext/ folder to your themes/third_party/ folder
- Go to Addons > Fieldtypes in your Control Panel and click Install to install the Babeltext fieldtype
- Create a new custom field for your channel and select its type as "Babeltext"
- In the field options select the type of field you wish to use (Text Input, Textarea or Rich Text Editor)
- In the languages table select a language you wish to add from the dropdown and then press "Add" to add it to the table.
- To change the order in which the language tabs appear in the entry form, click and drag the languages in the table up and down.
- If the custom field is set to required, you must check at least one of the languages in the table as required via the checkboxes.
Use the custom fieldtype short name to output your content as normal. Here's a sample:
{exp:channel:entries channel="channel_name"}
<!-- Call the field directly --->
<h3>{custom_field_name language="es"}</h3>
{/exp:channel entries}
- language : Set this to the two letter ISO language code of the language you wish to output. You could use a global variable in this case to set it dynamically (i.e.; {custom_field_name language="{lang_code}"}). If no language is set or the parameter is set to the default "dynamic", the Babeltext field will attempt to find the language code within the current URL structure (i.e.; http://example.com/de/ - displays the German version of the text). If the language was not set in the Babeltext field or none can be found, the tag will output the contents of the first language you configured in the list as a default.
Use the custom fieldtype short name as a tag pair to output the data in multiple languages in a loop. Here's a sample:
{exp:channel:entries channel="channel_name"}
<!-- Use the field name as a tag pair --->
{custom_field_name language="es|fr|en"}
<!-- Single variables available for each language in the loop -->
<div lang="{bt_id}">
<h3>{bt_name}</h3>
<p>{bt_content}</p>
</div>
{/custom_field_name}
{/exp:channel entries}
- language : A pipe delimited list of two letter ISO language codes in the order you wish the language data to appear. If left blank or set to "dynamic" the tag pair will output the content based on the URL or the default just as the single tag does.
These variables are available within the tag pair:
- bt_id : The two letter ISO language code of the language (i.e.; "en", "es", etc)
- bt_name : The name of the language (i.e.; "English", "Spanish", etc)
- bt_content : The content for the language
My initial plan is to release this fieldtype as a Beta to the EE Community to see if other EE Devs find it useful. If there is enough interest generated, I plan on working out the kinks, offering it on Devot:ee, and adding the following improvements:
General Code CleanupSupport for Native EE Rich Text EditorTag pair to output language texts in a loopChannel data updates on removing languages- Caching and performance tweaks
- Support for SafeCracker
- Support for Low Variables
- Support for Matrix and Wygwam
- Support for Better Workflow
- Any suggestions you may have are welcome... Hit me up on Twitter
- Initial working beta
- Added better Rich Text Editor Integration. Now checks for installation of the RTE and loads the users toolset or the default.
- Added number of rows input for textareas and Rich Text Editor input types, for height control in the entry form.
- Added Tag Pair option allowing you to loop though multiple languages as specified in the "language" tag parameter.
- Cleaned up code to match the EE coding style guidelines
- Added cleanup functionality to entry data when a language is removed or added in the field's settings. Now if an existing Babeltext field's languages are edited in the field's settings, Babeltext goes through all entries that use the field and updates the entry data to reflect the changes (i.e.; removing a language will remove that languages contents in the entry data).
- Fixed PHP errors when no language parameter was set on tag pairs
- Fixed PHP errors when the language parameter contains a language ID that is not set for the field. Now just returns empty strings.
- Bug Fix for PHP error in EE 2.6.1 on setting up Babeltext for the first time.
- Bug Fix for Native RTE fieldtype passing blank fields as valid due to RTE's use of Unicode zero space characters.