Commit 812ccfd7 authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

Premiers tests pour l'ajout de la langue dans les différentes routes. #167

parent 71d3c6dd
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import module namespace max.util = 'pddn/max/util' at 'rxq/util.xqm';
import module namespace max.html = 'pddn/max/html' at 'rxq/html.xqm';
import module namespace max.toc = 'pddn/max/toc' at 'rxq/toc.xqm';
import module namespace max.api = 'pddn/max/max_api' at 'rxq/max_api.xqm';
import module namespace max.i18n = 'pddn/max/i18n' at 'rxq/i18n.xqm';
import module namespace request = "http://exquery.org/ns/request";


@@ -60,9 +61,9 @@ function max:projectHome($project){
    let $redirection :=
        if (ends-with(request:uri(), '/'))
        then
            request:uri() || 'accueil.html'
            request:uri() || 'fr/accueil.html'
        else
            request:uri() || '/accueil.html'
            request:uri() || '/fr/accueil.html'
    return
        web:redirect($redirection)
};
@@ -74,8 +75,9 @@ declare
%output:html-version("5.0")
%output:indent("no")
%output:encoding("UTF-8")
%rest:path( "/{$project}/{$page=[a-zA-Z0-9_]+}.html")
function max:page($project, $page){
%rest:path( "/{$project}/{$lang=[a-z]+}/{$page=[a-zA-Z0-9_]+}.html")
function max:page($project, $lang, $page){
    let $l := max.i18n:setLang($project, $lang)
    let $dbPath := max.config:getProjectDBPath($project)
    return

@@ -132,8 +134,9 @@ declare
%output:html-version("5.0")
%output:indent("no")
%output:encoding("UTF-8")
%rest:path("/{$project}/sommaire/{$doc=.*}.html")
function max:documentTOC($project, $doc){
%rest:path("/{$project}/{$lang=[a-z]+}/sommaire/{$doc=.*}.html")
function max:documentTOC($project, $lang, $doc){
    let $l:= max.i18n:setLang($project, $lang)
    let $content := max.toc:getDocumentTOC($project, $doc || '.xml')
    return max.html:render($project, "sommaire", $content, ())
};
+7 −4
Original line number Diff line number Diff line
@@ -198,12 +198,15 @@ as item()+
declare %private function max.html:buildI8nMenu($projectId as xs:string){
    <ul class="i18n-menu">
        {
            let $path := request:path()
            for $l in max.i18n:getLanguageList($projectId)
                let $class:= if(max.i18n:getLang($projectId) = $l)
            then "max-lang selected"
                    then "max-lang selected fw-bold"
                    else "max-lang"
                let $currentLang := max.i18n:getLang($projectId)
                let $targetUrl := replace($path,'/'||$currentLang||'/','/'||$l||'/')
            return
                <li class="{$class}"><a role="button" onclick="MAX.setLanguage('{$l}')">{$l}</a></li>
                <li class="{$class}"><a role="button" class="text-decoration-none" href="{$targetUrl}">{$l}</a></li>
        }
    </ul>
};
+3 −3
Original line number Diff line number Diff line
@@ -5,10 +5,10 @@ import module namespace max.util = 'pddn/max/util' at 'util.xqm';
import module namespace max.config = 'pddn/max/config' at 'config.xqm';

declare
%rest:GET
%rest:path("/{$projectId}/setlang/{$lang}")
(:%rest:GET:)
(:%rest:path("/{$projectId}/setlang/{$lang}"):)
function max.i18n:setLang($projectId, $lang){
    session:set($projectId || '-lang', $lang)
    session:set($projectId || '-lang', $lang), $lang
};

declare function max.i18n:getLang($projectId){
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ declare function max.toc:getProjectTOC($project){
            'locale': max.i18n:getLang($project)
            })
        else
            max.util:list-db-resources($project)
            max.util:list-db-resources($project, max.i18n:getLang($project))

    let $tocXSL := max.util:getProjectTOCXSL($project)

+6 −6
Original line number Diff line number Diff line
@@ -150,13 +150,13 @@ declare function max.util:doc-in-collection($dbName, $collection){
(:
Lists all DB resources (recursively)
:)
declare function max.util:list-db-resources($project){
declare function max.util:list-db-resources($project, $lang){
    let $dbName := max.config:getProjectDBPath($project)
    let $xmlns:= max.config:getXMLFormat($project)
    let $baseURI:= max.util:getRelativeRootPath(())
    return
    <ul>
        {max.util:list-db-resources($project, $dbName, $baseURI, $xmlns,'')}
        {max.util:list-db-resources($project, $dbName, $baseURI, $xmlns,'', $lang)}
    </ul>

};
@@ -167,9 +167,9 @@ declare function max.util:list-db-resources($project){
Lists all DB resources (recursively) + add href prefix on each hyperlinks
:)

declare function max.util:list-db-resources($projectId, $dbName, $baseURI, $xmlns, $dir){
declare function max.util:list-db-resources($projectId, $dbName, $baseURI, $xmlns, $dir, $lang){
    for $d in db:dir($dbName, $dir)
    let $subDirs := max.util:list-db-resources($projectId, $dbName, $baseURI, $xmlns,$dir||'/'||$d)
    let $subDirs := max.util:list-db-resources($projectId, $dbName, $baseURI, $xmlns,$dir||'/'||$d,$lang)
    let $depth := count(string-to-codepoints($dir)[.=string-to-codepoints('/')])
    order by $d/text() 
    return
@@ -177,7 +177,7 @@ declare function max.util:list-db-resources($projectId, $dbName, $baseURI, $xmln
        return
            if(ends-with($d/text(),'.xml'))
            then
                <li data-depth='{$depth}' data-href='{$baseURI}{$projectId}/sommaire/{$fullPath}'>
                <li data-depth='{$depth}' data-href='{$baseURI}{$projectId}/{$lang}/sommaire/{$fullPath}'>
                    {
                        max.util:getDocTitle($dbName, $fullPath, $xmlns)
                    }
@@ -185,7 +185,7 @@ declare function max.util:list-db-resources($projectId, $dbName, $baseURI, $xmln
            else
                <li data-dir='true' data-depth='{$depth}'>{$d/text()}
                    <ul>
                        {max.util:list-db-resources($projectId, $dbName, $baseURI, $xmlns,$dir||'/'||$d)}
                        {max.util:list-db-resources($projectId, $dbName, $baseURI, $xmlns,$dir||'/'||$d, $lang)}
                    </ul>
                </li>
};