German "Umlaute" in blueprint field ( with key() )

Maybe I’m just being dumb but i’m having a blueprint that contains a bunch of text like:

          kamera:
            label: Kamera
            type: text
          schnitt:
            label: Schnitt
            type: text
          musik:
            label: Musik
            type: text
          kostüm:
            label: Kostüm
            type: text

and in my php file I wanna display the content along with the name and when a field is empty nothing should be shown. My code is like that and works as expected:

<?php foreach($page->content()->fields() as $field): ?>
        <?php if($field->isNotEmpty() && $field->key() == "musik"):?>
            <div class="one">
                <p class="two"><?= ucfirst($page->musik()->key()) ?></p>
                <div class="three">
                    <?= $page->musik()->kirbytext() ?>
                </div>
            </div>
        <?php endif ?>
    <?php endforeach ?>

Kostüm is displayed with the “ü” in the panel but on the page it’s displayed as “kostuem”. This only happens with the key(), and nowhere else. I have <meta charset="UTF-8"> in the header and tried various stuff from the forum like putting <?php header('Content-type: text/html; charset=utf-8'); ?> after the doctype. Is there anything else i can try?

You shouldn’t use umlauts in field names, they are invalid. Only use characters that are also allowed in PHP method names.

yeah i feel like this is a very german problem, is there a way to have it display the “ü” on the page even if the field is named “kostuem”?

Okay I think I got it to work using this code:

<?php if( $field->isNotEmpty() && $field->key() == "kostuem"):?>
   <p>Kostüm</p>
<?php else: ?>
   <p><?= ucfirst($field->key()) ?></p>
<?php endif ?>

IMO, this is not a very sustainable solution. What if you have multiple keys with umlauts or ß, then you would need multiple if statements.

I always use English keys in order not to have mixed languages in my code (for readability and to make code understandable for international developers). Then for such cases, I would use a key-value map (an array with the field key as key and the desired output as value). Such an array can be defined in your config.

Yeah that seems like a much more sophisticated version indeed. I will try to implement this instead. In this case I was kind of okay with my solution since the fields are fixed and there is only this one with an umlaut.