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

Add class for translation of dynamic elements: number of notes, reviews, etc. #1070

Open
mmalferov opened this issue Sep 14, 2024 · 0 comments
Labels

Comments

@mmalferov
Copy link
Member

mmalferov commented Sep 14, 2024

Base on: #1057 (comment)

I suggest add methods for different languages to form on doc-site correct plurals for different dynamic elements: the total note count, the number of upvotes, etc.

Maybe something like this:

https://onlinephp.io/c/bdfda

Contributors from each country will only have to implement their plural method and call in the code:

<?php

$num_notes = 1;
echo NumberBaseDeclinsion::decline($num_notes, ['note', 'notes',], 'en',); // 1 note
echo NumberBaseDeclinsion::decline($num_notes, ['заметка', 'заметки', 'заметок',], 'ru',); // 1 заметка

$num_notes = 2;
echo NumberBaseDeclinsion::decline($num_notes, ['note', 'notes',], 'en',); // 2 notes
echo NumberBaseDeclinsion::decline($num_notes, ['заметка', 'заметки', 'заметок',], 'ru',); // 2 заметки

$num_notes = 5;
echo NumberBaseDeclinsion::decline($num_notes, ['note', 'notes',], 'en',); // 5 notes
echo NumberBaseDeclinsion::decline($num_notes, ['заметка', 'заметки', 'заметок',], 'ru',); // 5 заметок

// Phrase
echo NumberBaseDeclinsion::decline(38, ['pink flamingo', 'pink flamingos',], 'en',); // 38 pink flamingos
echo NumberBaseDeclinsion::decline(38, ['розовый фламинго', 'розовых фламинго', 'розовых фламинго',], 'ru',); // 38 розовых фламинго

// And if you want the text not to break between the number and the next word, you can add an unbreakable space:
echo NumberBaseDeclinsion::decline(8, ['comment', 'comments',], 'en', '&nbsp;',); // 8&nbsp;comments

More examples can be found at the link.

In particular, if you translate the total number of notes of the contribution notes, then for the Russian language you will need 1 singular form + 2 plural forms. And for English, only two forms are enough. Therefore, a separate method (or function, if it is decided to write in a functional style) will be required for each language, which will form the correct string with a number for its language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants