Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: gender and plural in the autofill #920

Open
wiliamjk opened this issue Mar 8, 2023 · 12 comments
Open

Feature request: gender and plural in the autofill #920

wiliamjk opened this issue Mar 8, 2023 · 12 comments
Milestone

Comments

@wiliamjk
Copy link

wiliamjk commented Mar 8, 2023

Originally published here: https://wordpress.org/support/topic/feature-request-gender-and-plural-in-the-autofill/

I am a project editor responsible for translating your plugin into Brazilian Portuguese. As I use your plugin on almost every website I manage, this is very helpful.

However, the standard CPT label autofill feature has some limitations related to internationalization. That’s why I’m creating this topic so that we can discuss the possibility of making your plugin even more useful for foreign users.

Plural and singular

The first observation concerns plural and singular in some autocomplete strings.

I’ll give you an example from Portuguese:

In English, the phrase “Movie archives” uses the word “movie” in the singular. But in Portuguese, the most appropriate translation is in the plural. I will show step by step:

Movie -> Filme
Movies -> Filmes
archives -> arquivo (in Portuguese and with this meaning, this word is always translated in the singular)
Movie archive -> Arquivo de filmes (the noun is at the beginning with its attributes at the end. The word “de” indicates that the movie belongs to the archive)

But if I use the autofill it will generate this wrong sounding label: Arquivos de filme

This happens with several other sentences like “no movie found in trash”, for example. Also, I suspect other languages may have similar issues.

One suggestion that I don’t know if it’s possible to implement, but that would solve this problem, would be to use WordPress Translate’s placeholder feature:

image

Note that, in the translation, I need to insert the %s placeholder to define where the plugin will autofill.

We could define a placeholder for the label in the singular (%1$s) and another for the plural (%2$s) and we choose the most suitable one in the plugin’s translation. That way, regular users don’t even notice (it will just work) and people who know the language well can adapt it in the internationalization process. It would be possible?

Gender

The languages originating from Latin (and others as well) have a characteristic that is the gender of nouns.

For example, the word “Filme” (movie) is a masculine word, whereas the word “Página” (page) is a feminine word.

So “all movies” and “all pages” work fine in English just replicating “all _“. But, in Portuguese, the expression “all” must agree with the gender:

All Movies -> Todos os filmes
All Pages -> Todas as páginas

I’m not sure how it works in other languages, but I believe some even accept a neutral third gender.

This is a problem for your plugin’s internationalization because it will always autofill with the same gender, regardless of the gender of the selected word. This involves a mandatory manual review.

To resolve this, I thought it would work like this:

  1. The plugin detects the language of the WordPress installation
  2. If it’s Brazilian Portuguese (or another supported language), it shows a selector next to the autofill button: “Is this word masculine or feminine?”
  3. If the user chooses “female”, the plugin will autocomplete with female strings.
  4. In the plugin translation, we translate the appropriate strings for each genre

You can add languages little by little, checking if the functionality is suitable for the community.

I thought it might be a good idea to document this suggestion here for you to consider. As I mentioned, I use your plugin to create dozens of CPTs on different sites and something like this would save a lot of time manually reviewing the labels.

Anyway, thanks a lot for the excellent plugin!

@wiliamjk
Copy link
Author

wiliamjk commented Mar 8, 2023

In the original post, @tw2113 answered the following:

Definitely willing to help wherever we can. For the plural and singular, I believe we’re doing that directly on the fields in CPTUI via data attributes, for example: https://github.com/WebDevStudios/custom-post-type-ui/blob/master/inc/post-types.php#L417-L431

And then we’re doing the actual filling via https://github.com/WebDevStudios/custom-post-type-ui/blob/master/src/js/cptui-scripts.js#L241-L274 where we grab the attributes and fill in with JS and some quick string manipulation.

So I believe we’d need to touch up those fields that have the %s placeholder already to be a bit more robust. Not sure if https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals would be a good fit for this place, since that may be more for variable numbers and countable variations, as opposed to just singular/plural for movie vs filme and movies vs filmes.

The gender topic presents a more difficult, though I have to believe still accomplish-able process.

All said, would you be willing to movie this over to https://github.com/WebDevStudios/custom-post-type-ui/issues so that we can keep it more visibly tracked instead of just on the forum here?

@wiliamjk
Copy link
Author

wiliamjk commented Mar 8, 2023

Not sure if https://codex.wordpress.org/I18n_for_WordPress_Developers#Plurals would be a good fit for this place

I agree that not, after all, we would have to translate everything into two versions even though they are not totally correct.

I am not a developer, so I don't know if I can help in terms of technical solutions. But I know the features of the plugin well as well as the internationalization process (from English to Brazilian Portuguese at least), so if you can help with something, let me know!

@tw2113
Copy link
Member

tw2113 commented Mar 8, 2023

Thinking about this in parts, to not overly confuse myself. So I'm focused on the singular/plural aspect of things at the moment.

Since we have at least standard %s placeholders, and we're only switching out one potential value, I think our internationalized strings are fine, and workable. Correct me if I'm wrong on that part still, and perhaps argument swapping versions are still needed somehow.

