Search code examples
localizationgettext

How to handle list of undefined length with gettext?


I'd like to translate strings of the following format:

Delete files toto, tata and titi.

First idea was to use Delete files %s but then I thought about plural forms.

What if some language doesn't put 'and' at the end but, for example, two different words for the last item and the one before it.

So here are two questions:

  • Do you know a language like that?
  • Do you know a better way to handle this case?

Solution

  • This is more complicated.

    Actually it seems that you need only to choose between singular and plural form (although languages could have multiple plural forms). So basically Do you want to delete this file: %s? or Do you want to delete these files: %s?. I cannot say for all languages but this would be OK in Polish.
    However, if you want to put quantity (which is rather good idea), you would end up with multiple plural forms: Do you want to delete this file: %s (Czy chcesz usunąć ten plik: {0}? when translated) or Do you want to translate these %n files: %s translated either as Czy chcesz usunąć te %n pliki: %s? or Czy chcesz usunąć tych %n plików: %s?.

    As for lists, CLDR charts might be a good source of information on how to handle them - look for listPattern. Below I am presenting a fragment from Polish charts:

    enter image description here

    {0} and {1} are placeholders, the list you provided would look like: toto; tata i titi. I am still not totally sure this is what it should like (in Polish I am more inclined to toto, tata i titi) but in theory you could use this information to create a list.
    In another answer I claimed that it is actually impossible to create such lists in general case (regardless of the language) and people tend to use list view controls for selection or present data as vertical list to avoid problems. Your example would need to be modified to:

    These file(s) would be deleted:  
    toto  
    tata  
    titi  
    Are you sure?
    

    This might be problematic (it might not fit in the screen) but this is what people often do to avoid issues with lists in foreign languages.