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

Lars-Janssen's avatar

Vue pluralize in combination with php

Hi!,

I've got this in a .blade file:

<p class="text-grey-darker mt-1"><i>@{{ add.locations.length }} {{ ngettext('location', 'locations', 2) }}</i></p>

I want to pluralize location. But how do I add the javascript length to the ngettext php method?

This is obviously not working:

{{ ngettext('location', 'locations', @{{ add.locations.length }} ) }}

Thanks!

0 likes
3 replies
Snapey's avatar

How could you possibly add something that is calculated in the client to the server output?

Snapey's avatar
Snapey
Best Answer
Level 122

If locations (the variable) is coming from the server then you could check the length there and pass through the correct word.

Else just use a javascript ternary inline or a vue computed property?

1 like

Please or to participate in this conversation.