Search code examples
apachelocalizationserverdirectory-listingmod-autoindex

Can I change the language of mod_autoindex / Apache Directory Listing


is it possible to change the default language (German) of the Apache DirectoryListing?

I tried this:

DefaultLanguage de
AddLanguage de .de
LanguagePriority de en
ForceLanguagePriority Fallback

The table headers are still "Name", "Last modified" an "Size".


Solution

  • As of httpd 2.4.10, this is not possible using only httpd.conf because the column headings are hard-coded in modules/generators/mod_autoindex.c.

    I changed the headings using httpd.conf and JavaScript. This is not a full solution because it works for one language only. I have not been able to figure out how to do the same for several languages. It is, unfortunately, not possible to use 'document.documentElement.lang' to detect the appropriate language because mod_autoindex.c does not provide the 'lang' attribute.

    Here are the relevant lines from my httpd.conf (you can omit everything from IndexOptions except HTMLTable):

    LoadModule autoindex_module /usr/lib/httpd/modules/mod_autoindex.so
    IndexOptions HTMLTable Charset=UTF-8 SuppressDescription
    IndexStyleSheet "/DirectoryIndex.css"
    ReadmeName "/DirectoryIndexFooter.html"
    

    Note that you cannot omit the IndexStyleSheet directive even if you don't need the stylesheet. The stylesheet file does not have to exist.

    And this is my /DirectoryIndexFooter.html:

    <script>
      document.title = document.title.replace ('Index of', 'Sisukord:');
      var elem = document.getElementById ('indextitle');
      elem.innerHTML = elem.innerHTML.replace ('Index of', 'Sisukord:');
      elem = document.getElementsByClassName ('indexcolname') [0];
      elem.innerHTML = elem.innerHTML.replace ('Name', 'Nimi:');
      elem = document.getElementsByClassName ('indexcollastmod') [0];
      elem.innerHTML = elem.innerHTML.replace ('Last modified', 'Viimane muutmine:');
      elem = document.getElementsByClassName ('indexcolsize') [0];
      elem.innerHTML = elem.innerHTML.replace ('Size', 'Suurus:');
    </script>