Can I change the language of mod_autoindex / Apache Directory Listing

2k views Asked by At

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".

2

There are 2 answers

0
toomas On BEST ANSWER

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>
0
ondelettes On

This is just a complement to @toomas' answer.

You can combine his hack with Options +multiviews. See https://httpd.apache.org/docs/2.4/content-negotiation.html.

Then just add your files README.html.de, README.html.et… each of which can then perform the desired translation.

As a side note, ReadmeName "/README.html" means you use only one file — here a set — from the root folder for the whole site — unless stated otherwise for some locations/directories —, while ReadmeName "README.html" means you use a different one in each autoindexed folder.