Skip to content

Commit

Permalink
Fix/441 Fail if no language is set (#461)
Browse files Browse the repository at this point in the history
## Description, Context and related Issue

Fixes #441

## Types of changes
- Bug fix (non-breaking change which fixes an issue)
- 
## Checklist
- I have performed a self-review of my code
  • Loading branch information
peterstadler authored Dec 10, 2024
2 parents 48e9e2f + 9f63d59 commit fd45a49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 0 additions & 1 deletion add/controller.xql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ return
(: forward index.html to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="index.xql">
<set-header name="Set-Cookie" value="edirom-language={$langVal}" />
<add-parameter name="lang" value="{$langVal}"/>
</forward>
</dispatch>
Expand Down
30 changes: 17 additions & 13 deletions add/data/xqm/eutil.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,22 @@ declare function eutil:getLanguageString($key as xs:string, $values as xs:string
: @param $edition The current edition URI
: @return The preference value
:)
declare function eutil:getPreference($key as xs:string, $edition as xs:string?) as xs:string {
declare function eutil:getPreference($key as xs:string, $edition as xs:string?) as xs:string? {

let $preferencesFile :=
(: Try to load a custom preferences file :)
let $prefFileCustom :=
try { doc(edition:getPreferencesURI($edition)) }
catch * { util:log-system-out('Failed to load preferences') }

catch * { util:log-system-out('Failed to load the custom preferences file') }
return
$preferencesFile//entry[@key = $key]/@value => string()

(: If there is a value for the key in the custom preferences file :)
if($prefFileCustom//entry/@key = $key) then
$prefFileCustom//entry[@key = $key]/@value => string()
(: If not, take the value for the key in the default preferences file :)
else
try { doc($edition:default-prefs-location)//entry[@key = $key]/@value => string() }
(: If the key is not in the default file, then there should be an error :)
catch * { util:log-system-out(concat('Failed to find the key `', $key, '` in default preferences file')) }
};

(:~
Expand All @@ -299,16 +306,13 @@ declare function eutil:getPreference($key as xs:string, $edition as xs:string?)
: @return The language key
:)
declare function eutil:getLanguage($edition as xs:string?) as xs:string {

if (request:get-parameter("lang", "") != "") then
request:get-parameter("lang", "")

else if(request:get-cookie-names() = 'edirom-language') then
request:get-cookie-value('edirom-language')

else
else if(eutil:getPreference('application_language', edition:findEdition($edition))) then
eutil:getPreference('application_language', edition:findEdition($edition))

else
'de'
};

(:~
Expand Down

0 comments on commit fd45a49

Please sign in to comment.