Skip to content

Commit

Permalink
more effort on typographic quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Nov 21, 2016
1 parent 66b06a9 commit b54078b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion controller.xql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare variable $exist:resource external;
declare variable $exist:controller external;
declare variable $exist:prefix external;

let $lang := lang:get-set-language(())
let $lang := lang:guess-language(())
let $exist-vars := map {
'path' := $exist:path,
'resource' := $exist:resource,
Expand Down
2 changes: 1 addition & 1 deletion modules/config.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ declare function config:get-svn-props($docID as xs:string) as map() {
:)
declare function config:get-xsl-params($params as map()?) as element(parameters) {
<parameters>
<param name="lang" value="{lang:get-set-language(())}"/>
<param name="lang" value="{lang:guess-language(())}"/>
<param name="optionsFile" value="{$config:options-file-path}"/>
<param name="baseHref" value="{core:link-to-current-app(())}"/>
<param name="smufl-decl" value="{$config:smufl-decl-file-path}"/>
Expand Down
2 changes: 1 addition & 1 deletion modules/lang.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import module namespace core="http://xquery.weber-gesamtausgabe.de/modules/core"
: @param $lang the language to set
: @return xs:string the (newly) set language variable
:)
declare function lang:get-set-language($lang as xs:string?) as xs:string {
declare function lang:guess-language($lang as xs:string?) as xs:string {
if($lang = $config:valid-languages) then $lang
(: else try to guess from the URL path segment :)
else if(tokenize(request:get-attribute('$exist:path'), '/')[2] = $config:valid-languages) then tokenize(request:get-attribute('$exist:path'), '/')[2]
Expand Down
47 changes: 37 additions & 10 deletions modules/str.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,47 @@ declare function str:printFornameSurnameFromTEIpersName($persName as element(tei
};

(:~
: Surround a string with typographic quotes
: Surround a string with typographic double quotes
:
: @param $str the string to enquote
: @param $lang the language switch (en|de)
: @author Peter Stadler
: @return xs:string
: @return a single string if the input was a single string, a sequence of strings if the input was a sequence (where the quotes are then the first and the last item)
:)
declare function str:enquote($str as xs:string?, $lang as xs:string) as xs:string? {
let $quotes :=
declare function str:enquote($str as xs:string*, $lang as xs:string) as xs:string* {
if(count($str) = 1) then
switch ($lang)
case 'de' return '&#x201E;%1&#x201C;'
default return '&#x201C;%1&#x201D;'
return
if($str) then replace($quotes, '%1', $str)
else ()

case 'de' return concat('&#x201E;', $str, '&#x201C;')
case 'en' return concat('&#x201C;', $str, '&#x201D;')
default return concat('&quot;', $str, '&quot;')
else if(count($str) gt 1) then
switch ($lang)
case 'de' return ('&#x201E;', $str, '&#x201C;')
case 'en' return ('&#x201C;', $str, '&#x201D;')
default return ('&quot;', $str, '&quot;')
else ()
};

(:~
: Surround a string with typographic single quotes
:
: @param $str the string to enquote
: @param $lang the language switch (en|de)
: @author Peter Stadler
: @return a single string if the input was a single string, a sequence of strings if the input was a sequence (where the quotes are then the first and the last item)
:)
declare function str:enquote-single($str as xs:string*, $lang as xs:string) as xs:string* {
if(count($str) = 1) then
switch ($lang)
case 'de' return concat('&#x201A;', $str, '&#x2018;')
case 'en' return concat('&#x2018;', $str, '&#x2019;')
default return concat('&#x0027;', $str, '&#x0027;')
else if(count($str) gt 1) then
switch ($lang)
case 'de' return ('&#x201A;', $str, '&#x2018;')
case 'en' return ('&#x2018;', $str, '&#x2019;')
default return ('&#x0027;', $str, '&#x0027;')
else ()
};

(:~
Expand Down
6 changes: 5 additions & 1 deletion modules/wega-util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import module namespace functx="http://www.functx.com";
import module namespace config="http://xquery.weber-gesamtausgabe.de/modules/config" at "config.xqm";
import module namespace core="http://xquery.weber-gesamtausgabe.de/modules/core" at "core.xqm";
import module namespace str="http://xquery.weber-gesamtausgabe.de/modules/str" at "str.xqm";
import module namespace lang="http://xquery.weber-gesamtausgabe.de/modules/lang" at "lang.xqm";

(:~
: Get resources from the web by PND and store the result in a cache object with the current date.
Expand Down Expand Up @@ -242,7 +243,10 @@ declare function wega-util:txtFromTEI($nodes as node()*) as xs:string* {
case element(tei:del) return ()
case element(tei:note) return ()
case element(tei:lb) return '&#10;'
case element(tei:q) return (' &quot;', $node/child::node() ! wega-util:txtFromTEI(.), '&quot; ')
case element(tei:q) return str:enquote($node/child::node() ! wega-util:txtFromTEI(.), lang:guess-language(()))
case element(tei:quote) return
if($node[@rend='double-quotes']) then str:enquote($node/child::node() ! wega-util:txtFromTEI(.), lang:guess-language(()))
else str:enquote-single($node/child::node() ! wega-util:txtFromTEI(.), lang:guess-language(()))
case text() return replace($node, '\n+', ' ')
case document-node() return $node/child::node() ! wega-util:txtFromTEI(.)
case processing-instruction() return ()
Expand Down

0 comments on commit b54078b

Please sign in to comment.