[Enhancement]: Proper plurals support for localisation #2320

Open
opened 2026-04-25 00:06:05 +02:00 by adam · 4 comments
Owner

Originally created by @biuklija on GitHub (Oct 20, 2024).

Type of Enhancement

Web Interface/Frontend

Describe the Feature/Enhancement

Currently, some of the strings and labels for localisation are being reused in multiple locations without proper plurals support. While this works for English, problems arise in many inflected languages. Weblate has full support for these plural forms, so my suggestion is to separate labels/strings into "fixed" strings (meaning those that don't need plurals support) and "plural" strings require alternative translations in places where the translation depends on the number of items.

Why would this be helpful?

To take Croatian as an example, the string LabelBooks, if translated in the nominative case in Croatian (in plural) as "Knjige", would serve fine in the search results/search suggestions, e.g. here:
vivaldi_oLWveEENnL
However, the same word would be incorrect as a caption for the number of books available in a single library, where the translation is supposed to vary depending on the actual number of books.
vivaldi_6cxm860taj
Please note that in the above example with plurals the translation "knjiga/e" is my attempt to offer a correct translation for plurals of this word but some words have even more variants.

Future Implementation (Screenshot)

As per Weblate's documentation, we should have plural-supported strings. For example, the correct translation for the word "Book" in Croatian should be:
0, 1 knjiga
2, 3, 4 knjige
5-20 knjiga
21, 31... knjiga
22, 23, 24; 32, 33, 34... - knjige
25-30; 35-40... - knjiga

Audiobookshelf Server Version

v2.15.1

Current Implementation (Screenshot)

No response

Originally created by @biuklija on GitHub (Oct 20, 2024). ### Type of Enhancement Web Interface/Frontend ### Describe the Feature/Enhancement Currently, some of the strings and labels for localisation are being reused in multiple locations without proper plurals support. While this works for English, problems arise in many inflected languages. Weblate has full support for [these plural forms](https://docs.weblate.org/en/latest/user/translating.html#plurals), so my suggestion is to separate labels/strings into "fixed" strings (meaning those that don't need plurals support) and "plural" strings require alternative translations in places where the translation depends on the number of items. ### Why would this be helpful? To take Croatian as an example, the string `LabelBooks`, if translated in the nominative case in Croatian (in plural) as "Knjige", would serve fine in the search results/search suggestions, e.g. here: ![vivaldi_oLWveEENnL](https://github.com/user-attachments/assets/c0cf5abb-abaa-4b04-b0a0-c39c10836053) However, the same word would be incorrect as a caption for the number of books available in a single library, where the translation is supposed to vary depending on the actual number of books. ![vivaldi_6cxm860taj](https://github.com/user-attachments/assets/44ceae32-cf7c-4524-a0ae-b8b3ee6aa815) Please note that in the above example with plurals the translation "knjiga/e" is my attempt to offer a correct translation for plurals of this word but some words have even more variants. ### Future Implementation (Screenshot) As per Weblate's documentation, we should have plural-supported strings. For example, the correct translation for the word "Book" in Croatian should be: 0, 1 **knjiga** 2, 3, 4 **knjige** 5-20 **knjiga** 21, 31... **knjiga** 22, 23, 24; 32, 33, 34... - **knjige** 25-30; 35-40... - **knjiga** ### Audiobookshelf Server Version v2.15.1 ### Current Implementation (Screenshot) _No response_
adam added the enhancement label 2026-04-25 00:06:05 +02:00
Author
Owner

@nichwall commented on GitHub (Oct 20, 2024):

Would we need separate labels in the translation file for each combination of plurals in the code? Would we need to add language specific pluralization handling everywhere? I see we can add that in Weblate easily, but not sure to handle that nicely in the code without having a lot more translation targets.

Right now, we have a function which just substitutes values into the string called getString. An example of that is here for the sleep timer:

https://github.com/advplyr/audiobookshelf/blob/72e59e77a7e4b4d029cef3dd11662c58ba1d60a5/client/components/modals/SleepTimerModal.vue#L71-L112

and the string label/value is defined here:
https://github.com/advplyr/audiobookshelf/blob/72e59e77a7e4b4d029cef3dd11662c58ba1d60a5/client/strings/en-us.json#L622-L624

@nichwall commented on GitHub (Oct 20, 2024): Would we need separate labels in the translation file for each combination of plurals in the code? Would we need to add language specific pluralization handling everywhere? I see we can add that in Weblate easily, but not sure to handle that nicely in the code without having a *lot* more translation targets. Right now, we have a function which just substitutes values into the string called `getString`. An example of that is here for the sleep timer: https://github.com/advplyr/audiobookshelf/blob/72e59e77a7e4b4d029cef3dd11662c58ba1d60a5/client/components/modals/SleepTimerModal.vue#L71-L112 and the string label/value is defined here: https://github.com/advplyr/audiobookshelf/blob/72e59e77a7e4b4d029cef3dd11662c58ba1d60a5/client/strings/en-us.json#L622-L624
Author
Owner

@biuklija commented on GitHub (Oct 20, 2024):

If I understand this correctly, we're not using a multi-language translation library in this project (one which would automatically handle translations i.e. export and update a list of strings for translation and, presumably, provide support for plurals) and just doing string substitution?

I can see why adding project-wide plurals support might be a tall order, especially if done from scratch. I'm not sure how this is usually handled in other projects.

In any case, if reworking the entire localisation support is too much work and if we want to avoid creating too many new translation targets, separating strings which follow or precede a number could be an acceptable alternative.
For instance, we can have a fixed string Books that will always be Knjige (for the homepage links) and a {0} books string which I could translate as {0} knjiga/knjige, shorten as {0} knjiga/e or just do knjiga: {0} which would also work. There shouldn't be too many of these cases.

@biuklija commented on GitHub (Oct 20, 2024): If I understand this correctly, we're not using a multi-language translation library in this project (one which would automatically handle translations i.e. export and update a list of strings for translation and, presumably, provide support for plurals) and just doing string substitution? I can see why adding project-wide plurals support might be a tall order, especially if done from scratch. I'm not sure how this is usually handled in other projects. In any case, if reworking the entire localisation support is too much work and if we want to avoid creating too many new translation targets, separating strings which follow or precede a number could be an acceptable alternative. For instance, we can have a fixed string `Books` that will always be `Knjige` (for the homepage links) and a `{0} books` string which I could translate as `{0} knjiga/knjige`, shorten as `{0} knjiga/e` or just do `knjiga: {0}` which would also work. There shouldn't be too many of these cases.
Author
Owner

@advplyr commented on GitHub (Oct 20, 2024):

We can write a function that takes an optional number parameter and returns the correct plural form but I'm not seeing any examples in weblate how this is formatted

@advplyr commented on GitHub (Oct 20, 2024): We can write a function that takes an optional number parameter and returns the correct plural form but I'm not seeing any examples in weblate how this is formatted
Author
Owner

@biuklija commented on GitHub (Oct 21, 2024):

Weblate's documentation provides a list of file formats that support plurals along with format examples, but it seems that basic json files of the "key":"translation" type are not supported. To quote their documentation:

Pluralizing strings need proper support from the application framework as well. Choose native format of your platform such as GNU gettext PO (Portable Object), Android string resources or Stringsdict format.

@biuklija commented on GitHub (Oct 21, 2024): Weblate's documentation provides a list of [file formats](https://docs.weblate.org/en/latest/formats.html#translation-types-capabilities) that support plurals along with format examples, but it seems that basic json files of the "key":"translation" type are not supported. To quote their documentation: > Pluralizing strings need proper support from the application framework as well. Choose native format of your platform such as [GNU gettext PO (Portable Object)](https://docs.weblate.org/en/latest/formats/gettext.html#gettext), [Android string resources](https://docs.weblate.org/en/latest/formats/android.html#aresource) or [Stringsdict format](https://docs.weblate.org/en/latest/formats/stringsdict.html#stringsdict).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#2320