Project

General

Profile

Actions

Feature #39597

closed

Multiple locale names for TS config.locale_all

Added by Sven Tappert over 11 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
TypoScript
Target version:
Start date:
2012-08-07
Due date:
% Done:

100%

Estimated time:
1.00 h
PHP Version:
Tags:
Complexity:
easy
Sprint Focus:

Description

PHP setlocale() supports multiple locale names as fallback. This is not yet supported for the TypoScript config value "config.locale_all".

Affected are all Typo3 versions at least until the 7th of August 2012 (4.5.17, 4.6.10 4.7.2 6.0.0alpha3).

E.g.:

// Works in PHP since version 4.3.0
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
setlocale(LC_ALL, array('de_DE@euro', 'de_DE', 'deu_deu'));

# this will fail in TS-Setup
config.locale_all = de_DE@euro, de_DE, deu_deu

Possible solution (working, but not examined completely (especially the workaround for turkish locales)):
Function tslib_fe::settingLocale() could use t3lib_div::trimExplode() to support multiple values for setlocale().

function settingLocale()    {

        // Setting locale
    if ($this->config['config']['locale_all'])    {
        # Change by René Fritz, 22/10 2002
        # there's a problem that PHP parses float values in scripts wrong if the locale LC_NUMERIC is set to something with a comma as decimal point
        # this does not work in php 4.2.3
        #setlocale('LC_ALL',$this->config['config']['locale_all']);
        #setlocale('LC_NUMERIC','en_US');

        # so we set all except LC_NUMERIC

        // Support multiple names for setlocale
        $locale = t3lib_div::trimExplode(',', $this->config['config']['locale_all']);
        $locale = setlocale(LC_COLLATE, $locale);

        if ($locale) {

                // PHP fatals with uppercase I characters in method names with turkish locale LC_CTYPE
                // Seems to be fixed in PHP 5.4.5 (19-Jul-2012) 
                // @see http://bugs.php.net/bug.php?id=18556
            if ((version_compare(PHP_VERSION, '5.4.5') >= 0) || substr($locale, 0, 2) != 'tr' && substr($locale, 0, 7) != 'Turkish') {
                setlocale(LC_CTYPE, $locale);
            }

            setlocale(LC_MONETARY, $locale);
            setlocale(LC_TIME, $locale);

            $this->localeCharset = $this->csConvObj->get_locale_charset($locale);
        } else {
            $GLOBALS['TT']->setTSlogMessage('Locale "'.htmlspecialchars($this->config['config']['locale_all']).'" not found.', 3);
        }
    }
}

Maybe the mentioned problems concerning LC_ALL & LC_NUMERIC are solved, so the function could be completely refactored.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #29386: L10n: locales dependency is not taken into accountClosedXavier Perseguers2011-08-31

Actions
Actions #1

Updated by Jeff Segars over 11 years ago

  • Status changed from New to Needs Feedback

Sven,
I'm not the right person to give any final opinions on this on anything localization related in TYPO3 since I'm an American guy who almost always builds in English. I do wonder if there's some overlap with #29386 though. In that issue, a feature was added for locale fallback and extension labels. I wonder if the same fallback should actually be used here too.

Xavier,
I'm adding you as a follower since you were involved in the locale fallback for labels. What do you think?

Thanks,
Jeff

Actions #2

Updated by Markus Klein over 11 years ago

Hi Sven,

I'm not entirely sure, what you try to achieve with this?
Usually you should be able to figure out, which locales are supported on the server where you install TYPO3.

Actions #3

Updated by Sven Tappert over 11 years ago

Jeff Segars wrote:

I do wonder if there's some overlap with #29386 though. In that issue, a feature was added for locale fallback and extension labels. I wonder if the same fallback should actually be used here too.

Jeff,
thank you for the hint, but as far as I understand, it seems to be a different issue. The change I suggest doesn't relate to the Typo3 localization features, but more basically to php functions like strftime (e.g. when echoing the name of a weekday or a month). The translation is built into php and relies on the right locale to be set.

Markus Klein wrote:

I'm not entirely sure, what you try to achieve with this?
Usually you should be able to figure out, which locales are supported on the server where you install TYPO3.

Hi Markus,
your right, it's just for convenience and easier portability. I was just wondering, because I expected the locale_all setting to behave equivalent to the setlocale(LC_ALL, ..) function. Probably the feature was just never updated in Typo3, when it was added to php 4.3?

I think it's just nice to have it all in one line, working with all projects, without using conditions or the need to adapt it to each system when dragging the installation from development to production. Furthermore it might stay unnoticed for a long time when the setting of the locale failed. But of course, no must-have!

Actions #4

Updated by Alexander Opitz over 10 years ago

Hi,

as this issue is very old. Does the problem still exists within newer versions of TYPO3 CMS (6.1)?

Actions #5

Updated by Sven Tappert over 10 years ago

Yes, the issue still exists in 6.1

# not accepted, but should be to support seamless switch between different operating systems
config.locale_all = de_DE@euro, de_DE, deu_deu

In 6.1.2 it's located in \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController method "settingLocale()".

The config value should be converted to an array by trimExplode(). This array has to be passed to the native PHP function setlocale() (instead of the pure string).

setlocale() returns the accepted locale. So the return value $locale has be used after the first call to setlocale()
(instead of $this->config['config']['locale_all']).

The solution posted above still applies
(t3lib_div::trimExplode() has been moved to \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode()).

See: http://www.php.net/manual/en/function.setlocale.php

Note:
The special handling of turkish locales still works (and is still needed until PHP 5.5). It might be extended to check $locale against 'turkish' additionally, since this seems to be a valid turkish locale on some systems.

Actions #6

Updated by Alexander Opitz over 10 years ago

  • Status changed from Needs Feedback to New
Actions #7

Updated by Mathias Schreiber about 9 years ago

  • Target version set to 7.2 (Frontend)
Actions #8

Updated by Benni Mack almost 9 years ago

  • Target version changed from 7.2 (Frontend) to 7.4 (Backend)
Actions #9

Updated by Susanne Moog over 8 years ago

  • Target version changed from 7.4 (Backend) to 7.5
Actions #10

Updated by Benni Mack over 8 years ago

  • Target version changed from 7.5 to 8 LTS
Actions #11

Updated by Gerrit Code Review almost 8 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/47458

Actions #12

Updated by Gerrit Code Review almost 8 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/47458

Actions #13

Updated by Benni Mack almost 8 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #14

Updated by Riccardo De Contardi over 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF