Unable to change locale settings

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Unable to change locale settings

Post by flomo » 24 Oct 2019, 18:27

How would you change the decimal separator? I tried:

Code: Select all

    'client' => [
        'html' => [
            'common' => [
                'format' => [
                    'separatorDecimal' => '.',
                ]
            ],
        ]
    ]
but this doesn't change anything.

Also, Swiss Francs are correctly shown as "CHF" in the backend, but in "Fr" in the frontend. How would you change this? I tried:

Code: Select all

    'i18n' => [
        'de' => [
            'client/currency' => [
                'CHF' => 'CHF',
                'Fr' => 'CHF',
            ],
        ],
    ],
none of the two lines worked.

Then, how can I place the currency symbol in front of the price? I tried this as indicated here https://aimeos.org/docs/Developers/Html ... pe_formats:

Code: Select all

    'i18n' => [
        'de' => [
            'client/code' => [
                'price:default' => ['%2$s %1$s'],
            ],
        ],
    ],
didn't work either.

flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Re: Unable to change locale settings

Post by flomo » 24 Oct 2019, 19:42

I just found out, that the last example actually works and places the currency code before the price. However only on the product, not in the basket.

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Unable to change locale settings

Post by aimeos » 25 Oct 2019, 08:07

flomo wrote: 24 Oct 2019, 18:27 How would you change the decimal separator? I tried:
but this doesn't change anything.
The decimal separator is determined automatically by the locale setting due to the NumberFormatter class of the php-intl extension. You can't change that any more:
https://github.com/aimeos/aimeos-core/b ... Locale.php

The old view helper is still available but not used any more:
https://github.com/aimeos/aimeos-core/b ... andard.php
flomo wrote: 24 Oct 2019, 18:27 Also, Swiss Francs are correctly shown as "CHF" in the backend, but in "Fr" in the frontend. How would you change this? I tried:
Use this configuration:

Code: Select all

    'i18n' => [
        'de' => [
            'currency' => [
                'CHF' => 'CHF',
            ],
        ],
    ],
flomo wrote: 24 Oct 2019, 18:27 Then, how can I place the currency symbol in front of the price? I tried this as indicated here https://aimeos.org/docs/Developers/Html ... pe_formats:
This is the correct setting but keep in mind that the basket content is cached and only renewed if the basket is updated. You can disable caching the basket for development using this setting:
https://github.com/aimeos/aimeos-larave ... op.php#L65
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Re: Unable to change locale settings

Post by flomo » 25 Oct 2019, 09:13

Thanks for your always very appreciated support!
The decimal separator is determined automatically by the locale setting due to the NumberFormatter class of the php-intl extension. You can't change that any more:
In Switzerland we have 4 languages ((Swiss-) German, French, Italian and Rumantsch). Because its difficult to support all of them, we often add English to German and French. It's also not so easy to find translations in de_CH, that's why it's often easier to simply use the "de" locale (same goes for fr/fr_CH). NumberFormatter generates a different format for en, fr, de, fr_CH and de_CH (the latter two being the correct ones). I will have to find a way to somehow hardcode the formatting, no matter the locale.

It would be great to have a formatting column for each locale in the backend in a future version.
Use this configuration:
I had to use the following, because Aimeos treated the string as an array:

Code: Select all

    'i18n' => [
        'de' => [
            'currency' => [
                'CHF' => ['CHF'],
            ],
        ],
    ],
This is the correct setting but keep in mind that the basket content is cached and only renewed if the basket is updated. You can disable caching the basket for development using this setting:
I had it disabled and also cleared the cookies. But no matter what I do, I can't update the formatting in the basket. It reads "Versandkosten 0,00 CHF" while the product reads "ab 1 CHF 123,00 Inkl. 7,70% MwSt.". When I switch the locale to "en", value and currency are switched, but I can't influence it: "Shipping CHF 0.00".

flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Re: Unable to change locale settings

Post by flomo » 25 Oct 2019, 09:39

The old view helper is still available but not used any more:
I just played around with the helpers. Is there a possibility to overwrite or exchange them?

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Unable to change locale settings

Post by aimeos » 25 Oct 2019, 10:28

You can by creating your own view object in your service provider and extending/overwriting the method in the original view object:
https://github.com/aimeos/aimeos-larave ... hp#L82-L84

The easier way might be to use the pattern configuration for the NumberFomatter class: https://github.com/aimeos/aimeos-larave ... w.php#L162

Then, you can use configure patterns like "#.###.##0,00" to get always the same format:
https://unicode-org.github.io/icu-docs/ ... ml#details
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Unable to change locale settings

Post by aimeos » 25 Oct 2019, 15:10

Aimeos also has a fallback for translations from de_CH/fr_CH to de/fr. We will keep your suggestion in mind to add configure number formats per locale in the future.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Re: Unable to change locale settings

Post by flomo » 28 Oct 2019, 10:55

Aimeos also has a fallback for translations from de_CH/fr_CH to de/fr. We will keep your suggestion in mind to add configure number formats per locale in the future.
That would be great.
The easier way might be to use the pattern configuration for the NumberFomatter class:

Then, you can use configure patterns like "#.###.##0,00" to get always the same format:
This doesn't work, because a dot is always the decimal separator, which will get localized. So "#0.#" will produce a comma with locale "de" and a dot with locale "de_CH".

I now register my own instance of \Aimeos\Shop\Base\View which overwrites the addNumber() method with a custom Locale helper. This works so far.

However I'm still stuck with the currency formatting in the basket. This

Code: Select all

i18n\de\client/code\price:default = ['%2$s %1$s']
works, but doesn't change the basket (I did disable the basket caching and I also deleted the session cookie on each test).

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Unable to change locale settings

Post by aimeos » 28 Oct 2019, 12:05

flomo wrote: 28 Oct 2019, 10:55
Then, you can use configure patterns like "#.###.##0,00" to get always the same format:
This doesn't work, because a dot is always the decimal separator, which will get localized. So "#0.#" will produce a comma with locale "de" and a dot with locale "de_CH".
Would "#'###'##0.00" produce the desired result? I'm asking because you have to get the desired results with one of those patterns. Otherwise, it's useless to add locale specific formatting.
flomo wrote: 28 Oct 2019, 10:55 However I'm still stuck with the currency formatting in the basket. This

Code: Select all

i18n\de\client/code\price:default = ['%2$s %1$s']
Use that one for the basket and the order to reverse currency and value:

Code: Select all

'i18n' => [
	'de' => [
		'client' => [
			'%1$s %2$s' => ['%2$s %1$s']
		]
	]
]
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

flomo
Posts: 52
Joined: 26 Sep 2019, 15:11

Re: Unable to change locale settings

Post by flomo » 28 Oct 2019, 14:17

Would "#'###'##0.00" produce the desired result? I'm asking because you have to get the desired results with one of those patterns. Otherwise, it's useless to add locale specific formatting.
No, it doesn't work like this. With the pattern you can set the number of digits after the decimal separator, for example. But you can't define what the separator looks like. The idea of the NumberFormatter pattern is to define a pattern for a number, which then still gets localized. So the decimal separator will always be a comma for "de" and a dot for "de_CH", no matter the pattern.
Use that one for the basket and the order to reverse currency and value:
That worked, thank you very much.

Post Reply