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

fdusautoir's avatar

Lang [male|female]

Hi Everybody.

Is there a way to adapt a word according to the gender of the user (male or female) within the Lang class ?

For example in french a technician is : 'Technicien' for male and 'Technicienne' for female.

0 likes
8 replies
pobble's avatar

Not without getting the user to specify their sex, which some people outside of French speaking countries might find strange and intrusive.

fdusautoir's avatar

In fact, this is a website for employees of a society (1500 employees). And before they can using the site, their account had to be validate by the admin who can validate if the employee is a man or woman.

bashy's avatar

Will need to do an extra check and add it into the lang array as a different name?

fdusautoir's avatar

What do you mean by "add it into the lang array as a different name" ? Can you do an example ?

pmall's avatar

@fdusautoir I don't see how you can do this without adding a lang entry for technicien and technicienne, and a if condition on the user's sex.

RachidLaasri's avatar
Level 41

I think you can use the Laravel lang choice for this.

'job' => "{0} Technicien|{1}Technicienne",
trans_choice('filename.job', 1);
trans_choice('filename.job', 0);
1 like
Ronan-Lenor's avatar

this post is very old but i didn't found anywhere another trick that i'm using that allow to use the gender AND keep the pluralization. I use a negative value for feminine and a positive value for masculine.

// english
'year' => '[-1,1]year|[*,*]years',

// french
'year' => '[*,-2]années|[-1,0]année|{1}an|[2,*]ans',

then in your code you can do something like that:

trans_choice('project.year', ($isFeminine) ? -abs($count) : abs($count))

Please or to participate in this conversation.