Author: rogersennert_sz793679

Typo3 Localize your own extensions

When you try to write your own front end (FE) extensions with Typo3 there are common pitfalls. First of all be sure you enabled your table to hold the information. (Can be done very easy via the kickstarter). Next be sure you don’t query do much information of your table. All you need are the row where „sys_language_uid=0″. Your translation is made via the getRecordOverlay ! This short code snippet may help you to resolve your problems:

[sourcecode lang=“php“]
function readDBData( $table, $where )
{
$back = array();

if ( $where!=““ )
$where.= “ AND „;
$where .= “ deleted=0 AND hidden = 0 AND sys_language_uid=0″;

$res = $GLOBALS[‚TYPO3_DB‘]->exec_SELECTquery( ‚*‘, $table, $where );
while ($row = $GLOBALS[‚TYPO3_DB‘]->sql_fetch_assoc($res))
{
if ($GLOBALS[‚TSFE‘]->sys_language_content)
{
$OLmode = ($this->sys_language_mode == ’strict‘?’hideNonTranslated‘:“);
$row = $GLOBALS[‚TSFE‘]->sys_page->getRecordOverlay( $table, $row, $GLOBALS[‚TSFE‘]->sys_language_content, $OLmode);
}
$back[] = $row;
}

return $back;
}
[/sourcecode]

PS: Keep in mind this tip, too: Web List: ‚Localize-to-feature‘

Typo3 RealURL and 404 file not found

When using RealURL in multi language environment sending an real 404 is sometimes not so easy. Some I just want to give you some hints:

First of all enable the pageNotFound_handling of Typo3.

  • open the file typo3conf/localconf.php
  • add these lines

    $TYPO3_CONF_VARS["FE"]["pageNotFound_handling"] = 'http://www.my-domain.com/en/not-found.html';
    $TYPO3_CONF_VARS["FE"]["pageNotFound_handling_statheader"] = 'HTTP/1.1 404 Not Found';

Now you need to check your RealURL config:

  • Be sure you that you have not set postVarSet_failureMode OR set it to postVarSet_failureMode=''
  • Also be sure you have defined 'noMatch'=>'bypass' for every single preVars section!

That’s all 🙂 Now you get the your wonderful 404 file not found page every time when a wrong page is hit.

Typo3 Using typoLink in your own FrontEnd (FE) extension

Using the the typoLink function in your own Typo3 extension is very simple. First you need an instance of the tslib_cObj object. Then setup the config array and call the method. That’s all.
To create the instance you need to include the object first:

include_once(PATH_site.'typo3/sysext/cms/tslib/class.tslib_content.php');

Then create the tslib_cObj:

$cObj=t3lib_div::makeInstance('tslib_cObj');

Setup the config array: (See the typoLink documentation of possible entries)

$conf = array( 'parameter' => 'http://www.bstar.de' );

Call the method:

echo $cObj->typoLink('bstar.de', $conf );


If you don’t want to setup the conf array and don’t need the power of typoLink you can use getTypoLink also:

echo $cObj->getTypoLink('bstar.de', 'http://www.bstar.de' );

Cron sends no mail to MAILTO address

When you are using cron to do some automatic jobs and want the output to be mailed, be sure you are entering the mail address in the right format. In this case it means that the mail address must not contain an „_“ (underscore)! If you enter into the MAILTO env of the crontab a mail address which contains an underscore you’ll wait forever 😉
Of course this behavior depends of your cron version …

So don’t use an underscore when ever you are able to do.

Typo3 locallang.xml and UTF-8 II

Again I need to talk about the default section of the locallang.xml. When you are following the tip of my last post you may encounter an other problem. You don’t have a default anymore (yeah! I know I suggest to remove the default section). This is may a problem if you need to handle many languages and don’t had translate all of them right now.
So here comes my bad work-around.

  1. open ../t3lib/class.t3lib_div.php in an editor
  2. search for:
    $LOCAL_LANG['default'][$labelKey] = $csConvObj->utf8_decode($labelValue,'iso-8859-1');
  3. replace 'iso-8859-1' with $origCharset
  4. save the file
  5. you may need to clear you llxml cache

Now you can use the default section again and UTF-8 characters are working fine.

Typo3 output UTF-8 in your own extensions

After you had finally master your the utf8 convert of you Typ3 installation may encounter an other problem. Your own extension is not producing utf8 output.
Your first idea will be to add "SET NAMES UTF8;" to you database connection when using the DBAL of Typo3. But this is not your problem 😉 $GLOBALS['TYPO3_DB']->exec_SELECTquery (which is actually using the DBAL) gives your right want you want!

After a while you’ll may find out that you’ve used for some reasons htmlentities. And this is your problem! But don’t panic. You just need to added some more parameters and the world will be fine again. Just add ‚UTF-8‘ as third parameter to give the function a hint that you are using uft8. Tricky … isn’t it 😉

So it will look similar like this:
$str = htmlentities( $dbData, ENT_COMPAT, 'UTF-8' );

Typo3 locallang.xml and UTF-8

Building a multi language site can be very hard. First of all you need be sure that you are running Typo3 and your database with the correct encoding. UTF-8 is your friend! Apply all the setting you need for you installation (have a look at http://wiki.typo3.org/index.php/UTF-8_support will may help you) and also ensure your database is using UTF-8. (BTW: If you database tables are using UFT-8 you do NOT need to set $TYPO3_CONF_VARS[‚SYS‘][‚multiplyDBfieldSize‘] and do not forget to run database->compare of the installation tool)

Now your Typo3 installation is working fine. Really? Have you checked your own extensions? Ups! There is may a problem if you use getLL and locallang.xml. Some chars are may mess up even if the locallang.xml looks fine (of course you are using an UTF-8 enabled editor and you are saving this file as UTF-8).

The problem is the „default“ languageKey setting. You are not allowed to use any encoding then ansi. But what if you need some special chars there? Be sure you set an other default key (for example „config.language = en“ will do this job for english) and rename „default“ to „en“. Now you are fine!