Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/441 Fail if no language is set #461

Merged
merged 15 commits into from
Dec 10, 2024
Merged
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}" />
riedde marked this conversation as resolved.
Show resolved Hide resolved
<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
Loading