language: Use item 'fallbackSequence' instead of duplicating logic
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 1 Jun 2015 23:04:26 +0000 (00:04 +0100)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Jun 2015 17:45:12 +0000 (17:45 +0000)
commitdd587fb99cb24f0e2db4ca8a4107e1da5ba6ba3a
tree9c6bfdd05ae093df2a8a456d4b1d33a9bff1a420
parent70d7e2eeb36186f576e46af544e44e0e7880d8cf
language: Use item 'fallbackSequence' instead of duplicating logic

The 'fallbackSequence' is exactly generated for this purpose. It
is equal to the value of 'fallback' after splitting, trimming
and ensuring 'en' is present. See LocalisationCache::recache().

Also simplify returning of the first array index by returning it
directly instead of modifying the array first.

Due to an inconsistency between how LocalisationCache and Language classes
treat the fallback sequence differently, we have to manually fallback
to 'en' in case of unknown language codes. This is because otherwise
Language::factory() will throw an exception causing tests to fail.
We should investigate whether this is desirable or not, but keeping
existing behaviour for now and documenting it.

Change-Id: I9c1d51b59aabebf5a31f38205304bb8cc22dcd8c
languages/Language.php