Loading rxq/config.xqm +10 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,16 @@ declare function max.config:getProjectPrettyName($projectId){ else $projectId }; (:returns edition prettyName from config file:) declare function max.config:getProjectDefaultLang($projectId){ let $lang := doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]/@lang return if($lang) then string($lang) else 'fr' }; (:returns enabled plugin name list:) declare function max.config:getEnabledPluginNames($projectId){ doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]//plugin/@name Loading rxq/i18n.xqm +3 −72 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ module namespace max.i18n = 'pddn/max/i18n'; 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 Loading @@ -12,12 +12,12 @@ function max.i18n:setLang($projectId, $lang){ }; declare function max.i18n:getLang($projectId){ session:get($projectId || '-lang', 'fr') session:get($projectId || '-lang', max.config:getProjectDefaultLang($projectId)) }; declare function max.i18n:getText($projectId as xs:string, $key as xs:string){ max.i18n:getText($projectId, $key, session:get($projectId || '-lang', 'fr')) max.i18n:getText($projectId, $key, session:get($projectId || '-lang', max.config:getProjectDefaultLang($projectId))) }; declare function max.i18n:getText($projectId as xs:string, $key as xs:string, $locale as xs:string ?) Loading Loading @@ -49,72 +49,3 @@ declare function max.i18n:getLanguageList($projectId){ } catch * {'fr'} }; (: declare function max.i18n:getMap($projectId, $locale){ let $i18nResourceFile := max.util:maxHome() || "/ui/i18n/I18n" || $locale || ".xml" let $projectI18nFile := max.util:maxHome() || "/editions/" || $projectId || "/ui/i18n/I18n" || $locale || ".xml" let $primaryI18n := if (file:exists($projectI18nFile)) then doc($projectI18nFile) else doc($i18nResourceFile) let $secondaryI18n := if (file:exists($projectI18nFile)) then doc($i18nResourceFile) else () let $m1 := map:merge( for $entry in $primaryI18n//entry return map {string($entry/@key) : $entry/text() } ) let $m2 := map:merge( for $entry in $secondaryI18n//entry return if(not($primaryI18n//entry[@key=$entry/@key])) then map {string($entry/@key) : $entry/text()} else() ) return map:merge(($m2,$m1)) }; :) (: declare function max.i18n:getI18n($projectId, $locale) as node()*{ let $i18nResourceFile := max.util:maxHome() || "/ui/i18n/I18n" || $locale || ".xml" let $projectI18nFile := max.util:maxHome() || "/editions/" || $projectId || "/ui/i18n/I18n" || $locale || ".xml" let $primaryI18n := if (file:exists($projectI18nFile)) then doc($projectI18nFile) else doc($i18nResourceFile) let $secondaryI18n := if (file:exists($projectI18nFile)) then doc($i18nResourceFile) else () return <entries> { for $entry in $primaryI18n//entry return $entry } { for $entry in $secondaryI18n//entry return if(not($primaryI18n//entry[@key=$entry/@key])) then $entry else() } </entries> }; declare %rest:GET %output:method("html") %output:html-version("5.0") %output:indent("no") %output:encoding("UTF-8") %rest:path( "/{$projectId}/i18n/{$locale}.html") function max.i18n:listPage($projectId, $locale){ let $map := max.i18n:getMap($projectId, $locale) return <html> <body> <h1>I18n - {$projectId} - {$locale}</h1> <ul> { for $k in map:keys($map) return <li>{$k} : {map:get($map, $k)}</li> } </ul> </body> </html> }; :) No newline at end of file Loading
rxq/config.xqm +10 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,16 @@ declare function max.config:getProjectPrettyName($projectId){ else $projectId }; (:returns edition prettyName from config file:) declare function max.config:getProjectDefaultLang($projectId){ let $lang := doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]/@lang return if($lang) then string($lang) else 'fr' }; (:returns enabled plugin name list:) declare function max.config:getEnabledPluginNames($projectId){ doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]//plugin/@name Loading
rxq/i18n.xqm +3 −72 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ module namespace max.i18n = 'pddn/max/i18n'; 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 Loading @@ -12,12 +12,12 @@ function max.i18n:setLang($projectId, $lang){ }; declare function max.i18n:getLang($projectId){ session:get($projectId || '-lang', 'fr') session:get($projectId || '-lang', max.config:getProjectDefaultLang($projectId)) }; declare function max.i18n:getText($projectId as xs:string, $key as xs:string){ max.i18n:getText($projectId, $key, session:get($projectId || '-lang', 'fr')) max.i18n:getText($projectId, $key, session:get($projectId || '-lang', max.config:getProjectDefaultLang($projectId))) }; declare function max.i18n:getText($projectId as xs:string, $key as xs:string, $locale as xs:string ?) Loading Loading @@ -49,72 +49,3 @@ declare function max.i18n:getLanguageList($projectId){ } catch * {'fr'} }; (: declare function max.i18n:getMap($projectId, $locale){ let $i18nResourceFile := max.util:maxHome() || "/ui/i18n/I18n" || $locale || ".xml" let $projectI18nFile := max.util:maxHome() || "/editions/" || $projectId || "/ui/i18n/I18n" || $locale || ".xml" let $primaryI18n := if (file:exists($projectI18nFile)) then doc($projectI18nFile) else doc($i18nResourceFile) let $secondaryI18n := if (file:exists($projectI18nFile)) then doc($i18nResourceFile) else () let $m1 := map:merge( for $entry in $primaryI18n//entry return map {string($entry/@key) : $entry/text() } ) let $m2 := map:merge( for $entry in $secondaryI18n//entry return if(not($primaryI18n//entry[@key=$entry/@key])) then map {string($entry/@key) : $entry/text()} else() ) return map:merge(($m2,$m1)) }; :) (: declare function max.i18n:getI18n($projectId, $locale) as node()*{ let $i18nResourceFile := max.util:maxHome() || "/ui/i18n/I18n" || $locale || ".xml" let $projectI18nFile := max.util:maxHome() || "/editions/" || $projectId || "/ui/i18n/I18n" || $locale || ".xml" let $primaryI18n := if (file:exists($projectI18nFile)) then doc($projectI18nFile) else doc($i18nResourceFile) let $secondaryI18n := if (file:exists($projectI18nFile)) then doc($i18nResourceFile) else () return <entries> { for $entry in $primaryI18n//entry return $entry } { for $entry in $secondaryI18n//entry return if(not($primaryI18n//entry[@key=$entry/@key])) then $entry else() } </entries> }; declare %rest:GET %output:method("html") %output:html-version("5.0") %output:indent("no") %output:encoding("UTF-8") %rest:path( "/{$projectId}/i18n/{$locale}.html") function max.i18n:listPage($projectId, $locale){ let $map := max.i18n:getMap($projectId, $locale) return <html> <body> <h1>I18n - {$projectId} - {$locale}</h1> <ul> { for $k in map:keys($map) return <li>{$k} : {map:get($map, $k)}</li> } </ul> </body> </html> }; :) No newline at end of file