Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension in the apache (intl) and i18n translations problem #11767

Closed
spiritdead opened this issue Jun 16, 2016 · 17 comments
Closed

extension in the apache (intl) and i18n translations problem #11767

spiritdead opened this issue Jun 16, 2016 · 17 comments

Comments

@spiritdead
Copy link

spiritdead commented Jun 16, 2016

What steps will reproduce the problem?

install the extension in the apache (intl) and translate this (i18n)

What is the expected result?

the translate result

Additional info

Formatting message for language 'es' failed with error: Message pattern is invalid: msgfmt_create: message formatter creation failed: U_ARGUMENT_TYPE_MISMATCH. The message being formatted was: {notificationCount} {notificationCount, plural, =1{New} other{News}}.

'{notificationCount} {notificationCount, plural, =1{New} other{News}}' => '{notificationCount} {notificationCount, plural, =1{New} other{News}}',
Q A
Yii version 2.0.8
PHP version 5.6.*
Operating system win / linux / centOS

i see this #1072

and i have passed in the requirements yii2 (is rare)

@spiritdead
Copy link
Author

@samdark well the error is a mayus, plz can add in the documentation this...
http://php.net/manual/en/timezones.php

@spiritdead
Copy link
Author

spiritdead commented Jun 16, 2016

but the i18n is broken hehe

Formatting message for language 'es' failed with error: Message pattern is invalid: msgfmt_create: message formatter creation failed: U_ARGUMENT_TYPE_MISMATCH. The message being formatted was: {notificationCount} {notificationCount, plural, =1{New} other{News}}.

'{notificationCount} {notificationCount, plural, =1{New} other{News}}' => '{notificationCount} {notificationCount, plural, =1{New} other{News}}',
public function format($message, $params, $language)
    {
        $params = (array) $params;
        if ($params === []) {
            return $message;
        }

        if (preg_match('~{\s*[\d\w]+\s*,~u', $message)) {
            $formatter = $this->getMessageFormatter();
            $result = $formatter->format($message, $params, $language);
            if ($result === false) {
                $errorMessage = $formatter->getErrorMessage();
                Yii::warning("Formatting message for language '$language' failed with error: $errorMessage. The message being formatted was: $message.", __METHOD__);

                return $message;
            } else {
                return $result;
            }
        }

        $p = [];
        foreach ($params as $name => $value) {
            $p['{' . $name . '}'] = $value;
        }

        return strtr($message, $p);
    }

@spiritdead spiritdead changed the title Invalid Configuration – yii\base\InvalidConfigException datefmt_create: no such time zone: 'Europe/madrid': U_ILLEGAL_ARGUMENT_ERROR extension in the apache (intl) and i18n translations problem Jun 16, 2016
@lynicidn
Copy link
Contributor

what is version intl ?

@lynicidn
Copy link
Contributor

lynicidn commented Jun 16, 2016

try change
{notificationCount, plural,
to
{notificationCount,plural,

@spiritdead
Copy link
Author

@lynicidn nothing change and the version is our current ICU version is 54.1.

@lynicidn
Copy link
Contributor

ah, try use
'{notificationCount, plural, =1{# New} other{# News}}'

@spiritdead
Copy link
Author

@lynicidn nothing :( but if i remove the extension intl work perfectly :S

@lynicidn
Copy link
Contributor

use # instead duplicate variable name

@spiritdead
Copy link
Author

work!

@spiritdead
Copy link
Author

but is rare if i have the {notificationCount} not work and when i remove this and add the # work ?

@lynicidn
Copy link
Contributor

👏

@spiritdead
Copy link
Author

@samdark plz can add this in the documentations when use INTL ?

@samdark
Copy link
Member

samdark commented Jun 18, 2016

So how the line looks in the end?

@pstddc
Copy link

pstddc commented Jun 24, 2016

@samdark строка содержащая 2 раза одну переменную не будет работать
т.е.
{a} {a, plural, =1{One}} - не работает
{a, plural, =1{# One}} - работает

@cebe
Copy link
Member

cebe commented Jun 25, 2016

can you check {a, number} {a, plural, =1{One}}? seen this in some versions of intl which have a type mismatch as they first thread a as a string and are then unable to use that string as plural rule input anymore.

@SilverFire
Copy link
Member

@cebe's option works fine. The problem is out of Yii scope, closing

@phdcoder
Copy link

phdcoder commented Nov 20, 2019

This error occurs because of old ICU version on intl module on PHP. There is some scenarios that is hard to fix it, hosting providers for example, and a solution is to use the fallback function to format the message provided by Yii itself. Remove the if enclosing the fallbackformat call on MessageFormartter::formart .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants