Render numbers with dot instead of comma (e.g. for stylesheets) in multi-language site

Hey all,

i use values from the panel to create css variables. They work with numbers like 1.19.
But when I change the language in the frontend to Dutch, the numbers are automatically translated to 1,119 (with a comma). Css can’t use those numbers. Why is this happening and how can I change it?

Thank you in advance.

Hey,
not sure but maybe you could add translate: false to those fields?

There are different ways to achieve that:

  1. IMO best option: Format the numbers with number_format: PHP: number_format - Manual
  2. Within your language specific locale settings, set LC_NUMERIC for Dutch to en (only makes sense if you don’t need numbers with language specific formatting for other purposes
  3. Do a simple string replacement when rendering the number in your template

I will go with your suggestion Texnixe.
I try this but it doesnt work yet:

<?= $panel->bodytextsize()->number_format($number, 2, '.', '')->or(1.5) ?>

whats wrong with it?

number_format() is a php function, you cannot call it on a field:

<?= number_format($page->bodytextsize()->or(1.5), 2, '.', '') ?>

I guess you meant $page, not $panel

No $panel was right. Then option 2 might be better…
I tried this but there is something wrong too, I guess…

<?php

return [
    'code' => 'nl',
    'default' => false,
    'direction' => 'ltr',
    'LC_NUMERIC'=> 'en_EN',
    'locale' => [
        'LC_ALL' => 'nl_NL',
        'LC_NUMERIC' => 'en_EN'
    ],
    'name' => 'Nederlands',
    'translations' => [

    ],
    'url' => NULL
];

Why do you think so?

Check how to do the locale settings right in the docs:

en_EN doesnt make sense, should be en_USoren_GB(the second part is a country code), also check the exact available locales on your machine usinglocale -a | grep en`

Yes that works! thank you.
I still think it is strange to change the numbers to 0,99. In Dutch this would be wrong as well.