Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

Can __( method have lowercase parameter ?

In laravel 11 app I keep lang labels in lower case, like :

'select' => 'seleccionar',

when I need to show some text as example in Capitalized format I use code :

{{ \Str::ucfirst(__('quiz.select') }}

I wonder if laravel have possibility /addive plugins to make it more readable(as it seems to me) like :

{{ __('quiz.select', LANG::CAPITALIZED) }}

where LANG is some enum ?

0 likes
5 replies
krisi_gjika's avatar

personally I keep all translations in lower case and use css to capitalize, this way someone working on front-end does not need to learn php to have control over the way the text is rendered.

1 like
JussiMannisto's avatar

@krisi_gjika CSS is only useful in the case of uppercase transform. Otherwise capitalization has to be done by the translator. It's impossible to do that with CSS due to language differences, even for simple things like labels.

tuncdogu55's avatar

In my opinion in Laravel, there's no built-in feature for directly specifying text transformations like capitalization within the __() function for translations. However, you can achieve this by using custom helper functions.

Custom Helper Function

You can create a custom helper function to handle text transformations. Here's an example:

  1. Create a Custom Helper Function:

    In your app/helpers.php file (create it if it doesn’t exist), add the following function:

    if (! function_exists('trans_with_transform')) {
        function trans_with_transform($key, $transform = null, $locale = null) {
            $translation = __($key, [], $locale);
            if ($transform === 'capitalized') {
                return \Str::ucfirst($translation);
            }
            // Add more transformations if needed
            return $translation;
        }
    }
    

Do you know how register a Helper ?

for use after register:

{{ trans_with_transform('quiz.select', 'capitalized') }}

You can add more transform methods for your project.

1 like
tuncdogu55's avatar
Level 1

@mstdmstd Yes, I'll provide a new one because I believe this is more readable And same with @krisi_gjika 's suggestion. in your style.css

.text-transform-none {
    text-transform: none;
}

.text-transform-uppercase {
    text-transform: uppercase;
}

.text-transform-lowercase {
    text-transform: lowercase;
}

.text-transform-capitalize {
    text-transform: capitalize;
}

After that in your blade page : For example in welcome.blade.php

//  add style 
<p class="text-transform-none">This text will not be transformed.</p>
<p class="text-transform-uppercase">this text will be transformed to uppercase.</p>
<p class="text-transform-lowercase">THIS TEXT WILL BE TRANSFORMED TO LOWERCASE.</p>
<p class="text-transform-capitalize">this text will be transformed to Capitalize.</p>
1 like

Please or to participate in this conversation.