Open biuklija opened 1 day ago
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:
and the string label/value is defined here: https://github.com/advplyr/audiobookshelf/blob/72e59e77a7e4b4d029cef3dd11662c58ba1d60a5/client/strings/en-us.json#L622-L624
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.
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
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.
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: 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. 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