The actual issue is on the javascript side where we are looking at a second data-attribute for which version we think should get used, "singular" or "plural". The question then turns to how do we offer any sort of ability to change that data attribute. Even with the ability to detect current languages, we'd still need to 1) Add filters to each plurality setting, 2) Offer a way to conditionally set for each label in a smart way so that only ones that need changed, are.

I am also pretty certain that https://developer.wordpress.org/reference/functions/_x/ would not be worthwhile solution because that still is run BEFORE the actual switching occurs.

@tw2113
Copy link
Member

tw2113 commented Mar 8, 2023

@wiliamjk is there a for-sure set list of labels that would work better with plural instead of the singular that they're receiving now?

A potential solution that I'm envisioning is some sort of filter that could be added to the 'plurality' => 'singular', lines and then we ourselves check if the current site/user language is Brazilian Portuguese or not. If yes, we check the current label being translated and if it's one that is by default singular, but should be plural for Brazilian Portuguese, then we return plural for the plurality line.

To make that work though, I'd need a definitive list of which labels would work better that way.

@wiliamjk
Copy link
Author

wiliamjk commented Mar 8, 2023

is there a for-sure set list of labels that would work better with plural instead of the singular that they're receiving now?

The direct answer is yes, but it depends. Almost every sentence I managed to force a translation a little different from the usual one, but that works in the default singular/plural. Just one phrase I couldn't get at all which is "___ archives". However, other translators may disagree with my approach and suggest other things (or even think of a solution that I haven't found). 🤷‍♂️

To make that work though, I'd need a definitive list of which labels would work better that way.

I think that this way, you will have a lot of work and it depends on a very close follow-up between the person responsible for internationalization and you. I'm willing to help, but I don't think this will happen with all languages.

So... I had suggested using different placeholders because that way it would take little effort from you to make the plugin compatible with all languages.

I don't know if it's possible, but would we be able to create a placeholder of our own just for that?
For example {{singular}} or {{plural}}?
Then you can insert in the string translation comments an instruction guiding the translator that he can use any of the two placeholders as long as it is appropriate.

I made a mockup of how it would look in the translate.wordpress.org translation panel:
image

But again, I don't know the difficulty of doing this from a programming point of view, so let me know if this really isn't feasible...

@tw2113
Copy link
Member

tw2113 commented Mar 8, 2023

Gimme some time to ponder over that one, that {{singular}} {{plural}} idea may have some feet to it instead of my current method, but need to think through it a bit more.

I do know that by default we are switching out the word item from the final untranslated result, with the JS.

@tw2113 tw2113 closed this as completed Mar 9, 2023
@tw2113 tw2113 reopened this Mar 9, 2023
@tw2113
Copy link
Member

tw2113 commented Mar 9, 2023

Understood if you don't fully understand the javascript portion of this, but the way I'm seeing potential for the singular/plural portion of this, is that when translating these specific autopopulate values, it'd be a case of returning either {{singular}} or {{plural}} instead of %s in general. I've confirmed that PHP won't throw a fit if no %s placeholder is returned. It would if the replacement value wasn't.

So in our javascript, we'd need to amend this section linked below, to first check for {{singular}} or {{plural}} first and if either of those exist, replace appropriately OTHERWISE just use what we have now with checking the if ( 'plural' === plurality ) { etc.

https://github.com/WebDevStudios/custom-post-type-ui/blob/master/src/js/cptui-scripts.js#L259-L273

Is that making sense here? If yes, I'll branch out into a new issue dedicated for just that process, and then resume mulling over the gender aspect.

@wiliamjk
Copy link
Author

wiliamjk commented Mar 9, 2023

I think that's it! You can do it.

I think it's important not to forget to add descriptions in the related strings so that translators from other regions can adapt the translations: https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#descriptions

@tw2113
Copy link
Member

tw2113 commented Mar 10, 2023

Absolutely on the descriptions and helper text. We would need to update appropriately for the comments like these: /* translators: Used for autofill */

@tw2113
Copy link
Member

tw2113 commented Mar 10, 2023

Branched off a new issue for the plurality over at #921

@tw2113
Copy link
Member

tw2113 commented Mar 10, 2023

On the topic of the gender aspect, I'm having a much bigger problem trying to think of a way to resolve this since it's coming down to a lot more variables in play. Yeah we could provide a dropdown that allows for specifying the gender, but then we have to also add in and provide strings ourselves for both variations, at minimum for as many languages as we can manage and detect which are used.

On the flipside, I would point out that the autofill functionality is definitely a nice touch, but also not a required step to use or set up. So I'm wondering if it'd maybe be a bit more advantageous to show some quick messaging, for languages that do have the different gender possibilities, about doing a quick spotcheck review of the genders and touchup as needed. Yes we'd still be requiring that review, but it'd be proactive in reminding the potential site owner to do so.

@Maikuolan
Copy link

but I believe some even accept a neutral third gender.

@wiliamjk Greek does that. (Probably others too, no doubt, but that's the one that immediately comes to mind for me).

@tw2113 tw2113 added this to the 1.14.0 milestone Jul 17, 2023
@tw2113 tw2113 modified the milestones: 1.14.0, Next Release Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants